cmvr-visual/backend/tests/test_schema_v4.py
zhanghao 88cf14d794 feat: consolidate story studio and editable automatic production
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.
2026-11-14 14:07:26 +08:00

67 lines
3.1 KiB
Python
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from pathlib import Path
import pytest
from alembic import command
from alembic.config import Config
from sqlalchemy import create_engine, inspect, text
def test_v4_preserves_private_assets_and_adds_sharing_tombstones(tmp_path):
config = Config(str(Path(__file__).parents[1] / "alembic.ini"))
path = tmp_path / "upgrade-v4.sqlite"
config.attributes["url"] = "sqlite+aiosqlite:///" + str(path)
command.upgrade(config, "003")
engine = create_engine("sqlite:///" + str(path))
with engine.begin() as connection:
connection.execute(
text(
"INSERT INTO visual_users(id,username,display_name,password_hash,role,disabled,must_change_password,created_at) VALUES('owner','owner','Owner','UNCHANGED','user',0,0,CURRENT_TIMESTAMP)"
)
)
connection.execute(
text(
"INSERT INTO visual_assets(id,owner_id,name,storage_key,kind,mime_type,size_bytes,sha256,tags,favorite,origin,ready,created_at) VALUES('asset','owner','Original','owner/asset/source.png','image','image/png',123,:sha,'[]',0,'upload',1,CURRENT_TIMESTAMP)"
),
{"sha": "0" * 64},
)
command.upgrade(config, "004")
command.upgrade(config, "004")
with engine.begin() as connection:
assert connection.scalar(text("SELECT version_num FROM alembic_version")) == "004"
assert connection.execute(
text("SELECT name,size_bytes,library_scope FROM visual_assets WHERE id='asset'")
).one() == ("Original", 123, "private")
assert (
connection.scalar(text("SELECT password_hash FROM visual_users WHERE id='owner'"))
== "UNCHANGED"
)
inspector = inspect(connection)
for name in ["visual_jobs", "visual_drafts", "visual_workflow_runs", "visual_batches"]:
column = next(c for c in inspector.get_columns(name) if c["name"] == "deleted_at")
assert column["nullable"]
assert "visual_shared_assets" in inspector.get_table_names()
# 历å<E280A0>² 004 行为由上方断言ä¿<C3A4>留;当å‰<C3A5> metadata 在全部增é‡<C3A9>å<EFBFBD>‡çº§å<C2A7>Žæ ¡éªŒã€‚
command.upgrade(config, "head")
with engine.begin() as connection:
from app.core.schema import schema_preflight
from app.models import Base
assert schema_preflight(connection, Base.metadata).matches
def test_v4_reruns_after_partial_ddl(tmp_path):
config = Config(str(Path(__file__).parents[1] / "alembic.ini"))
path = tmp_path / "partial-v4.sqlite"
config.attributes["url"] = "sqlite+aiosqlite:///" + str(path)
command.upgrade(config, "003")
engine = create_engine("sqlite:///" + str(path))
with engine.begin() as connection:
connection.execute(text("ALTER TABLE visual_jobs ADD COLUMN deleted_at DATETIME NULL"))
connection.execute(
text(
"ALTER TABLE visual_assets ADD COLUMN library_scope VARCHAR(16) NOT NULL DEFAULT 'private'"
)
)
command.upgrade(config, "004")
with engine.begin() as connection:
assert connection.scalar(text("SELECT version_num FROM alembic_version")) == "004"