mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-26 18:42:49 +00:00
Migration issue resolution
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
<<<<<<< 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.
|
||||
@@ -16,3 +17,6 @@ AND "seatId" IS NOT NULL;
|
||||
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
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
<<<<<<< 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)
|
||||
@@ -10,3 +11,6 @@ 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
|
||||
|
||||
@@ -1 +1,5 @@
|
||||
<<<<<<< Updated upstream
|
||||
ALTER TABLE "passenger"."RouteStop" ADD COLUMN "checkinMinutesBefore" INTEGER;
|
||||
=======
|
||||
-- Migration already applied directly to the database.
|
||||
>>>>>>> Stashed changes
|
||||
|
||||
@@ -1,13 +1,21 @@
|
||||
-- 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),
|
||||
@@ -31,3 +39,28 @@ 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
|
||||
|
||||
Reference in New Issue
Block a user