b9617ae152
- 后端 Schema 将 interface_language 和 ai_language 合并为 language - 前端设置界面只保留一个语言选项 - AI 回复语言统一使用 language 设置 - 更新协议文档 - 新增数据库迁移脚本
53 lines
2.0 KiB
Python
53 lines
2.0 KiB
Python
"""migrate existing profile settings to new schema
|
|
|
|
Revision ID: 20260428_0003
|
|
Revises: 20260428_0002
|
|
Create Date: 2026-04-28
|
|
|
|
"""
|
|
|
|
from alembic import op
|
|
|
|
revision = "20260428_0003"
|
|
down_revision = "20260428_0002"
|
|
branch_labels = None
|
|
depends_on = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
op.execute(
|
|
"""
|
|
UPDATE profiles
|
|
SET settings = jsonb_build_object(
|
|
'version', 1,
|
|
'preferences', jsonb_build_object(
|
|
'language', COALESCE(settings->'preferences'->>'language', 'zh-CN'),
|
|
'timezone', COALESCE(settings->'preferences'->>'timezone', 'Asia/Shanghai'),
|
|
'country', COALESCE(settings->'preferences'->>'country', 'US')
|
|
),
|
|
'privacy', jsonb_build_object(
|
|
'can_sell', COALESCE((settings->'privacy'->>'can_sell')::boolean, false),
|
|
'profile_visibility', COALESCE(settings->'privacy'->>'profile_visibility', 'public')
|
|
),
|
|
'notification', jsonb_build_object(
|
|
'allow_notifications', COALESCE((settings->'notification'->>'allow_notifications')::boolean, true),
|
|
'allow_vibration', COALESCE((settings->'notification'->>'allow_vibration')::boolean, true)
|
|
),
|
|
'divination_tutorial', jsonb_build_object(
|
|
'divination_entry_shown', COALESCE((settings->'divination_tutorial'->>'divination_entry_shown')::boolean, false),
|
|
'auto_divination_shown', COALESCE((settings->'divination_tutorial'->>'auto_divination_shown')::boolean, false),
|
|
'manual_divination_shown', COALESCE((settings->'divination_tutorial'->>'manual_divination_shown')::boolean, false)
|
|
)
|
|
)
|
|
WHERE settings IS NOT NULL;
|
|
"""
|
|
)
|
|
|
|
|
|
def downgrade() -> None:
|
|
raise RuntimeError(
|
|
"20260428_0003 is a destructive JSON data-shape migration and cannot be "
|
|
"downgraded automatically. Restore profile settings from backup if rollback "
|
|
"to the previous schema is required."
|
|
)
|