feat(notification): 通知标题和正文支持多语言
- 通知静态配置支持 title/body i18n - 前端通知列表和详情页展示本地化内容 - 新增数据库迁移脚本 - 更新通知协议文档
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
"""Convert notification title/body from text to jsonb (i18n dict).
|
||||
|
||||
title and body become jsonb objects keyed by locale code:
|
||||
{"zh": "欢迎来到觅爻", "zh_Hant": "...", "en": "..."}
|
||||
|
||||
Existing data is wrapped under the "zh" key (simplified Chinese default).
|
||||
|
||||
Revision ID: 20260428_0001
|
||||
"""
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
revision = "20260428_0001"
|
||||
down_revision = "20260427_0002"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
op.execute(
|
||||
"""
|
||||
ALTER TABLE notifications
|
||||
ALTER COLUMN title TYPE jsonb USING jsonb_build_object('zh', title),
|
||||
ALTER COLUMN body TYPE jsonb USING jsonb_build_object('zh', body);
|
||||
"""
|
||||
)
|
||||
|
||||
op.execute(
|
||||
"""
|
||||
ALTER TABLE notifications DROP CONSTRAINT IF EXISTS ck_notifications_payload_object;
|
||||
"""
|
||||
)
|
||||
|
||||
op.execute(
|
||||
"""
|
||||
ALTER TABLE notifications
|
||||
ADD CONSTRAINT ck_notifications_payload_object
|
||||
CHECK (jsonb_typeof(payload) = 'object');
|
||||
"""
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.execute(
|
||||
"""
|
||||
ALTER TABLE notifications
|
||||
ALTER COLUMN title TYPE text USING COALESCE(title ->> 'zh', ''),
|
||||
ALTER COLUMN body TYPE text USING COALESCE(body ->> 'zh', '');
|
||||
"""
|
||||
)
|
||||
Reference in New Issue
Block a user