- 为后端Admin新增migration_compat工具,支持离线迁移时的基线资源检查,重构全部alembic迁移脚本适配离线模式,避免重复创建已存在的数据库表和字段 - 完善初始数据库迁移脚本,添加默认部门种子数据,新增ConciergeAdvisor详情字段从JSON到JSONB的类型转换迁移 - 小程序端新增图片资源解析工具resolveNetworkImage,实现本地静态资源到CDN的自动映射,添加图片加载容错降级机制 - 完善HeroSlide类型定义,新增actionLabel字段,优化首页轮播组件的文本渲染与错误处理逻辑 - 新增对应测试用例验证迁移路径正确性与前端数据处理逻辑 - 新增临时 brainstorm UI对比草稿与开发临时状态文件
88 lines
2.9 KiB
Python
88 lines
2.9 KiB
Python
"""Add long-form detail content to homepage team buildings.
|
|
|
|
Revision ID: 0020_home_team_building_details
|
|
Revises: 0019_home_wild_archive_images
|
|
"""
|
|
|
|
from alembic import context, op
|
|
import sqlalchemy as sa
|
|
from sqlalchemy import inspect
|
|
from sqlalchemy.dialects import postgresql
|
|
|
|
from app.migration_compat import baseline_column_names
|
|
|
|
|
|
revision = "0020_home_team_building_details"
|
|
down_revision = "0019_home_wild_archive_images"
|
|
branch_labels = None
|
|
depends_on = None
|
|
|
|
|
|
DETAIL_COLUMNS = {"detailSubtitle", "detailParagraphs"}
|
|
|
|
|
|
def missing_detail_columns(existing_columns: set[str]) -> set[str]:
|
|
return DETAIL_COLUMNS.difference(existing_columns)
|
|
|
|
|
|
def is_offline_mode() -> bool:
|
|
try:
|
|
return context.is_offline_mode()
|
|
except (NameError, AttributeError):
|
|
return False
|
|
|
|
|
|
def upgrade() -> None:
|
|
if is_offline_mode():
|
|
columns_to_add = missing_detail_columns(
|
|
baseline_column_names("HomeTeamBuilding")
|
|
)
|
|
else:
|
|
bind = op.get_bind()
|
|
existing_columns = {column["name"] for column in inspect(bind).get_columns("HomeTeamBuilding")}
|
|
columns_to_add = missing_detail_columns(existing_columns)
|
|
|
|
if "detailSubtitle" in columns_to_add:
|
|
op.add_column(
|
|
"HomeTeamBuilding",
|
|
sa.Column("detailSubtitle", sa.String(), nullable=False, server_default=""),
|
|
)
|
|
if "detailParagraphs" in columns_to_add:
|
|
op.add_column(
|
|
"HomeTeamBuilding",
|
|
sa.Column(
|
|
"detailParagraphs",
|
|
postgresql.JSONB(astext_type=sa.Text()),
|
|
nullable=False,
|
|
server_default=sa.text("'[]'::jsonb"),
|
|
),
|
|
)
|
|
op.execute(
|
|
sa.text(
|
|
'UPDATE "HomeTeamBuilding" '
|
|
'SET "detailSubtitle" = CASE '
|
|
'WHEN COALESCE("detailSubtitle", \'\') = \'\' THEN "description" '
|
|
'ELSE "detailSubtitle" END, '
|
|
'"detailParagraphs" = CASE '
|
|
'WHEN "detailParagraphs" IS NULL OR jsonb_typeof("detailParagraphs") <> \'array\' '
|
|
'OR (jsonb_typeof("detailParagraphs") = \'array\' '
|
|
'AND jsonb_array_length("detailParagraphs") = 0) '
|
|
'THEN jsonb_build_array("description") '
|
|
'ELSE "detailParagraphs" END '
|
|
'WHERE COALESCE("detailSubtitle", \'\') = \'\' '
|
|
'OR "detailParagraphs" IS NULL '
|
|
'OR jsonb_typeof("detailParagraphs") <> \'array\' '
|
|
'OR (jsonb_typeof("detailParagraphs") = \'array\' '
|
|
'AND jsonb_array_length("detailParagraphs") = 0)'
|
|
)
|
|
)
|
|
if "detailSubtitle" in columns_to_add:
|
|
op.alter_column("HomeTeamBuilding", "detailSubtitle", server_default=None)
|
|
if "detailParagraphs" in columns_to_add:
|
|
op.alter_column("HomeTeamBuilding", "detailParagraphs", server_default=None)
|
|
|
|
|
|
def downgrade() -> None:
|
|
op.drop_column("HomeTeamBuilding", "detailParagraphs")
|
|
op.drop_column("HomeTeamBuilding", "detailSubtitle")
|