From dea2a527aa196cde42a3298b8caf156a54f6cb58 Mon Sep 17 00:00:00 2001 From: dum Date: Thu, 27 Nov 2025 14:34:44 +0530 Subject: [PATCH] Rename debrid fields and update user settings Safely adds the 'debrid_service' column and conditionally updates existing rows based on the presence of 'debrid_token'. --- .../migration.sql | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/prisma/migrations/20251119115438_rename_debrid_fields/migration.sql b/prisma/migrations/20251119115438_rename_debrid_fields/migration.sql index 61a7b0e..6f86bb3 100644 --- a/prisma/migrations/20251119115438_rename_debrid_fields/migration.sql +++ b/prisma/migrations/20251119115438_rename_debrid_fields/migration.sql @@ -1,5 +1,21 @@ --- Add debrid_service field (debrid_token was already renamed via db push) -ALTER TABLE "user_settings" ADD COLUMN "debrid_service" VARCHAR(255); +-- Safely add the new 'debrid_service' column if it doesn't exist yet +ALTER TABLE "user_settings" ADD COLUMN IF NOT EXISTS "debrid_service" VARCHAR(255); --- Set default service to 'realdebrid' for existing users who have a token -UPDATE "user_settings" SET "debrid_service" = 'realdebrid' WHERE "debrid_token" IS NOT NULL; +-- Conditionally update existing rows to set the default service to 'realdebrid' +-- only if the 'debrid_token' column actually exists. +DO $$ +BEGIN + IF EXISTS ( + SELECT 1 + FROM information_schema.columns + WHERE table_schema = 'public' + AND table_name = 'user_settings' + AND column_name = 'debrid_token' + ) THEN + -- Use EXECUTE so the UPDATE is not parsed at compile time (avoids errors + -- if the column is missing at parse time in some PostgreSQL versions) + EXECUTE 'UPDATE "user_settings" + SET "debrid_service" = ''realdebrid'' + WHERE "debrid_token" IS NOT NULL'; + END IF; +END $$;