Restructure backend and frontend modules; add story, library, and editor schema migrations. Support editable automatic production, manual confirmation modes, account and user lifecycle management, compact container scrolling, consistent forms, and per-task result previews. Update inference and TTS scheduling, deployment guidance, and regression coverage; remove obsolete standalone pages and temporary acceptance artifacts.
64 lines
3.2 KiB
Python
64 lines
3.2 KiB
Python
"""Append-only story selections and durable candidate plans; no legacy table changes."""
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
from sqlalchemy.dialects.mysql import DATETIME
|
|
|
|
revision = "005"
|
|
down_revision = "004"
|
|
branch_labels = None
|
|
depends_on = None
|
|
|
|
|
|
def referenced_type(bind, name):
|
|
column = next(c["type"].copy() for c in sa.inspect(bind).get_columns(name) if c["name"] == "id")
|
|
if bind.dialect.name == "mysql":
|
|
charset, collation = bind.execute(sa.text("SELECT CHARACTER_SET_NAME,COLLATION_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME=:name AND COLUMN_NAME='id'"), {"name": name}).one()
|
|
column.charset, column.collation = charset, collation
|
|
return column
|
|
|
|
|
|
def upgrade():
|
|
bind = op.get_bind()
|
|
timestamp = sa.DateTime().with_variant(DATETIME(fsp=6), "mysql")
|
|
metadata = sa.MetaData()
|
|
uid, did = referenced_type(bind, "visual_users"), referenced_type(bind, "visual_drafts")
|
|
sa.Table("visual_users", metadata, sa.Column("id", uid.copy(), primary_key=True))
|
|
sa.Table("visual_drafts", metadata, sa.Column("id", did.copy(), primary_key=True))
|
|
common = lambda: [
|
|
sa.Column("id", sa.String(32), primary_key=True),
|
|
sa.Column("owner_id", uid.copy(), sa.ForeignKey("visual_users.id"), nullable=False, index=True),
|
|
sa.Column("draft_id", did.copy(), sa.ForeignKey("visual_drafts.id"), nullable=False, index=True),
|
|
sa.Column("shot_id", sa.String(32), nullable=False, index=True),
|
|
sa.Column("kind", sa.String(16), nullable=False),
|
|
sa.Column("context_hash", sa.String(64), nullable=False),
|
|
sa.Column("version", sa.Integer(), nullable=False),
|
|
sa.Column("created_at", timestamp, nullable=False),
|
|
]
|
|
candidate = sa.Table("visual_shot_candidates", metadata, *common(),
|
|
sa.Column("source_kind", sa.String(16), nullable=False),
|
|
sa.Column("job_id", sa.String(32), nullable=True, index=True),
|
|
sa.Column("asset_id", sa.String(32), nullable=True),
|
|
sa.Column("asset_sha256", sa.String(64), nullable=True),
|
|
sa.Column("generation_hash", sa.String(64), nullable=False),
|
|
sa.Column("created_revision", sa.Integer(), nullable=False),
|
|
sa.Column("state", sa.String(32), nullable=False),
|
|
sa.Column("plan_json", sa.JSON(), nullable=False),
|
|
sa.Column("error_json", sa.JSON(), nullable=True),
|
|
sa.Column("batch_id", sa.String(32), nullable=True, index=True),
|
|
sa.Column("deleted_at", timestamp, nullable=True))
|
|
selection = sa.Table("visual_shot_selections", metadata, *common(),
|
|
sa.Column("candidate_id", sa.String(32), nullable=True),
|
|
sa.Column("asset_id", sa.String(32), nullable=True),
|
|
sa.Column("decision_json", sa.JSON(), nullable=False),
|
|
sa.UniqueConstraint("draft_id", "shot_id", "kind", "version"))
|
|
for table in (candidate, selection):
|
|
table.create(bind, checkfirst=True)
|
|
existing = {i["name"] for i in sa.inspect(bind).get_indexes(table.name)}
|
|
for index in table.indexes:
|
|
if index.name not in existing:
|
|
index.create(bind, checkfirst=True)
|
|
|
|
|
|
def downgrade():
|
|
raise RuntimeError("Destructive downgrade unsupported; restore a verified joint checkpoint")
|