DispelEvilBot/sql/V20__message_sequences.sql

49 lines
2.1 KiB
SQL
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- Последовательности сообщений (Блок 4): несколько сообщений по порядку,
-- у каждого — опциональная картинка (файл в общем volume) и свои кнопки.
CREATE TABLE IF NOT EXISTS bot.message_sequences (
key text PRIMARY KEY,
title text NOT NULL,
description text NOT NULL DEFAULT '',
updated_at timestamptz NOT NULL DEFAULT now(),
updated_by bigint
);
COMMENT ON TABLE bot.message_sequences IS 'Именованные последовательности сообщений (приветствие и т.п.)';
CREATE TABLE IF NOT EXISTS bot.message_sequence_items (
id bigserial PRIMARY KEY,
sequence_key text NOT NULL REFERENCES bot.message_sequences (key) ON DELETE CASCADE,
position integer NOT NULL,
text text NOT NULL DEFAULT '',
enabled boolean NOT NULL DEFAULT true,
image_name text,
updated_at timestamptz NOT NULL DEFAULT now(),
updated_by bigint,
UNIQUE (sequence_key, position)
);
COMMENT ON TABLE bot.message_sequence_items IS 'Сообщения последовательности по порядку';
COMMENT ON COLUMN bot.message_sequence_items.image_name IS 'Имя файла в общем volume media/ (необязательно)';
CREATE TABLE IF NOT EXISTS bot.message_sequence_buttons (
id bigserial PRIMARY KEY,
item_id bigint NOT NULL REFERENCES bot.message_sequence_items (id) ON DELETE CASCADE,
position integer NOT NULL,
text text NOT NULL,
url text NOT NULL,
UNIQUE (item_id, position)
);
COMMENT ON TABLE bot.message_sequence_buttons IS 'Inline-кнопки конкретного сообщения последовательности';
CREATE TABLE IF NOT EXISTS bot.message_sequence_history (
id bigserial PRIMARY KEY,
sequence_key text NOT NULL,
snapshot jsonb NOT NULL,
editor_id bigint,
changed_at timestamptz NOT NULL DEFAULT now()
);
CREATE INDEX IF NOT EXISTS idx_sequence_history_key_time
ON bot.message_sequence_history (sequence_key, changed_at DESC);