-- yandex_alice-channels

CREATE TABLE yandex_alice_channels
(
    id bigint primary key,
    uuid NVARCHAR(36),
    deleted BIT NOT NULL,
    name varchar(200),
    created_at datetimeoffset NOT NULL,
    updated_at datetimeoffset NOT NULL,
    deleted_at datetimeoffset,
    restored_at datetimeoffset
);

CREATE UNIQUE INDEX yandex_alice_channels_uuid_uniq
    ON yandex_alice_channels(uuid);

-- yandex_alice-chats

CREATE TABLE yandex_alice_chats
(
    id bigint PRIMARY KEY IDENTITY(1,1),
    chat_id bigint NOT NULL REFERENCES chats(id),
    created_at datetimeoffset NOT NULL,
    updated_at datetimeoffset NOT NULL
);

CREATE UNIQUE INDEX yandex_alice_chats_chat_uniq
    ON yandex_alice_chats(chat_id);

CREATE TABLE yandex_alice_configs
(
    channel_id bigint PRIMARY KEY NOT NULL REFERENCES channels(id),
    access_token NVARCHAR(255)
);

CREATE TABLE yandex_alice_users
(
    id bigint PRIMARY KEY IDENTITY(1,1),
    yandex_id NVARCHAR(256),
    name NVARCHAR(512),
    surname NVARCHAR(512),
    created_at datetimeoffset NOT NULL,
    updated_at datetimeoffset NOT NULL
);

CREATE UNIQUE INDEX yandex_alice_users_id_yandex_id_uniq ON yandex_alice_users(id, yandex_id);

alter table clients add yandex_id nvarchar(500);



