diff --git a/migrations/014_telegram_users.sql b/migrations/014_telegram_users.sql new file mode 100644 index 0000000..c3c27f2 --- /dev/null +++ b/migrations/014_telegram_users.sql @@ -0,0 +1,21 @@ +-- Migration 014: telegram_users 表 +-- EventRouter 用於查詢 is_admin=true 的推播對象,取代 .env 硬編碼 +-- 建立日期:2026-04-19 + +CREATE TABLE IF NOT EXISTS telegram_users ( + id SERIAL PRIMARY KEY, + telegram_id BIGINT NOT NULL UNIQUE, -- Telegram chat_id(群組為負數) + username VARCHAR(100), -- 顯示名稱(方便辨識) + is_active BOOLEAN NOT NULL DEFAULT TRUE, + is_admin BOOLEAN NOT NULL DEFAULT FALSE, + note TEXT, + created_at TIMESTAMP NOT NULL DEFAULT NOW(), + updated_at TIMESTAMP NOT NULL DEFAULT NOW() +); + +CREATE INDEX IF NOT EXISTS idx_tg_users_admin_active ON telegram_users(is_admin, is_active); + +-- 種子:EwoooC 管理群組(從 .env OPENCLAW_GROUP_ID 遷移) +INSERT INTO telegram_users (telegram_id, username, is_active, is_admin, note) +VALUES (-1003940688311, 'EwoooC_Admin_Group', true, true, '主要告警群組,原 OPENCLAW_GROUP_ID') +ON CONFLICT (telegram_id) DO NOTHING;