CREATE TABLE ticket_comments (
    id BIGINT PRIMARY KEY,
    ticket_id BIGINT NOT NULL REFERENCES tickets(id),
    chat_id BIGINT NOT NULL REFERENCES chats(id),
    client_id BIGINT REFERENCES clients(id),
    channel_type varchar(100),
    author_id BIGINT REFERENCES users(id),
    edited_by_user_id BIGINT REFERENCES users(id),
    deleted_by_user_id BIGINT REFERENCES users(id),
    text varchar(512) not null ,
    deleted BOOLEAN default false,

    created_at TIMESTAMP WITH TIME ZONE NOT NULL,
    edited_at TIMESTAMP WITH TIME ZONE,
    deleted_at TIMESTAMP WITH TIME ZONE
);

CREATE SEQUENCE ticket_comments_id_seq;

create index ticket_comments_ticket_comments_id_ticket_id_ix
    on ticket_comments(id, ticket_id) where deleted = false;
