打通 T+ 快照、业务、发货、回款和核算准备链路,保留来源差异并提供待补状态。 新增业务自动接入任务、跨平台读取服务托管、权限复核、来源关联和前端核对页面。 补充迁移、隔离集成测试、浏览器模拟验收及角色授权边界修复。
41 lines
2.0 KiB
Python
41 lines
2.0 KiB
Python
"""V30 业务接入与核算准备解耦;无默认回填。"""
|
|
|
|
from pathlib import Path
|
|
|
|
from alembic import op
|
|
from sqlalchemy import text
|
|
|
|
revision = "30c1d2e3f4a5"
|
|
down_revision = "29b0c1d2e3f4"
|
|
branch_labels = None
|
|
depends_on = None
|
|
|
|
|
|
def upgrade():
|
|
script = Path(__file__).resolve().parents[3] / "db/migration/V30__tplus_business_sync.sql"
|
|
for statement in script.read_text(encoding="utf-8").split(";\n"):
|
|
sql = "\n".join(line for line in statement.splitlines() if not line.lstrip().startswith("--")).strip()
|
|
if sql:
|
|
op.get_bind().execute(text(sql))
|
|
|
|
|
|
def downgrade():
|
|
connection = op.get_bind()
|
|
for table, condition in (("tplus_business_documents", "1=1"), ("products", "product_category IS NULL"),
|
|
("customers", "customer_type IS NULL"), ("business_items", "product_category IS NULL"),
|
|
("shipments", "freight_amount IS NULL")):
|
|
if connection.scalar(text(f"SELECT COUNT(*) FROM {table} WHERE {condition}")):
|
|
raise RuntimeError("已有接入或待补资料,请关闭接入并回退兼容版本;不删除业务数据以降级结构")
|
|
op.drop_table("tplus_business_documents")
|
|
op.drop_table("tplus_business_sync_configs")
|
|
for index in ("idx_tplus_source_heads_parent", "idx_tplus_source_heads_customer_date", "idx_tplus_source_heads_date"):
|
|
op.drop_index(index, "tplus_source_heads")
|
|
for column in ("source_parent_id", "source_customer_id", "source_date"):
|
|
op.drop_column("tplus_source_heads", column)
|
|
op.drop_column("businesses", "integration_json")
|
|
for table, column, sql_type, default in (("products", "product_category", "VARCHAR(32)", ""),
|
|
("customers", "customer_type", "VARCHAR(32)", " DEFAULT 'personal'"),
|
|
("business_items", "product_category", "VARCHAR(32)", ""),
|
|
("shipments", "freight_amount", "DECIMAL(14,2)", " DEFAULT 0")):
|
|
connection.execute(text(f"ALTER TABLE {table} MODIFY {column} {sql_type} NOT NULL{default}"))
|