alter table clients
    add blocked boolean default false;
update clients set blocked = false;
alter table clients
    add blocked_until varchar(100);
alter table clients
    add blocked_at timestamptz;
alter table clients
    add block_reason varchar(255);
alter table clients
    add user_who_blocked_id bigint references users (id);

alter table tickets
    add blocked boolean default false;
update tickets set blocked = false;
alter table tickets
    add blocked_until varchar(100);
alter table tickets
    add blocked_at timestamptz;
alter table tickets
    add block_reason varchar(255);
alter table tickets
    add user_who_blocked_id bigint references users (id);

create table blocked_tickets
(
    ticket_id     bigint primary key references tickets (id),
    blocked_until varchar(100),
    deleted       boolean default false,
    changed_at    timestamptz
);

create table blocked_clients
(
    client_id     bigint primary key references clients (id),
    blocked_until varchar(100),
    deleted       boolean default false,
    changed_at    timestamptz
);

create table blocked_tickets_settings
(
    project_id               bigint references projects (id) not null,
    first_assign_to_group    boolean                       default true,
    first_assign_to_group_id bigint references groups (id),
    next_assign_to_group     boolean                       default false,
    next_assign_to_group_id  bigint references groups (id),
    close_next_with_reply    boolean                       default true,
    close_next_reply         varchar(255)                  default 'Извините, все операторы заняты',
    created_at               timestamptz                     not null,
    updated_at               timestamptz
);