Files
mkd/backend/migrations/create_pr_smm_channels.sql
2026-02-04 00:17:04 +05:00

29 lines
1.4 KiB
SQL
Executable File
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.
-- PR SMM: каналы и снимки подписчиков
-- Каналы (Telegram, VK, WhatsApp и др.)
CREATE TABLE IF NOT EXISTS pr_smm_channels (
id BIGSERIAL PRIMARY KEY,
name TEXT NOT NULL,
type VARCHAR(20) NOT NULL CHECK (type IN ('tg', 'vk', 'wa', 'other')),
url TEXT,
sort_order INT NOT NULL DEFAULT 0,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);
CREATE INDEX IF NOT EXISTS idx_pr_smm_channels_sort ON pr_smm_channels(sort_order);
-- Снимки количества подписчиков по дате (история фиксаций)
CREATE TABLE IF NOT EXISTS pr_smm_subscriber_snapshots (
id BIGSERIAL PRIMARY KEY,
channel_id BIGINT NOT NULL REFERENCES pr_smm_channels(id) ON DELETE CASCADE,
subscribers_count INT NOT NULL,
recorded_at DATE NOT NULL DEFAULT CURRENT_DATE,
note TEXT,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);
CREATE INDEX IF NOT EXISTS idx_pr_smm_snapshots_channel ON pr_smm_subscriber_snapshots(channel_id);
CREATE INDEX IF NOT EXISTS idx_pr_smm_snapshots_recorded ON pr_smm_subscriber_snapshots(recorded_at DESC);
COMMENT ON TABLE pr_smm_channels IS 'SMM-каналы УК: Telegram, VK, WhatsApp и др.';
COMMENT ON TABLE pr_smm_subscriber_snapshots IS 'Фиксации количества подписчиков по дате для истории';