From 2b5db67bcdeca367c3b2006b5973f7d4aeaac617 Mon Sep 17 00:00:00 2001 From: natib21 Date: Tue, 16 Jun 2026 06:33:43 +0000 Subject: [PATCH] fix --- ...718549400000-FixOrphanedRouteMilestones.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 apps/edr-freight-api/src/migrations/1718549400000-FixOrphanedRouteMilestones.ts diff --git a/apps/edr-freight-api/src/migrations/1718549400000-FixOrphanedRouteMilestones.ts b/apps/edr-freight-api/src/migrations/1718549400000-FixOrphanedRouteMilestones.ts new file mode 100644 index 000000000..cc8768868 --- /dev/null +++ b/apps/edr-freight-api/src/migrations/1718549400000-FixOrphanedRouteMilestones.ts @@ -0,0 +1,19 @@ +import { MigrationInterface, QueryRunner } from 'typeorm'; + +export class FixOrphanedRouteMilestones1718549400000 implements MigrationInterface { + public async up(queryRunner: QueryRunner): Promise { + // Clean up orphaned route_milestones records + await queryRunner.query(` + UPDATE "freight"."route_milestones" + SET "yard_id" = NULL + WHERE "yard_id" IS NOT NULL + AND "yard_id" NOT IN (SELECT "id" FROM "freight"."yards") + `); + + console.log('✅ Cleaned up orphaned route_milestones records'); + } + + public async down(queryRunner: QueryRunner): Promise { + // No rollback needed for data cleanup + } +}