diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 44be07550..912c6bbd7 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -162,6 +162,17 @@ jobs: -t "${COMPOSE_PROJECT_NAME}-${{ matrix.service }}-migration" \ . + - name: Resolve failed migrations for ${{ matrix.service }} + if: matrix.service == 'passenger-api' + run: | + set -euo pipefail + docker run --rm --env-file "${SERVICE_ENV_FILE}" \ + --entrypoint npx \ + "${COMPOSE_PROJECT_NAME}-${{ matrix.service }}-migration" \ + prisma migrate resolve \ + --applied 20260718144855_unique_constraint_schedule_id_seat_id_departure_station_id \ + || true + - name: Run migrations for ${{ matrix.service }} if: contains(fromJson('["passenger-api", "payment-api"]'), matrix.service) run: | diff --git a/apps/edr-passenger-api/prisma/migrations/20260718144855_unique_constraint_schedule_id_seat_id_departure_station_id/migration.sql b/apps/edr-passenger-api/prisma/migrations/20260718144855_unique_constraint_schedule_id_seat_id_departure_station_id/migration.sql index 2b67ec9cf..a512eeccd 100644 --- a/apps/edr-passenger-api/prisma/migrations/20260718144855_unique_constraint_schedule_id_seat_id_departure_station_id/migration.sql +++ b/apps/edr-passenger-api/prisma/migrations/20260718144855_unique_constraint_schedule_id_seat_id_departure_station_id/migration.sql @@ -4,5 +4,17 @@ - A unique constraint covering the columns `[scheduleId,seatId,departureStationId]` on the table `JourneySegment` will be added. If there are existing duplicate values, this will fail. */ +-- Deduplicate before applying the unique index. +-- Keeps the row with the lowest id per (scheduleId, seatId, departureStationId) group. +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; + -- CreateIndex -CREATE UNIQUE INDEX IF NOT EXISTS "JourneySegment_scheduleId_seatId_departureStationId_key" ON "JourneySegment"("scheduleId", "seatId", "departureStationId"); +CREATE UNIQUE INDEX IF NOT EXISTS "JourneySegment_scheduleId_seatId_departureStationId_key" + ON "JourneySegment"("scheduleId", "seatId", "departureStationId");