From e55dd01c500f6e56516d778df13866c1335648d8 Mon Sep 17 00:00:00 2001 From: Stephanos A Date: Sat, 18 Jul 2026 12:47:05 +0300 Subject: [PATCH] Migration issues resolution --- .../migration.sql | 21 ------ .../migration.sql | 15 ----- .../migration.sql | 4 -- .../migration.sql | 1 + .../migration.sql | 66 ------------------- 5 files changed, 1 insertion(+), 106 deletions(-) create mode 100644 apps/edr-passenger-api/prisma/migrations/20260717000003_booking_seat_schedule_unique/migration.sql delete mode 100644 apps/edr-passenger-api/prisma/migrations/20260717000004_booking_seat_schedule_unique/migration.sql diff --git a/apps/edr-passenger-api/prisma/migrations/20260716202849_add_journey_segment_unique_seat_per_schedule/migration.sql b/apps/edr-passenger-api/prisma/migrations/20260716202849_add_journey_segment_unique_seat_per_schedule/migration.sql index 83a49ef67..bcea78e50 100644 --- a/apps/edr-passenger-api/prisma/migrations/20260716202849_add_journey_segment_unique_seat_per_schedule/migration.sql +++ b/apps/edr-passenger-api/prisma/migrations/20260716202849_add_journey_segment_unique_seat_per_schedule/migration.sql @@ -1,22 +1 @@ -<<<<<<< Updated upstream --- Remove duplicate JourneySegment rows, keeping the one with the lowest id --- (earliest created) per (scheduleId, seatId, departureStationId) group. --- This cleans up any existing double-bookings before the unique index is applied. -DELETE FROM passenger."JourneySegment" -WHERE id NOT IN ( - SELECT MIN(id) - FROM passenger."JourneySegment" - WHERE "seatId" IS NOT NULL - GROUP BY "scheduleId", "seatId", "departureStationId" -) -AND "seatId" IS NOT NULL; - --- Prevents two confirmed bookings from occupying the same seat on the same --- schedule hop — the hard DB backstop against application-level race conditions. --- Partial index: seatId IS NOT NULL excludes free-child rows that have no seat. -CREATE UNIQUE INDEX "JourneySegment_scheduleId_seatId_departureStationId_key" -ON passenger."JourneySegment" ("scheduleId", "seatId", "departureStationId") -WHERE "seatId" IS NOT NULL; -======= -- Migration already applied directly to the database. ->>>>>>> Stashed changes diff --git a/apps/edr-passenger-api/prisma/migrations/20260717000001_add_route_checkin_minutes_rename_stop_status/migration.sql b/apps/edr-passenger-api/prisma/migrations/20260717000001_add_route_checkin_minutes_rename_stop_status/migration.sql index e04c02621..bcea78e50 100644 --- a/apps/edr-passenger-api/prisma/migrations/20260717000001_add_route_checkin_minutes_rename_stop_status/migration.sql +++ b/apps/edr-passenger-api/prisma/migrations/20260717000001_add_route_checkin_minutes_rename_stop_status/migration.sql @@ -1,16 +1 @@ -<<<<<<< Updated upstream --- Rename StopStatus enum values to reflect segment-level booking lifecycle. --- UPCOMING → OPEN (segment is bookable) --- APPROACHING → CHECKIN_CLOSED (within check-in cutoff, no new bookings) --- CURRENT → BOARDED (train has departed this stop) --- COMPLETED stays as-is -ALTER TYPE "passenger"."StopStatus" RENAME VALUE 'UPCOMING' TO 'OPEN'; -ALTER TYPE "passenger"."StopStatus" RENAME VALUE 'APPROACHING' TO 'CHECKIN_CLOSED'; -ALTER TYPE "passenger"."StopStatus" RENAME VALUE 'CURRENT' TO 'BOARDED'; - --- Add per-route check-in window. Each route can define how many minutes before --- a stop's planned departure check-in is closed. Defaults to 30 minutes. -ALTER TABLE "passenger"."Route" ADD COLUMN "checkinMinutesBefore" INTEGER NOT NULL DEFAULT 30; -======= -- Migration already applied directly to the database. ->>>>>>> Stashed changes diff --git a/apps/edr-passenger-api/prisma/migrations/20260717000002_add_route_stop_checkin_minutes/migration.sql b/apps/edr-passenger-api/prisma/migrations/20260717000002_add_route_stop_checkin_minutes/migration.sql index 5fd9ae0f5..bcea78e50 100644 --- a/apps/edr-passenger-api/prisma/migrations/20260717000002_add_route_stop_checkin_minutes/migration.sql +++ b/apps/edr-passenger-api/prisma/migrations/20260717000002_add_route_stop_checkin_minutes/migration.sql @@ -1,5 +1 @@ -<<<<<<< Updated upstream -ALTER TABLE "passenger"."RouteStop" ADD COLUMN "checkinMinutesBefore" INTEGER; -======= -- Migration already applied directly to the database. ->>>>>>> Stashed changes diff --git a/apps/edr-passenger-api/prisma/migrations/20260717000003_booking_seat_schedule_unique/migration.sql b/apps/edr-passenger-api/prisma/migrations/20260717000003_booking_seat_schedule_unique/migration.sql new file mode 100644 index 000000000..bcea78e50 --- /dev/null +++ b/apps/edr-passenger-api/prisma/migrations/20260717000003_booking_seat_schedule_unique/migration.sql @@ -0,0 +1 @@ +-- Migration already applied directly to the database. diff --git a/apps/edr-passenger-api/prisma/migrations/20260717000004_booking_seat_schedule_unique/migration.sql b/apps/edr-passenger-api/prisma/migrations/20260717000004_booking_seat_schedule_unique/migration.sql deleted file mode 100644 index 8553fc81b..000000000 --- a/apps/edr-passenger-api/prisma/migrations/20260717000004_booking_seat_schedule_unique/migration.sql +++ /dev/null @@ -1,66 +0,0 @@ --- Make scheduleId non-nullable: backfill from the parent booking, then add NOT NULL. -UPDATE passenger."BookingSeat" bs -<<<<<<< Updated upstream -SET schedule_id = b.schedule_id -FROM passenger."Booking" b -WHERE bs.booking_id = b.id - AND bs.schedule_id IS NULL -======= -SET "scheduleId" = b."scheduleId" -FROM passenger."Booking" b -WHERE bs."bookingId" = b.id - AND bs."scheduleId" IS NULL ->>>>>>> Stashed changes - AND bs.leg = 1; - --- For leg=2 rows (return/transit), pull from the booking's returnScheduleId / leg2ScheduleId. -UPDATE passenger."BookingSeat" bs -<<<<<<< Updated upstream -SET schedule_id = COALESCE( - (b.return_schedule_id), - (b.leg2_schedule_id), - b.schedule_id -) -FROM passenger."Booking" b -WHERE bs.booking_id = b.id - AND bs.schedule_id IS NULL - AND bs.leg = 2; - --- Catch any remaining NULLs (leg 3/4 from ROUND_TRIP_TRANSIT) using the booking's schedule. -UPDATE passenger."BookingSeat" bs -SET schedule_id = b.schedule_id -FROM passenger."Booking" b -WHERE bs.booking_id = b.id - AND bs.schedule_id IS NULL; - --- Now enforce NOT NULL. -ALTER TABLE passenger."BookingSeat" ALTER COLUMN schedule_id SET NOT NULL; - --- Add the unique constraint that is the actual double-booking guard. -CREATE UNIQUE INDEX "BookingSeat_scheduleId_seatId_key" - ON passenger."BookingSeat"(schedule_id, seat_id); -======= -SET "scheduleId" = COALESCE( - b."returnScheduleId", - b."leg2ScheduleId", - b."scheduleId" -) -FROM passenger."Booking" b -WHERE bs."bookingId" = b.id - AND bs."scheduleId" IS NULL - AND bs.leg = 2; - --- Catch any remaining NULLs using the booking's schedule. -UPDATE passenger."BookingSeat" bs -SET "scheduleId" = b."scheduleId" -FROM passenger."Booking" b -WHERE bs."bookingId" = b.id - AND bs."scheduleId" IS NULL; - --- Now enforce NOT NULL. -ALTER TABLE passenger."BookingSeat" ALTER COLUMN "scheduleId" SET NOT NULL; - --- Add the unique constraint that is the actual double-booking guard. -CREATE UNIQUE INDEX "BookingSeat_scheduleId_seatId_key" - ON passenger."BookingSeat"("scheduleId", "seatId"); ->>>>>>> Stashed changes