CREATE TABLE "user" ( id BIGSERIAL PRIMARY KEY, telegram_id BIGINT NOT NULL ); CREATE TABLE chat ( id BIGSERIAL PRIMARY KEY, telegram_id BIGINT NOT NULL, user_id BIGINT NOT NULL, members JSON, FOREIGN KEY (user_id) REFERENCES "user"(id) ON DELETE CASCADE ); CREATE TABLE integration ( id BIGSERIAL PRIMARY KEY, type VARCHAR(32) NOT NULL, chat_id BIGINT NOT NULL, params JSON, FOREIGN KEY (chat_id) REFERENCES chat(id) ON DELETE CASCADE );