CREATE TABLE client_comments (
    id NUMBER(19) PRIMARY KEY,
    client_id NUMBER(19) REFERENCES clients(id),
    project_id NUMBER(19) REFERENCES projects(id),
    author_id NUMBER(19) REFERENCES users(id),
    text varchar2(512),
    channel_type varchar2(100),
    rating_state varchar2(100),
    rating NUMBER(10),
    edited_by_user_id NUMBER(19) REFERENCES users(id),
    deleted_by_user_id NUMBER(19) REFERENCES users(id),
    deleted number(1) default 0,

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

CREATE SEQUENCE client_comments_id_seq;

create index client_comments_client_comments_id_ticket_id_ix
    on client_comments(CASE WHEN deleted = 0
                                THEN id
                           END,
                       CASE WHEN deleted = 0
                                THEN client_id
                           END);
