Files
ewoooc/migrations/014_telegram_users.sql
ogt 15c899915a 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>
2026-04-19 16:40:56 +08:00

22 lines
1.0 KiB
SQL
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.
-- 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;