feat(db): migration 014 — telegram_users 表

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 <noreply@anthropic.com>
This commit is contained in:
ogt
2026-04-19 16:40:56 +08:00
parent 551bab5fe6
commit 15c899915a

View File

@@ -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;