20 lines
872 B
SQL
20 lines
872 B
SQL
-- Переводим все текущие шаблоны сообщений в последовательности (по одному сообщению).
|
|
-- Старые строки message_templates оставляем как фолбэк для кода.
|
|
INSERT INTO bot.message_sequences (key, title, description)
|
|
SELECT t.key,
|
|
coalesce(nullif(t.description, ''), t.key),
|
|
t.description
|
|
FROM bot.message_templates AS t
|
|
WHERE NOT EXISTS (SELECT 1 FROM bot.message_sequences AS s WHERE s.key = t.key)
|
|
ON CONFLICT (key) DO NOTHING;
|
|
|
|
INSERT INTO bot.message_sequence_items (sequence_key, position, text, enabled)
|
|
SELECT t.key, 0, t.text, t.enabled
|
|
FROM bot.message_templates AS t
|
|
WHERE NOT EXISTS (
|
|
SELECT 1
|
|
FROM bot.message_sequence_items AS i
|
|
WHERE i.sequence_key = t.key AND i.position = 0
|
|
)
|
|
ON CONFLICT (sequence_key, position) DO NOTHING;
|