"""迁移 039:任务冻结版本与输出审计字段。""" import logging from sqlalchemy import inspect, text logger = logging.getLogger(__name__) COLUMNS = { "snapshot_id": "BIGINT", "snapshot_hash": "VARCHAR(64)", "scenario_version_id": "BIGINT", "scenario_hash": "VARCHAR(64)", "policy_version_id": "BIGINT", "policy_hash": "VARCHAR(64)", "template_version_id": "BIGINT", "template_hash": "VARCHAR(64)", "asset_sha256": "VARCHAR(64)", "renderer_version": "VARCHAR(100)", "submit_revision": "INTEGER", "output_reconciliation_json": "TEXT", "visual_check_json": "TEXT", "result_state": "VARCHAR(20) DEFAULT 'current' NOT NULL", } def migrate(): from insurance.db.compat import db if "insurance_generation_tasks" not in inspect(db.engine).get_table_names(): logger.info("[migrate_039] 任务表不存在,交由模型初始化创建") return existing = {item["name"] for item in inspect(db.engine).get_columns("insurance_generation_tasks")} for name, ddl in COLUMNS.items(): if name not in existing: db.session.execute(text(f"ALTER TABLE insurance_generation_tasks ADD COLUMN {name} {ddl}")) db.session.commit() logger.info("[migrate_039] 任务冻结版本与输出审计字段迁移完成")