
CREATE TABLE IF NOT EXISTS yandex_alice_channels
(
    id bigint NOT NULL,
    uuid character varying(36),
    name character varying(255),
    deleted boolean 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,
    CONSTRAINT yandex_alice_channels_pkey PRIMARY KEY (id)
);

CREATE UNIQUE INDEX IF NOT EXISTS yandex_alice_channels_uuid_uniq
    ON yandex_alice_channels(uuid);


CREATE TABLE IF NOT EXISTS yandex_alice_chats
(
    id bigint PRIMARY KEY NOT NULL,
    chat_id bigint 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 IF NOT EXISTS yandex_alice_chats_chat_uniq
    ON yandex_alice_chats(chat_id);


CREATE TABLE IF NOT EXISTS yandex_alice_configs
(
    channel_id bigint PRIMARY KEY NOT NULL REFERENCES channels(id),
    access_token character varying(255)
);


CREATE TABLE IF NOT EXISTS yandex_alice_users
(
    id bigint PRIMARY KEY NOT NULL,
    yandex_id varchar,
    name character varying(512),
    surname character varying,
    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 IF NOT EXISTS yandex_alice_users_id_yandex_id_uniq ON yandex_alice_users(id, yandex_id);

alter table clients add if not exists yandex_id varchar;



