-- Auth

CREATE TABLE user_sessions (
  id         BIGSERIAL PRIMARY KEY,
  user_id    BIGINT      NOT NULL REFERENCES users (id),
  token      VARCHAR     NOT NULL,
  active     BOOLEAN     NOT NULL DEFAULT FALSE,
  created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
  expires_at TIMESTAMPTZ NOT NULL
);

CREATE INDEX user_sessions_user_id_ix
  ON user_sessions (user_id);
CREATE UNIQUE INDEX user_sessions_token_uniq
  ON user_sessions (token);
