CREATE TABLE ticket_comments (
    id BIGINT PRIMARY KEY IDENTITY (1, 1),
    ticket_id BIGINT NOT NULL REFERENCES tickets(id),
    chat_id BIGINT NOT NULL REFERENCES chats(id),
    client_id BIGINT REFERENCES clients(id),
    channel_type NVARCHAR(100),
    author_id BIGINT REFERENCES users(id),
    edited_by_user_id BIGINT REFERENCES users(id),
    deleted_by_user_id BIGINT REFERENCES users(id),
    text NVARCHAR(512) not null,
    deleted BIT default 0,

    created_at DATETIMEOFFSET NOT NULL,
    edited_at DATETIMEOFFSET,
    deleted_at DATETIMEOFFSET
);

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