create table info_requests
(
    id          NUMBER(19) primary key,
    project_id NUMBER(19) references projects(id),
    ticket_id NUMBER(19) references tickets(id),
    client_id NUMBER(19) references clients(id),
    user_id NUMBER(19) references users(id),
    state varchar2(200) not null,
    client_consent NUMBER(1) default false not null,
    name varchar2(500) default '',
    phone varchar2(20) default '',
    email varchar2(500) default '',
    deleted     NUMBER(1) default 0,
    created_at  TIMESTAMP WITH TIME ZONE  not null,
    updated_at  TIMESTAMP WITH TIME ZONE,
    deleted_at  TIMESTAMP WITH TIME ZONE
);

create sequence info_requests_id_seq;

CREATE INDEX info_requests_client_id_ticket_id_ix
    ON info_requests (ticket_id, client_id, id DESC);

alter table tickets add info_request_id NUMBER(19) references info_requests(id);
alter table ticket_messages add info_request_id NUMBER(19) references info_requests(id);
alter table chat_messages add info_request_id NUMBER(19) references info_requests(id);
