--- files

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

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;
