From cad5b3fc287a3587a04bbb6ffc2a259730a100a2 Mon Sep 17 00:00:00 2001 From: Matt Date: Thu, 7 May 2026 16:31:08 +0200 Subject: [PATCH] fix(migration): drop default on User.roles before altering type MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The 20260507151706_drop_award_master_role migration failed on prod with 'default for column "roles" cannot be cast automatically to type "UserRole_new"[]'. Postgres won't auto-cast the @default([]) binding through an enum-type swap. Same DROP DEFAULT / SET DEFAULT dance the singular `role` column already had. The original migration ran in a transaction that fully rolled back, so the DB is unchanged — the fixed migration can be applied as-is once the failed record is resolved (DELETE FROM _prisma_migrations WHERE migration_name='20260507151706_drop_award_master_role'). Co-Authored-By: Claude Opus 4.7 (1M context) --- .../20260507151706_drop_award_master_role/migration.sql | 2 ++ 1 file changed, 2 insertions(+) diff --git a/prisma/migrations/20260507151706_drop_award_master_role/migration.sql b/prisma/migrations/20260507151706_drop_award_master_role/migration.sql index 95d6e9e..670e1fb 100644 --- a/prisma/migrations/20260507151706_drop_award_master_role/migration.sql +++ b/prisma/migrations/20260507151706_drop_award_master_role/migration.sql @@ -22,8 +22,10 @@ ALTER TABLE "User" ALTER COLUMN role TYPE "UserRole_new" USING role::text::"UserRole_new"; ALTER TABLE "User" ALTER COLUMN role SET DEFAULT 'APPLICANT'; +ALTER TABLE "User" ALTER COLUMN roles DROP DEFAULT; ALTER TABLE "User" ALTER COLUMN roles TYPE "UserRole_new"[] USING roles::text[]::"UserRole_new"[]; +ALTER TABLE "User" ALTER COLUMN roles SET DEFAULT '{}'::"UserRole_new"[]; DROP TYPE "UserRole"; ALTER TYPE "UserRole_new" RENAME TO "UserRole";