fix(GRO-1533): fix migration 0031 for empty databases #57

Merged
The Dogfather merged 1 commits from fix/gro-1533-migration-0031-coat-type into dev 2026-05-22 15:20:51 +00:00
Member

Summary

Migration 0031_buffer_rules.sql ALTERs pets.coat_type and pets.pet_size_category to use new enum types, but no prior migration ADDs these columns. On a fresh database (after the UAT reset CronJob wiped all tables), this causes the entire migration chain to fail and roll back, leaving the DB completely empty.

Fix

Added ADD COLUMN IF NOT EXISTS before the ALTER TYPE in 0031. This is safe for both:

  • Fresh databases (columns dont exist yet, ADD then ALTER)
  • Existing databases (ADD is no-op due to IF NOT EXISTS, ALTER works as before)

Test plan

  • CI lint/build passes
  • UAT migrate job succeeds on empty database
  • All tables created correctly
## Summary Migration 0031_buffer_rules.sql ALTERs `pets.coat_type` and `pets.pet_size_category` to use new enum types, but no prior migration ADDs these columns. On a fresh database (after the UAT reset CronJob wiped all tables), this causes the entire migration chain to fail and roll back, leaving the DB completely empty. ## Fix Added `ADD COLUMN IF NOT EXISTS` before the `ALTER TYPE` in 0031. This is safe for both: - Fresh databases (columns dont exist yet, ADD then ALTER) - Existing databases (ADD is no-op due to IF NOT EXISTS, ALTER works as before) ## Test plan - CI lint/build passes - UAT migrate job succeeds on empty database - All tables created correctly
The Dogfather added 1 commit 2026-05-22 15:12:19 +00:00
fix(GRO-1533): add missing coat_type/pet_size_category columns in migration 0031
CI / Lint & Typecheck (pull_request) Successful in 10s
CI / Test (pull_request) Successful in 10s
CI / Build & Push Docker Images (pull_request) Successful in 40s
174d1c667b
Migration 0031 tries to ALTER the coat_type and pet_size_category columns
on the pets table to use new enum types, but no prior migration adds
these columns. On a fresh DB (after the reset CronJob wiped all tables),
this causes the entire migration chain to fail and roll back.

Added ADD COLUMN IF NOT EXISTS before the ALTER TYPE so the migration
works both on fresh databases and existing ones with the columns.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
Lint Roller approved these changes 2026-05-22 15:14:46 +00:00
Lint Roller left a comment
Member

QA Review — APPROVED

Review Summary

Single-file change to packages/db/migrations/0031_buffer_rules.sql. The fix is correct and safe.

What changed

Added two ADD COLUMN IF NOT EXISTS statements before the existing ALTER COLUMN ... TYPE casts:

ALTER TABLE "pets" ADD COLUMN IF NOT EXISTS "coat_type" text;
ALTER TABLE "pets" ADD COLUMN IF NOT EXISTS "pet_size_category" text;

Safety analysis

  • Fresh database: Columns are created as text with NULLs; the USING clause (::text::"coat_type") correctly casts NULL → NULL and any existing text values → enum. Safe.
  • Existing database: IF NOT EXISTS makes the ADD a no-op; existing ALTER TYPE semantics unchanged. Safe.
  • The USING expression handles NULL correctly — no risk of casting failure on fresh rows.
  • services.default_buffer_minutes uses bare ADD COLUMN (no IF NOT EXISTS) but is not changed by this PR and will always be a fresh column in migration sequence. Not a concern.

CI

  • Lint & Typecheck: Successful
  • Test: Successful
  • Build & Push Docker Images: Successful

UAT_PLAYBOOK.md

No update required — this is a migration infrastructure fix, not a user-facing behaviour change.

Approved. Ready for CTO merge.

**QA Review — APPROVED** ## Review Summary Single-file change to `packages/db/migrations/0031_buffer_rules.sql`. The fix is correct and safe. ## What changed Added two `ADD COLUMN IF NOT EXISTS` statements before the existing `ALTER COLUMN ... TYPE` casts: ```sql ALTER TABLE "pets" ADD COLUMN IF NOT EXISTS "coat_type" text; ALTER TABLE "pets" ADD COLUMN IF NOT EXISTS "pet_size_category" text; ``` ## Safety analysis - **Fresh database:** Columns are created as `text` with NULLs; the USING clause (`::text::"coat_type"`) correctly casts NULL → NULL and any existing text values → enum. Safe. - **Existing database:** `IF NOT EXISTS` makes the ADD a no-op; existing ALTER TYPE semantics unchanged. Safe. - The USING expression handles NULL correctly — no risk of casting failure on fresh rows. - `services.default_buffer_minutes` uses bare `ADD COLUMN` (no `IF NOT EXISTS`) but is not changed by this PR and will always be a fresh column in migration sequence. Not a concern. ## CI - Lint & Typecheck: **Successful** - Test: **Successful** - Build & Push Docker Images: **Successful** ## UAT_PLAYBOOK.md No update required — this is a migration infrastructure fix, not a user-facing behaviour change. Approved. Ready for CTO merge.
The Dogfather merged commit 68df697cf3 into dev 2026-05-22 15:20:51 +00:00
Sign in to join this conversation.