CREATE EXTENSION IF NOT EXISTS "uuid-ossp";

CREATE TABLE tgchats (
    id BIGINT PRIMARY KEY,
    chat_type TEXT NOT NULL,
    title TEXT NOT NULL
);

CREATE TABLE users (
    id BIGINT PRIMARY KEY,
    username TEXT,
    first_name TEXT,
    last_name TEXT
);

CREATE TABLE successed (
    id BIGSERIAL PRIMARY KEY,
    user_id BIGINT NOT NULL REFERENCES users(id) ON DELETE CASCADE,
    reason TEXT NOT NULL,
    created_at TIMESTAMP DEFAULT NOW() NOT NULL,
    slice_id UUID NOT NULL UNIQUE
);

CREATE TABLE tg_messages (
    id BIGINT PRIMARY KEY,
    text TEXT NOT NULL,
    message_time TIMESTAMP NOT NULL,
    user_id BIGINT NOT NULL REFERENCES users(id),
    chat_id BIGINT NOT NULL REFERENCES tgchats(id),
    slice_id UUID NOT NULL
);
