From 85cff19c59ce5ab300e9737c6726fdddece3c92d Mon Sep 17 00:00:00 2001 From: Flea Flicker Date: Wed, 15 Apr 2026 15:25:20 +0000 Subject: [PATCH] fix(GRO-666): make migration 0028 idempotent to resolve E2E failure - Add IF NOT EXISTS to all ADD COLUMN statements (schema already has these columns) - Use DROP CONSTRAINT IF EXISTS for both possible auto-generated constraint names - Idempotent: safe to re-run on databases that already have the schema changes cc @cpfarhood Co-Authored-By: Paperclip --- packages/db/migrations/0028_sms_reminders.sql | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/packages/db/migrations/0028_sms_reminders.sql b/packages/db/migrations/0028_sms_reminders.sql index 4c63eb2..1e7314b 100644 --- a/packages/db/migrations/0028_sms_reminders.sql +++ b/packages/db/migrations/0028_sms_reminders.sql @@ -1,12 +1,15 @@ --- SMS opt-in fields for clients -ALTER TABLE "clients" ADD COLUMN "sms_opt_in" boolean NOT NULL DEFAULT false; -ALTER TABLE "clients" ADD COLUMN "sms_consent_date" timestamp; -ALTER TABLE "clients" ADD COLUMN "sms_opt_out_date" timestamp; -ALTER TABLE "clients" ADD COLUMN "sms_consent_text" text; +-- SMS opt-in fields for clients (idempotent) +ALTER TABLE "clients" ADD COLUMN IF NOT EXISTS "sms_opt_in" boolean NOT NULL DEFAULT false; +ALTER TABLE "clients" ADD COLUMN IF NOT EXISTS "sms_consent_date" timestamp; +ALTER TABLE "clients" ADD COLUMN IF NOT EXISTS "sms_opt_out_date" timestamp; +ALTER TABLE "clients" ADD COLUMN IF NOT EXISTS "sms_consent_text" text; --- Add channel column to reminder_logs with default 'email' -ALTER TABLE "reminder_logs" ADD COLUMN "channel" text NOT NULL DEFAULT 'email'; +-- Add channel column to reminder_logs with default 'email' (idempotent) +ALTER TABLE "reminder_logs" ADD COLUMN IF NOT EXISTS "channel" text NOT NULL DEFAULT 'email'; --- Drop the old unique constraint and recreate with channel -ALTER TABLE "reminder_logs" DROP CONSTRAINT "reminder_logs_appointment_id_reminder_type_unique"; +-- Drop old unique constraints if they exist (idempotent) +ALTER TABLE "reminder_logs" DROP CONSTRAINT IF EXISTS "reminder_logs_appointment_id_reminder_type_key"; +ALTER TABLE "reminder_logs" DROP CONSTRAINT IF EXISTS "reminder_logs_appointment_id_reminder_type_unique"; + +-- Add new unique constraint with channel ALTER TABLE "reminder_logs" ADD CONSTRAINT "reminder_logs_appointment_id_reminder_type_channel_unique" UNIQUE ("appointment_id", "reminder_type", "channel");