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.
169 lines
5.6 KiB
Python
169 lines
5.6 KiB
Python
"""Destructive rehearsal, restricted to the named isolated verification container.
|
|
Credentials arrive through environment, never command arguments or output.
|
|
"""
|
|
|
|
import asyncio
|
|
import importlib.util
|
|
import json
|
|
import os
|
|
from pathlib import Path
|
|
import sys
|
|
from sqlalchemy import text
|
|
from sqlalchemy.engine import make_url
|
|
from sqlalchemy.ext.asyncio import create_async_engine
|
|
from alembic import command
|
|
from alembic.config import Config
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
sys.path.insert(0, str(ROOT / "backend"))
|
|
from app.core.schema import schema_preflight, check_schema_revision
|
|
|
|
url = make_url(os.environ["CMVR_VERIFY_MYSQL_URL"])
|
|
if url.host != "cmvr-visual-v2-test-mysql":
|
|
raise SystemExit("Refusing non-isolated verification database")
|
|
|
|
|
|
def migration_config(database):
|
|
config = Config(str(ROOT / "backend/alembic.ini"))
|
|
config.attributes["url"] = url.set(database=database)
|
|
return config
|
|
|
|
|
|
async def reset(database):
|
|
engine = create_async_engine(url.set(database="mysql"))
|
|
async with engine.begin() as c:
|
|
# Both names are fixed program constants, never user input.
|
|
await c.execute(text(f"DROP DATABASE IF EXISTS `{database}`"))
|
|
await c.execute(
|
|
text(f"CREATE DATABASE `{database}` CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci")
|
|
)
|
|
await engine.dispose()
|
|
|
|
|
|
def legacy_metadata():
|
|
spec = importlib.util.spec_from_file_location(
|
|
"verify_legacy", ROOT / "backend/alembic/legacy_schema.py"
|
|
)
|
|
module = importlib.util.module_from_spec(spec)
|
|
spec.loader.exec_module(module)
|
|
return module.Base.metadata
|
|
|
|
|
|
async def legacy_setup(database):
|
|
engine = create_async_engine(url.set(database=database))
|
|
meta = legacy_metadata()
|
|
async with engine.begin() as c:
|
|
await c.run_sync(meta.create_all)
|
|
assert (await c.run_sync(schema_preflight, meta)).matches
|
|
await c.execute(
|
|
meta.tables["visual_users"]
|
|
.insert()
|
|
.values(
|
|
id="legacy-owner",
|
|
username="legacy",
|
|
display_name="Legacy",
|
|
password_hash="PRESERVE-EXACT-BYTES",
|
|
role="admin",
|
|
)
|
|
)
|
|
await c.execute(
|
|
meta.tables["visual_jobs"]
|
|
.insert()
|
|
.values(
|
|
id="legacy-job",
|
|
owner_id="legacy-owner",
|
|
task_type="image.generate",
|
|
state="cancelled",
|
|
phase="cancelled",
|
|
input_json={"prompt": "legacy"},
|
|
parameters={},
|
|
request_key="legacy-request",
|
|
request_hash="a" * 64,
|
|
upstream_key="legacy-upstream",
|
|
)
|
|
)
|
|
await c.execute(
|
|
meta.tables["visual_assets"]
|
|
.insert()
|
|
.values(
|
|
id="legacy-asset",
|
|
owner_id="legacy-owner",
|
|
name="kept.png",
|
|
storage_key="legacy/kept.png",
|
|
kind="image",
|
|
mime_type="image/png",
|
|
size_bytes=8,
|
|
sha256="b" * 64,
|
|
tags=["historical"],
|
|
)
|
|
)
|
|
await engine.dispose()
|
|
|
|
|
|
async def interrupt_002(database):
|
|
engine = create_async_engine(url.set(database=database))
|
|
async with engine.begin() as c:
|
|
# MySQL commits this DDL; emulate a process failure before the rest of002.
|
|
await c.execute(
|
|
text(
|
|
"ALTER TABLE visual_users ADD COLUMN must_change_password BOOL NOT NULL DEFAULT false"
|
|
)
|
|
)
|
|
await engine.dispose()
|
|
|
|
|
|
async def verify(database, legacy=False):
|
|
engine = create_async_engine(url.set(database=database))
|
|
async with engine.begin() as c:
|
|
await c.run_sync(check_schema_revision, {"004"})
|
|
if legacy:
|
|
row = (
|
|
await c.execute(
|
|
text(
|
|
"SELECT password_hash,must_change_password FROM visual_users WHERE id='legacy-owner'"
|
|
)
|
|
)
|
|
).one()
|
|
assert tuple(row) == ("PRESERVE-EXACT-BYTES", 0)
|
|
row = (
|
|
await c.execute(
|
|
text(
|
|
"SELECT execution_mode,desired_state,request_hash FROM visual_jobs WHERE id='legacy-job'"
|
|
)
|
|
)
|
|
).one()
|
|
assert tuple(row) == ("interactive", "run", "a" * 64)
|
|
assert (
|
|
await c.execute(
|
|
text(
|
|
"SELECT count(*) FROM visual_asset_tags WHERE asset_id='legacy-asset' AND tag='historical'"
|
|
)
|
|
)
|
|
).scalar() == 1
|
|
await engine.dispose()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
for name in ("cmvr_visual_v2_empty", "cmvr_visual_v2_legacy"):
|
|
asyncio.run(reset(name))
|
|
command.upgrade(migration_config("cmvr_visual_v2_empty"), "head")
|
|
asyncio.run(verify("cmvr_visual_v2_empty"))
|
|
asyncio.run(legacy_setup("cmvr_visual_v2_legacy"))
|
|
command.stamp(migration_config("cmvr_visual_v2_legacy"), "001")
|
|
asyncio.run(interrupt_002("cmvr_visual_v2_legacy"))
|
|
command.upgrade(migration_config("cmvr_visual_v2_legacy"), "head")
|
|
asyncio.run(verify("cmvr_visual_v2_legacy", True))
|
|
command.upgrade(migration_config("cmvr_visual_v2_legacy"), "head")
|
|
asyncio.run(verify("cmvr_visual_v2_legacy", True))
|
|
print(
|
|
json.dumps(
|
|
{
|
|
"mysql": "8.0.36",
|
|
"empty_upgrade": "passed",
|
|
"legacy_preservation": "passed",
|
|
"partial_ddl_recovery": "passed",
|
|
"repeated_upgrade": "passed",
|
|
}
|
|
)
|
|
)
|