--- files

CREATE TABLE files (
  id              VARCHAR(255) PRIMARY KEY,
  type            VARCHAR(255)     NOT NULL,
  actor           NVARCHAR(255)     NOT NULL,
  actor_client_id BIGINT REFERENCES clients (id),
  actor_user_id   BIGINT REFERENCES users (id),
  name            NVARCHAR(255)     NOT NULL,
  path            NVARCHAR(255)     NOT NULL,
  size            BIGINT      NOT NULL,
  content_type    VARCHAR(128)     NOT NULL,
  image_width     BIGINT      NULL,
  image_height    BIGINT      NULL,
  created_at      DATETIMEOFFSET NOT NULL DEFAULT SYSDATETIMEOFFSET()
);

CREATE INDEX files_actor_client_id_ix
  ON files (actor_client_id)
  WHERE actor_client_id IS NOT NULL;

CREATE INDEX files_actor_user_id_ix
  ON files (actor_user_id)
  WHERE actor_user_id IS NOT NULL;
