--- user-status

create table statuses (
    id bigint primary key identity(1, 1),
    user_id bigint not null references users(id),
    "type" nvarchar(255) not null,
    "active" bit not null,
    started_at datetimeoffset not null,
    ended_at datetimeoffset
);

create unique index statuses_user_type_active_uniq
on statuses (user_id, "type", active)
where active = 1;

create index statuses_started_ix on statuses(started_at);
create index statuses_user_started_in on statuses(user_id, started_at);
