From 85cd6cdf2a18f7cf01db0febf501b7fc62698154 Mon Sep 17 00:00:00 2001 From: Roba Boru Date: Sun, 19 Jul 2026 17:54:06 +0300 Subject: [PATCH] fix(passenger-api): repair StopStatus enum values in deployed DB The init migration created StopStatus with UPCOMING/APPROACHING/CURRENT/COMPLETED. Migration 20260717000001 was an empty no-op file that claimed the rename was "applied directly", but the ALTER TYPE RENAME VALUE SQL was never executed on deployed environments. TripStopTime rows with status='UPCOMING' cause P2023 (PrismaClientKnownRequestError) on every search call that includes stopTimes. This idempotent migration checks pg_enum before renaming so it is safe to run whether or not the rename was previously applied. Co-Authored-By: Claude Sonnet 4.6 --- .../migration.sql | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 apps/edr-passenger-api/prisma/migrations/20260719000001_repair_stop_status_enum/migration.sql diff --git a/apps/edr-passenger-api/prisma/migrations/20260719000001_repair_stop_status_enum/migration.sql b/apps/edr-passenger-api/prisma/migrations/20260719000001_repair_stop_status_enum/migration.sql new file mode 100644 index 000000000..f744dfcbc --- /dev/null +++ b/apps/edr-passenger-api/prisma/migrations/20260719000001_repair_stop_status_enum/migration.sql @@ -0,0 +1,53 @@ +-- Repair StopStatus enum values. +-- The init migration created: COMPLETED, APPROACHING, CURRENT, UPCOMING +-- The current Prisma schema expects: OPEN, CHECKIN_CLOSED, BOARDED, COMPLETED +-- Migration 20260717000001 was supposed to rename these directly but its SQL +-- file is empty (marked "already applied"), so the rename may not have run +-- on all deployed environments. This migration is idempotent: it only renames +-- a value if the old label still exists in pg_enum. + +DO $$ +DECLARE + v_has_upcoming boolean; + v_has_approaching boolean; + v_has_current boolean; +BEGIN + SELECT EXISTS ( + SELECT 1 FROM pg_enum e + JOIN pg_type t ON e.enumtypid = t.oid + JOIN pg_namespace n ON t.typnamespace = n.oid + WHERE n.nspname = 'passenger' AND t.typname = 'StopStatus' AND e.enumlabel = 'UPCOMING' + ) INTO v_has_upcoming; + + SELECT EXISTS ( + SELECT 1 FROM pg_enum e + JOIN pg_type t ON e.enumtypid = t.oid + JOIN pg_namespace n ON t.typnamespace = n.oid + WHERE n.nspname = 'passenger' AND t.typname = 'StopStatus' AND e.enumlabel = 'APPROACHING' + ) INTO v_has_approaching; + + SELECT EXISTS ( + SELECT 1 FROM pg_enum e + JOIN pg_type t ON e.enumtypid = t.oid + JOIN pg_namespace n ON t.typnamespace = n.oid + WHERE n.nspname = 'passenger' AND t.typname = 'StopStatus' AND e.enumlabel = 'CURRENT' + ) INTO v_has_current; + + IF v_has_upcoming THEN + ALTER TYPE passenger."StopStatus" RENAME VALUE 'UPCOMING' TO 'OPEN'; + END IF; + + IF v_has_approaching THEN + ALTER TYPE passenger."StopStatus" RENAME VALUE 'APPROACHING' TO 'CHECKIN_CLOSED'; + END IF; + + IF v_has_current THEN + ALTER TYPE passenger."StopStatus" RENAME VALUE 'CURRENT' TO 'BOARDED'; + END IF; +END $$; + +-- Reset column default to the current enum label name. +-- If the old label 'UPCOMING' was just renamed to 'OPEN', the stored DEFAULT +-- string 'UPCOMING' becomes invalid and must be updated. +ALTER TABLE passenger."TripStopTime" ALTER COLUMN "status" DROP DEFAULT; +ALTER TABLE passenger."TripStopTime" ALTER COLUMN "status" SET DEFAULT 'OPEN';