From 529a8eabeb067e62726339894887d54939d19262 Mon Sep 17 00:00:00 2001 From: Potenz Date: Fri, 31 Oct 2025 17:44:32 +0530 Subject: [PATCH] deleted temp file --- migratedb.txt | 56 --------------------------------------------------- 1 file changed, 56 deletions(-) delete mode 100644 migratedb.txt diff --git a/migratedb.txt b/migratedb.txt deleted file mode 100644 index 41df6cb..0000000 --- a/migratedb.txt +++ /dev/null @@ -1,56 +0,0 @@ -1. -``` -npx prisma migrate dev --create-only --name add_patient_status_enum -``` - -2. -``` - --- Create the enum type (quoted name keeps exact case) -DO $$ -BEGIN - IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'PatientStatus') THEN - CREATE TYPE "PatientStatus" AS ENUM ('ACTIVE', 'INACTIVE', 'UNKNOWN'); - END IF; -END$$; - --- 1) Add new enum column (nullable for backfill) -ALTER TABLE "Patient" - ADD COLUMN IF NOT EXISTS "status_new" "PatientStatus"; - --- 2) Backfill from old text column to enum (case-insensitive) -UPDATE "Patient" -SET "status_new" = CASE - WHEN "status" IS NULL THEN 'UNKNOWN'::"PatientStatus" - WHEN lower("status") = 'active' THEN 'ACTIVE'::"PatientStatus" - WHEN lower("status") = 'inactive' THEN 'INACTIVE'::"PatientStatus" - ELSE 'UNKNOWN'::"PatientStatus" -END -WHERE "status_new" IS NULL; - --- 3) Safety: ensure no NULLs remain -DO $$ -DECLARE cnt INTEGER; -BEGIN - SELECT count(*) INTO cnt FROM "Patient" WHERE "status_new" IS NULL; - IF cnt > 0 THEN - RAISE EXCEPTION 'Migration abort: % rows have NULL status_new', cnt; - END IF; -END$$; - --- 4) Make new column NOT NULL and set DB default to UNKNOWN -ALTER TABLE "Patient" - ALTER COLUMN "status_new" SET DEFAULT 'UNKNOWN', - ALTER COLUMN "status_new" SET NOT NULL; - --- 5) Drop old column and rename new -> status -ALTER TABLE "Patient" DROP COLUMN IF EXISTS "status"; -ALTER TABLE "Patient" RENAME COLUMN "status_new" TO "status"; - -``` - - -3. -``` -npx prisma migrate dev -``` \ No newline at end of file