diff --git a/apps/edr-freight-api/src/migrations/1718549400000-FixOrphanedRouteMilestones.ts b/apps/edr-freight-api/src/migrations/1718549400000-FixOrphanedRouteMilestones.ts deleted file mode 100644 index c28836194..000000000 --- a/apps/edr-freight-api/src/migrations/1718549400000-FixOrphanedRouteMilestones.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { MigrationInterface, QueryRunner } from 'typeorm'; - -export class FixOrphanedRouteMilestones1718549400000 implements MigrationInterface { - public async up(queryRunner: QueryRunner): Promise { - // Delete orphaned route_milestones records (yard_id is NOT NULL, cannot be set to null) - await queryRunner.query(` - DELETE FROM "freight"."route_milestones" - WHERE "yard_id" IS NOT NULL - AND "yard_id" NOT IN (SELECT "id" FROM "freight"."yards") - `); - - console.log('✅ Deleted orphaned route_milestones records'); - } - - public async down(_queryRunner: QueryRunner): Promise { - // No rollback needed for data cleanup - } -} diff --git a/apps/edr-freight-api/src/migrations/1718549500000-FixOrphanedRoutes.ts b/apps/edr-freight-api/src/migrations/1718549500000-FixOrphanedRoutes.ts deleted file mode 100644 index bfd9994f3..000000000 --- a/apps/edr-freight-api/src/migrations/1718549500000-FixOrphanedRoutes.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { MigrationInterface, QueryRunner } from 'typeorm'; - -export class FixOrphanedRoutes1718549500000 implements MigrationInterface { - public async up(queryRunner: QueryRunner): Promise { - // Delete orphaned routes records with invalid origin_yard_id - await queryRunner.query(` - DELETE FROM "freight"."routes" - WHERE "origin_yard_id" IS NOT NULL - AND "origin_yard_id" NOT IN (SELECT "id" FROM "freight"."yards") - `); - - // Also clean up destination_yard_id if it exists and has the same issue - await queryRunner.query(` - DELETE FROM "freight"."routes" - WHERE "destination_yard_id" IS NOT NULL - AND "destination_yard_id" NOT IN (SELECT "id" FROM "freight"."yards") - `); - - console.log('✅ Deleted orphaned routes records'); - } - - public async down(_queryRunner: QueryRunner): Promise { - // No rollback needed for data cleanup - } -} diff --git a/apps/edr-freight-api/src/migrations/1718549600000-FixOrphanedBookings.ts b/apps/edr-freight-api/src/migrations/1718549600000-FixOrphanedBookings.ts deleted file mode 100644 index a51adbaa0..000000000 --- a/apps/edr-freight-api/src/migrations/1718549600000-FixOrphanedBookings.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { MigrationInterface, QueryRunner } from 'typeorm'; - -export class FixOrphanedBookings1718549600000 implements MigrationInterface { - public async up(queryRunner: QueryRunner): Promise { - // First, delete orphaned unloading_registrations that reference bookings with invalid yards - await queryRunner.query(` - DELETE FROM "freight"."unloading_registrations" - WHERE "booking_id" IN ( - SELECT b."id" FROM "freight"."bookings" b - WHERE ( - ("origin_yard_id" IS NOT NULL AND "origin_yard_id" NOT IN (SELECT "id" FROM "freight"."yards")) - OR - ("destination_yard_id" IS NOT NULL AND "destination_yard_id" NOT IN (SELECT "id" FROM "freight"."yards")) - ) - ) - `); - - // Delete orphaned bookings records with invalid origin_yard_id - await queryRunner.query(` - DELETE FROM "freight"."bookings" - WHERE "origin_yard_id" IS NOT NULL - AND "origin_yard_id" NOT IN (SELECT "id" FROM "freight"."yards") - `); - - // Also clean up destination_yard_id if it exists and has the same issue - await queryRunner.query(` - DELETE FROM "freight"."bookings" - WHERE "destination_yard_id" IS NOT NULL - AND "destination_yard_id" NOT IN (SELECT "id" FROM "freight"."yards") - `); - - console.log('✅ Deleted orphaned unloading_registrations and bookings records'); - } - - public async down(_queryRunner: QueryRunner): Promise { - // No rollback needed for data cleanup - } -}