diff --git a/packages/db/migrations/0039_extend_pet_profile_columns_idempotent.sql b/packages/db/migrations/0039_extend_pet_profile_columns_idempotent.sql new file mode 100644 index 0000000..f38869b --- /dev/null +++ b/packages/db/migrations/0039_extend_pet_profile_columns_idempotent.sql @@ -0,0 +1,27 @@ +-- Migration: 0039_extend_pet_profile_columns_idempotent.sql +-- GRO-2033: re-register the temperament/medical/preferred-cuts columns from +-- 0034 with an idempotent ADD COLUMN IF NOT EXISTS + a monotonic journal +-- `when` (1780000000001), above the 0033 high-water mark (1779500000000) +-- and above the most recent applied migration 0038 (1780000000000). +-- +-- 0034_extend_pet_profile_columns.sql was authored on 2026-05-28 with +-- `when` = 1751140800000 (2025-06-28) — *below* the 0033 high-water mark +-- of 1779500000000 (2026-05-23). drizzle-orm@0.38.4 +-- (pg-core/dialect.js#migrate) only applies a migration when +-- `migration.folderMillis > lastDbMigration.created_at`, so on prod — +-- whose last applied entry was 0033 at created_at=1779500000000 — 0034 +-- was silently skipped, leaving `pets.temperament_score` (and friends) +-- missing. The migrate Job still exits 0 ("migrations applied +-- successfully!") because the journal high watermark *was* advanced by +-- 0038, but no schema change ever ran for 0034. Seed/reset then crash on: +-- PostgresError: column "temperament_score" does not exist (42703) +-- +-- Same pattern as GRO-1999 (0037 → 0038): do NOT modify 0034 in-place +-- (UAT/dev have already applied it via their lower watermarks). Add a +-- new idempotent migration with a monotonic `when` instead so existing +-- DBs apply it cleanly and fresh DBs are a no-op-after-no-op. + +ALTER TABLE "pets" ADD COLUMN IF NOT EXISTS "temperament_score" integer; +ALTER TABLE "pets" ADD COLUMN IF NOT EXISTS "temperament_flags" jsonb DEFAULT '[]'; +ALTER TABLE "pets" ADD COLUMN IF NOT EXISTS "medical_alerts" jsonb DEFAULT '[]'; +ALTER TABLE "pets" ADD COLUMN IF NOT EXISTS "preferred_cuts" jsonb DEFAULT '[]'; diff --git a/packages/db/migrations/0040_register_missing_coat_type_values.sql b/packages/db/migrations/0040_register_missing_coat_type_values.sql new file mode 100644 index 0000000..88ff7ec --- /dev/null +++ b/packages/db/migrations/0040_register_missing_coat_type_values.sql @@ -0,0 +1,26 @@ +-- Migration: 0040_register_missing_coat_type_values.sql +-- GRO-2033: re-register the 'short' / 'medium' / 'silky' coat_type enum +-- values that 0036 added with `when` = 1751480000000 — *below* the 0033 +-- high-water mark of 1779500000000. drizzle-orm@0.38.4 +-- (pg-core/dialect.js#migrate) silently skipped 0036 on prod for the same +-- reason it skipped 0034 (see 0039). 0036 itself was idempotent +-- (`ADD VALUE IF NOT EXISTS`), but its journal entry was never applied, +-- so the values are not in the prod enum. +-- +-- Same pattern as GRO-1999 (0037 → 0038) and 0039: do NOT modify 0036 in +-- place. Add a new entry with a monotonic `when` (1780000000002) so +-- existing prod re-applies it; UAT/dev are a safe no-op because the +-- statements are `IF NOT EXISTS` and the values are already there. +-- +-- Postgres restriction: `ALTER TYPE ... ADD VALUE` cannot run inside a +-- transaction block, so we emit individual auto-commit DDL statements +-- (no BEGIN/COMMIT). drizzle-kit migrate executes inside a tx; with +-- `ADD VALUE IF NOT EXISTS` Postgres is permissive and treats it as a +-- regular DDL statement that *can* run inside a tx in 9.6+ when no new +-- value is actually added. If you ever rename this to add a value that +-- doesn't exist on every target DB, lift it out of the journal +-- transaction (single-statement file) — see GRO-1999 commit 423d4bf. + +ALTER TYPE "coat_type" ADD VALUE IF NOT EXISTS 'short'; +ALTER TYPE "coat_type" ADD VALUE IF NOT EXISTS 'medium'; +ALTER TYPE "coat_type" ADD VALUE IF NOT EXISTS 'silky'; diff --git a/packages/db/migrations/meta/_journal.json b/packages/db/migrations/meta/_journal.json index 0645748..47e54de 100644 --- a/packages/db/migrations/meta/_journal.json +++ b/packages/db/migrations/meta/_journal.json @@ -267,6 +267,20 @@ "when": 1780000000000, "tag": "0038_register_extra_large_pet_size_category", "breakpoints": true + }, + { + "idx": 39, + "version": "7", + "when": 1780000000001, + "tag": "0039_extend_pet_profile_columns_idempotent", + "breakpoints": true + }, + { + "idx": 40, + "version": "7", + "when": 1780000000002, + "tag": "0040_register_missing_coat_type_values", + "breakpoints": true } ] }