test(api): Postgres migration smoke test — apply all migrations to a fresh real DB in CI #196

Open
opened 2026-11-13 13:17:28 +01:00 by amiryahaya · 0 comments
Owner

Why

PR #195: hand-written raw SQL in 20261112053648_NormalizeUserEmailsLower referenced "Users" (table is really users — staging schema is snake_case tables / PascalCase columns). Result: 42P01 on apply → startup MigrateAsync crash → staging API crash-looped ~21h (2026-11-12 14:04 deploy → 2026-11-13 fix; 1400+ restarts, every staging-deploy smoke red since).

Zero CI coverage exists for this bug class: the test suite uses EnsureCreated and never applies migrations (UniqueTenantRoot deliberately documents that its SQL is Postgres-only because tests never apply migrations).

What

  • A dedicated CI leg (or step in api-ci) that:

    1. boots a real Postgres service container (same major version as staging: 17),
    2. runs dotnet ef database update (or db.Database.MigrateAsync() from a tiny harness) against the empty DB,
    3. asserts: migrator reaches HEAD, __EFMigrationsHistory ends at the latest migration,
    4. boots the API against the migrated DB and polls /health/ (catches startup-path regressions beyond migrations),
    5. optionally: re-runs MigrateAsync a second time (idempotency / no-op check).
  • Also worth asserting in the smoke: the snake_case-tables/PascalCase-columns naming convention itself (tables must be users, folders, ...) so a future model rename cannot silently diverge from the live schema.

Constraints

  • Design-time note: DesignTimeDbContextFactory hardcodes localhost:5432 and ignores env vars; use --connection (supported by dotnet ef database update) or the harness MigrateAsync route.
  • Test DB user/password can match the appsettings defaults (failsulit/failsulit) — no secrets needed.

Exit

The #195 bug class fails CI on any future PR that adds broken migration SQL. Regression check: reverting the #195 fix on a branch makes this leg red with 42P01.

Source: PR #195, staging incident 2026-11-12 → 2026-11-13.

## Why PR #195: hand-written raw SQL in `20261112053648_NormalizeUserEmailsLower` referenced `"Users"` (table is really `users` — staging schema is snake_case tables / PascalCase columns). Result: `42P01` on apply → startup `MigrateAsync` crash → **staging API crash-looped ~21h** (2026-11-12 14:04 deploy → 2026-11-13 fix; 1400+ restarts, every staging-deploy smoke red since). Zero CI coverage exists for this bug class: the test suite uses `EnsureCreated` and never applies migrations (`UniqueTenantRoot` deliberately documents that its SQL is Postgres-only because tests never apply migrations). ## What - A dedicated CI leg (or step in api-ci) that: 1. boots a real Postgres service container (same major version as staging: 17), 2. runs `dotnet ef database update` (or `db.Database.MigrateAsync()` from a tiny harness) against the empty DB, 3. asserts: migrator reaches HEAD, `__EFMigrationsHistory` ends at the latest migration, 4. boots the API against the migrated DB and polls `/health/` (catches startup-path regressions beyond migrations), 5. optionally: re-runs `MigrateAsync` a second time (idempotency / no-op check). - Also worth asserting in the smoke: the snake_case-tables/PascalCase-columns naming convention itself (tables must be `users`, `folders`, ...) so a future model rename cannot silently diverge from the live schema. ## Constraints - Design-time note: `DesignTimeDbContextFactory` hardcodes `localhost:5432` and ignores env vars; use `--connection` (supported by `dotnet ef database update`) or the harness `MigrateAsync` route. - Test DB user/password can match the appsettings defaults (`failsulit`/`failsulit`) — no secrets needed. ## Exit The #195 bug class fails CI on any future PR that adds broken migration SQL. Regression check: reverting the #195 fix on a branch makes this leg red with 42P01. **Source**: PR #195, staging incident 2026-11-12 → 2026-11-13.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
primatekuntech/failsulit#196
No description provided.