fix(api): NormalizeUserEmailsLower — real table name is users, not Users #195

Merged
amiryahaya merged 1 commit from fix/migration-users-table-casing into main 2026-11-13 12:55:09 +01:00
Owner

Staging outage

Staging API has been crash-looping since the 2026-11-12 14:04 deploy (app-api-1 Restarting(139), 1400+ restarts, ~21h of downtime; staging-deploy smoke has been red on every run since — /health/ never answered).

Cause: 20261112053648_NormalizeUserEmailsLower (#186) contains hand-written raw SQL referencing "Users" — the staging schema is snake_case tables (users) with PascalCase columns (users.Email, folders.IsTenantRoot; see applied AddUserPanicLock, which correctly uses table: "users"). Postgres quoted identifiers are case-sensitive → 42P01: relation "Users" does not exist → unhandled exception in startup MigrateAsync (Program.cs:564) → crash → docker restart → repeat. UniqueTenantRoot (20261112081825, #193) is correct as written — it never ran because this migration crashed first.

Fix

One line: "Users" → users (unquoted lowercase, matching the raw-SQL style of UniqueTenantRoot).

Safe to edit in place: no database has ever applied this migration (any DB with the real schema would crash identically); CI tests use EnsureCreated and never apply migrations.

Verification (local, fresh Postgres container)

  • Before: pre-fix SQL run verbatim on the real schema → ERROR: relation "Users" does not exist (42P01) — byte-identical to the staging crash logs.
  • After: full dotnet ef database update from an empty DB applies all 45 migrations cleanly; ix_folders_one_tenant_root unique index created; history ends at UniqueTenantRoot.
  • dotnet build clean (0 errors).

After merge

staging-deploy auto-fires (paths filter matches src/FailSulit.Api/**) → container should converge, both pending migrations apply, /health/ answers, admin portal (/admin is baked into the api image) comes back with the #187 fix finally live.

Follow-up

Will file: Postgres migration smoke test (apply-all on a real fresh DB + boot) so hand-written SQL gets exercised in CI — this exact bug class (15h+ staging downtime) currently has zero coverage.

## Staging outage Staging API has been crash-looping since the 2026-11-12 14:04 deploy (`app-api-1` Restarting(139), 1400+ restarts, ~21h of downtime; staging-deploy smoke has been red on every run since — `/health/` never answered). **Cause:** `20261112053648_NormalizeUserEmailsLower` (#186) contains hand-written raw SQL referencing `"Users"` — the staging schema is snake_case **tables** (`users`) with PascalCase **columns** (`users.Email`, `folders.IsTenantRoot`; see applied `AddUserPanicLock`, which correctly uses `table: "users"`). Postgres quoted identifiers are case-sensitive → `42P01: relation "Users" does not exist` → unhandled exception in startup `MigrateAsync` (Program.cs:564) → crash → docker restart → repeat. **`UniqueTenantRoot` (20261112081825, #193) is correct as written** — it never ran because this migration crashed first. ## Fix One line: `"Users"` → `users` (unquoted lowercase, matching the raw-SQL style of UniqueTenantRoot). Safe to edit in place: no database has ever applied this migration (any DB with the real schema would crash identically); CI tests use EnsureCreated and never apply migrations. ## Verification (local, fresh Postgres container) - **Before:** pre-fix SQL run verbatim on the real schema → `ERROR: relation "Users" does not exist` (42P01) — byte-identical to the staging crash logs. - **After:** full `dotnet ef database update` from an empty DB applies all 45 migrations cleanly; `ix_folders_one_tenant_root` unique index created; history ends at `UniqueTenantRoot`. - `dotnet build` clean (0 errors). ## After merge staging-deploy auto-fires (paths filter matches `src/FailSulit.Api/**`) → container should converge, both pending migrations apply, `/health/` answers, admin portal (`/admin` is baked into the api image) comes back with the #187 fix finally live. ## Follow-up Will file: Postgres migration smoke test (apply-all on a real fresh DB + boot) so hand-written SQL gets exercised in CI — this exact bug class (15h+ staging downtime) currently has zero coverage.
fix(api): NormalizeUserEmailsLower — real table name is users, not Users
All checks were successful
Security CI / security-scan (pull_request) Successful in 4m17s
API CI / build-and-test (pull_request) Successful in 7m57s
12f249e812
Staging schema is snake_case TABLES / PascalCase COLUMNS (users.Email,
folders.IsTenantRoot — see applied AddUserPanicLock which uses table:
"users"). The hand-written raw SQL referenced "Users" — a table that
does not exist — so the migration crashed with 42P01 on apply and the
API entered a crash-loop on staging at the 2026-11-12 14:04 deploy
(1400+ restarts; /health never answered, staging-deploy smoke red since).

NormalizeUserEmailsLower has never applied anywhere (any DB with the
real schema would crash identically), so editing in place is safe;
UniqueTenantRoot (20261112081825) is correct as written — it never ran
because this migration crashed first.

Verified locally: fresh Postgres + full `dotnet ef database update`
applies all 45 migrations cleanly with the fix (ix_folders_one_tenant_
root created, history ends at UniqueTenantRoot); the pre-fix SQL run
verbatim on the same schema reproduces 42P01 relation "Users" does
not exist — identical to the staging crash logs.
Sign in to join this conversation.
No description provided.