fix: a rollback never stops the database from starting; schema changes are migration files

schema.sql dropped and re-added three CHECK constraints on every start, so
an older image narrowed the lists and failed on rows written by a newer one
(an Expedição user, for example). They are now created only when missing,
and app/migrate.py applies timestamped files from app/migrations/ once each,
recording them in dtf_local.migrations; an older image skips names it does
not know. The first migration sets today's full lists. A CI step rehearses
the rollback on the real database inside a rolled-back transaction.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Cauê Faleiros
2026-11-09 16:11:30 -03:00
parent 63af984e83
commit 6b7ef1c4c8
11 changed files with 278 additions and 12 deletions

View File

@@ -23,6 +23,7 @@ jobs:
deploy.test_production_preflight \
tests.test_pricing \
tests.test_coupons \
tests.test_migrate \
tests.test_secrets -v
sh -n infra/lock_dependencies.sh
@@ -67,6 +68,12 @@ jobs:
$COMPOSE up --build -d --wait --wait-timeout 600
$COMPOSE ps
# The database never blocks a rollback. Runs in db-init, the only job
# with the administrator connection; the whole test is rolled back, so
# nothing it inserts or alters remains.
- name: Rollback and migrations
run: $COMPOSE run --rm --no-deps db-init python -m tests.migrations_test
# Run inside the stack's own network. The runner is itself a container, so
# ports published on the host's loopback are in a different namespace and
# unreachable from here. SITE_HOST_HEADER keeps the Host the gateway and