-- email-channels

CREATE TABLE email_channels
(
    id bigint PRIMARY KEY NOT NULL references channels(id),
    uuid nvarchar(36),
    deleted BIT NOT NULL,
    project_id BIGINT NOT NULL references projects(id),
    created_at DATETIMEOFFSET NOT NULL,
    updated_at DATETIMEOFFSET NOT NULL,
    deleted_at DATETIMEOFFSET,
    restored_at DATETIMEOFFSET
);

CREATE UNIQUE INDEX email_channels_uuid_uniq
    ON email_channels(uuid);

-- email configs

CREATE TABLE email_channel_configs
(
    channel_id bigint NOT NULL references channels(id),
    smtp_addr nvarchar(255),
    smtp_port nvarchar(10),
    imap_addr nvarchar(255),
    imap_port nvarchar(10),
    login nvarchar(125),
    password nvarchar,
    email nvarchar(225),
    signature_template nvarchar(4000),
    header_template nvarchar(4000),
    delete_after bit
);

CREATE UNIQUE INDEX email_channels_configs_channel_id_uniq
    ON email_channel_configs(channel_id);

