CREATE TABLE telegram_publics (
    id NUMBER(19) PRIMARY KEY,
    title VARCHAR2(255) not null,
    telegram_link varchar2(512) not null,
    channel_id NUMBER(19) references channels (id),
    deleted NUMBER(1) NOT NULL,

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

CREATE SEQUENCE telegram_publics_id_seq;

CREATE UNIQUE INDEX telegram_publics_uniq ON telegram_publics (
                            CASE WHEN deleted = 0
                                THEN telegram_link
                            END,
                CASE WHEN deleted = 0
                            THEN channel_id
                        END
    );
