-- Auth

CREATE TABLE user_sessions (
  id         BIGINT IDENTITY(1,1) PRIMARY KEY,
  user_id    BIGINT      NOT NULL REFERENCES users (id),
  token      VARCHAR(255)     NOT NULL,
  active     BIT     NOT NULL DEFAULT 0,
  created_at DATETIMEOFFSET NOT NULL DEFAULT SYSDATETIMEOFFSET(),
  expires_at DATETIMEOFFSET 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);
