CREATE TABLE tickets_closing_settings (
    id NUMBER(19) PRIMARY KEY,
    project_id NUMBER(19) NOT NULL REFERENCES projects(id),
    closing_message varchar2(1024),
    inactivity_time NUMBER(19),
    enabled NUMBER(1),
    close_bot_dialogs NUMBER(1),
    close_user_dialogs NUMBER(1),
    deleted NUMBER(1),

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

CREATE SEQUENCE tickets_closing_settings_id_seq;

CREATE UNIQUE INDEX tickets_closing_settings_uniq ON tickets_closing_settings (
                                                                   CASE WHEN deleted = 0
                                                                            THEN project_id
                                                                       END,
                                                                   CASE WHEN deleted = 0
                                                                            THEN id
                                                                       END);
