31 lines
934 B
Python
31 lines
934 B
Python
|
|
"""迁移 028:海报背景资产、可编辑文档和合规版本。"""
|
|||
|
|
import logging
|
|||
|
|
|
|||
|
|
from sqlalchemy import inspect, text
|
|||
|
|
|
|||
|
|
logger = logging.getLogger(__name__)
|
|||
|
|
|
|||
|
|
|
|||
|
|
def migrate():
|
|||
|
|
"""幂等增加海报可编辑文档字段。"""
|
|||
|
|
from insurance.db.compat import db
|
|||
|
|
|
|||
|
|
existing = {
|
|||
|
|
item["name"]
|
|||
|
|
for item in inspect(db.engine).get_columns("poster_records")
|
|||
|
|
}
|
|||
|
|
columns = {
|
|||
|
|
"document_json": "TEXT",
|
|||
|
|
"document_revision": "INTEGER NOT NULL DEFAULT 1",
|
|||
|
|
"background_file_url": "VARCHAR(500)",
|
|||
|
|
"compliance_json": "TEXT",
|
|||
|
|
"compliance_revision": "VARCHAR(64)",
|
|||
|
|
}
|
|||
|
|
for name, definition in columns.items():
|
|||
|
|
if name not in existing:
|
|||
|
|
db.session.execute(text(
|
|||
|
|
f"ALTER TABLE poster_records ADD COLUMN {name} {definition}"
|
|||
|
|
))
|
|||
|
|
db.session.commit()
|
|||
|
|
logger.info("[migrate_028] 海报可编辑文档字段迁移完成")
|