Some checks are pending
build-images / api (push) Waiting to run
build-images / worker-gpu (push) Waiting to run
build-images / web (push) Waiting to run
codeql / Analyze (javascript-typescript) (push) Waiting to run
codeql / Analyze (python) (push) Waiting to run
perf / API hot-path micro-smoke (budgeted) (push) Waiting to run
perf / Desktop engine crates (release build check) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (comfy-workflow-schema) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (effects-core) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (eventbus-types) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (growth-analytics) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (trends-schema) (push) Waiting to run
vision2026-ci / API phase modules (ruff + pytest) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (provider-adapter-kit) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (publishing-connectors) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (render-core) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (shot-template-schema) (push) Waiting to run
vision2026-ci / Python SDK resource tests (push) Waiting to run
vision2026-ci / Desktop engine crates (test + clippy + fmt) (push) Waiting to run
vision2026-ci / Alembic upgrade + drift check (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (caption-engine) (push) Waiting to run
Paid, hosted product at menivor.com, now retired as a company project. Fresh squashed history of the cleaned working tree (secret-scanned, no .env, no customer data, no outreach logs). Built on MoneyPrinterTurbo (MIT, harry0703) — see NOTICE.
53 lines
2.3 KiB
Python
53 lines
2.3 KiB
Python
"""Brand Agent migration ``f7b9d1e3a5c8``: idempotent, reversible, and matches the models."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import importlib.util
|
|
from pathlib import Path
|
|
|
|
import sqlalchemy as sa
|
|
from alembic.migration import MigrationContext
|
|
from alembic.operations import Operations
|
|
|
|
from app.domains.brand_agent import models as agent_models
|
|
from app.models.db import models as core_models # noqa: F401 (users/workspaces)
|
|
from app.models.db.base import Base
|
|
|
|
REPO = Path(__file__).resolve().parents[2]
|
|
MIGRATION = REPO / "migrations" / "versions" / "20261006_0900_f7b9d1e3a5c8_brand_agent.py"
|
|
#: Added by a later, additive migration (``b4f6a8c0e2d5_growth_tasks.py``, see
|
|
#: ``test_brand_agent_growth_tasks_migration.py``) -- not this migration's job to create.
|
|
NEWER_TABLES = frozenset({"agent_growth_tasks"})
|
|
NEWER_COLUMNS = frozenset({("agent_library_items", "body")})
|
|
TABLES = sorted(cls.__tablename__ for cls in (getattr(agent_models, n) for n in agent_models.__all__)
|
|
if cls.__tablename__ not in NEWER_TABLES)
|
|
|
|
|
|
def _load():
|
|
spec = importlib.util.spec_from_file_location("brand_agent_migration", MIGRATION)
|
|
module = importlib.util.module_from_spec(spec)
|
|
spec.loader.exec_module(module)
|
|
return module
|
|
|
|
|
|
def test_migration_creates_every_model_table_with_the_model_columns():
|
|
migration = _load()
|
|
assert migration.down_revision == "f4b6d8a0c2e5"
|
|
engine = sa.create_engine("sqlite://")
|
|
Base.metadata.tables["users"].create(engine)
|
|
Base.metadata.tables["workspaces"].create(engine)
|
|
with engine.begin() as conn:
|
|
with Operations.context(MigrationContext.configure(conn)):
|
|
migration.upgrade()
|
|
migration.upgrade() # idempotent
|
|
inspector = sa.inspect(conn)
|
|
assert sorted(t for t in inspector.get_table_names() if t.startswith("agent_")) == TABLES
|
|
for name in TABLES:
|
|
migrated = {c["name"] for c in inspector.get_columns(name)}
|
|
modeled = {c.name for c in Base.metadata.tables[name].columns
|
|
if (name, c.name) not in NEWER_COLUMNS}
|
|
assert migrated == modeled, name
|
|
with Operations.context(MigrationContext.configure(conn)):
|
|
migration.downgrade()
|
|
assert not [t for t in sa.inspect(conn).get_table_names() if t.startswith("agent_")]
|