--- user-status

create table statuses (
    id number(19) primary key,
    user_id number(19) not null references users(id),
    "type" varchar2(255 char) not null,
    "active" number(1) not null,
    started_at timestamp with time zone not null,
    ended_at timestamp with time zone
);

create sequence statuses_id_seq;

create unique index statuses_type_active_uniq
on statuses (
    case when "active" = 1
        then user_id
    end,
    case when "active" = 1
        then "type"
    end,
    case when "active" = 1
        then "active"
    end
);

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