refactor(backend): Alembic owns the local schema; v1 ALTER list deleted
Platform v2 step 1.0 (APPS_PLATFORM D-13, D-17). - migrations/ with env.py (render_as_batch, models/all.py metadata, no fileConfig) and baseline 0001_v2_baseline autogenerated from the models and reviewed; it also seeds the pos_settings rows a fresh v1 install got - core/schema.py::upgrade_to_head() is the only way the schema is built: app startup, seed.py, demo_seed.py, wipe_database.py and the tests. It refuses v1 databases (tables without alembic_version) with a clear error - main.py: _run_migrations() and create_all removed (723 lines) - sync_events became a model (was raw DDL); price_event_log order indexes declared on the model; unused order_discounts.price_before/after dropped - tests/guards: no-drift + idempotent upgrade + install defaults + v1 refusal + no create_all; placeholders for the time (1.1) and access (1.5) guards - CS-1 rewritten for Alembic on this branch Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -13,9 +13,8 @@ How the DB tests are isolated (agent notes):
|
||||
* Before anything imports config/database, this file points DATABASE_URL,
|
||||
LOG_DIR and TLS_DIR at a fresh temp folder. Tests can never touch a dev or
|
||||
venue database.
|
||||
* The schema is built once per test session (fixture `_schema`).
|
||||
>>> Step 1.0 (Alembic) must replace the body of `_build_schema` with
|
||||
>>> `alembic upgrade head`, so tests run on exactly the migrated schema.
|
||||
* The schema is built once per test session (fixture `_engine`) with the same
|
||||
Alembic upgrade the app runs at startup, so tests see the migrated schema.
|
||||
* Each test gets one connection with an outer transaction that is rolled
|
||||
back at the end. App code may call db.commit() freely: the session uses
|
||||
join_transaction_mode="create_savepoint", so its commits only release
|
||||
@@ -68,10 +67,9 @@ def pytest_collection_modifyitems(config, items):
|
||||
# ── schema + per-test transaction ───────────────────────────────────────────
|
||||
|
||||
def _build_schema(engine):
|
||||
import main # registers every model; also runs setup_logging() into LOG_DIR
|
||||
from database import Base
|
||||
Base.metadata.create_all(bind=engine)
|
||||
main._run_migrations()
|
||||
import main # noqa: F401 registers every model; also runs setup_logging() into LOG_DIR
|
||||
from core.schema import upgrade_to_head
|
||||
upgrade_to_head(engine)
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
|
||||
Reference in New Issue
Block a user