-- yandex_alice-channels

CREATE TABLE yandex_alice_channels
(
    id NUMBER(19) primary key NOT NULL,
    uuid varchar2(36),
    name varchar2(200),
    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,
    restored_at timestamp with time zone
);

CREATE UNIQUE INDEX yandex_alice_channels_uuid_uniq
    ON yandex_alice_channels(uuid);

-- yandex_alice-chats

CREATE TABLE yandex_alice_chats
(
    id NUMBER(19) PRIMARY KEY NOT NULL,
    chat_id NUMBER(19) NOT NULL,
    created_at timestamp with time zone NOT NULL,
    updated_at timestamp with time zone NOT NULL
);

CREATE SEQUENCE yandex_alice_chats_id_seq;

CREATE UNIQUE INDEX yandex_alice_chats_chat_uniq
    ON yandex_alice_chats(chat_id);

-- yandex_alice_congigs

CREATE TABLE yandex_alice_configs
(
    channel_id NUMBER(19) PRIMARY KEY NOT NULL REFERENCES channels(id),
    access_token varchar2(255)
);

-- yandex_alice users

CREATE TABLE yandex_alice_users
(
    id NUMBER(19) PRIMARY KEY NOT NULL,
    yandex_id varchar2(256),
    name varchar2(512),
    surname varchar2(4000),
    created_at timestamp with time zone NOT NULL,
    updated_at timestamp with time zone NOT NULL
);

CREATE SEQUENCE yandex_alice_users_id_seq;

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

alter table clients add yandex_id varchar2(500);

