From 15c899915a98c38376fa4f5bc01e5335734ddb88 Mon Sep 17 00:00:00 2001 From: ogt Date: Sun, 19 Apr 2026 16:40:56 +0800 Subject: [PATCH] =?UTF-8?q?feat(db):=20migration=20014=20=E2=80=94=20teleg?= =?UTF-8?q?ram=5Fusers=20=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit EventRouter 改走 DB 路徑查 admin chat_id, 取代 .env TELEGRAM_CHAT_IDS 硬編碼。 種子: -1003940688311 (EwoooC_Admin_Group, is_admin=true) 已在 188 momo_analytics 執行建表 + 種子植入。 Co-Authored-By: Claude Sonnet 4.6 --- migrations/014_telegram_users.sql | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 migrations/014_telegram_users.sql 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;