database.ts 导出db常量替代getDb()函数 env.ts JWT_SECRET/ES_URL改optional加DEV_MODE/PUSH_GATEWAY_URL elasticsearch.ts ES降级: ES_URL未设置时esClient=null notifications.service.ts 加createBatch+分页查询+Push Gateway推送调用 新建msg-init.sql创建2张表
27 lines
1.0 KiB
SQL
27 lines
1.0 KiB
SQL
-- Msg 服务数据库初始化脚本
|
||
-- 表:msg_notifications / msg_notification_preferences
|
||
|
||
CREATE TABLE IF NOT EXISTS msg_notifications (
|
||
id CHAR(36) NOT NULL PRIMARY KEY,
|
||
user_id CHAR(36) NOT NULL,
|
||
type VARCHAR(50) NOT NULL,
|
||
title VARCHAR(200) NOT NULL,
|
||
content TEXT NOT NULL,
|
||
channel VARCHAR(20) NOT NULL DEFAULT 'in_app',
|
||
is_read BOOLEAN NOT NULL DEFAULT FALSE,
|
||
metadata JSON NULL,
|
||
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||
INDEX idx_notifications_user_id (user_id),
|
||
INDEX idx_notifications_is_read (is_read),
|
||
INDEX idx_notifications_created_at (created_at),
|
||
INDEX idx_notifications_user_read (user_id, is_read)
|
||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||
|
||
CREATE TABLE IF NOT EXISTS msg_notification_preferences (
|
||
user_id CHAR(36) NOT NULL PRIMARY KEY,
|
||
email_enabled BOOLEAN NOT NULL DEFAULT TRUE,
|
||
sms_enabled BOOLEAN NOT NULL DEFAULT FALSE,
|
||
push_enabled BOOLEAN NOT NULL DEFAULT TRUE,
|
||
in_app_enabled BOOLEAN NOT NULL DEFAULT TRUE
|
||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|