--- user-status

create table statuses (
    id bigint primary key,
    user_id bigint not null references users(id),
    "type" varchar not null,
    active boolean not null,
    started_at timestamptz not null,
    ended_at timestamptz
);

create sequence statuses_id_seq;

create unique index statuses_type_active_uniq
on statuses (user_id, "type", active)
where active is true;

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