diff --git a/apps/edr-freight-api/src/migrations/1718549400000-FixOrphanedRouteMilestones.ts b/apps/edr-freight-api/src/migrations/1718549400000-FixOrphanedRouteMilestones.ts index d2aa22e8c..c28836194 100644 --- a/apps/edr-freight-api/src/migrations/1718549400000-FixOrphanedRouteMilestones.ts +++ b/apps/edr-freight-api/src/migrations/1718549400000-FixOrphanedRouteMilestones.ts @@ -2,15 +2,14 @@ import { MigrationInterface, QueryRunner } from 'typeorm'; export class FixOrphanedRouteMilestones1718549400000 implements MigrationInterface { public async up(queryRunner: QueryRunner): Promise { - // Clean up orphaned route_milestones records + // Delete orphaned route_milestones records (yard_id is NOT NULL, cannot be set to null) await queryRunner.query(` - UPDATE "freight"."route_milestones" - SET "yard_id" = NULL + DELETE FROM "freight"."route_milestones" WHERE "yard_id" IS NOT NULL AND "yard_id" NOT IN (SELECT "id" FROM "freight"."yards") `); - console.log('✅ Cleaned up orphaned route_milestones records'); + console.log('✅ Deleted orphaned route_milestones records'); } public async down(_queryRunner: QueryRunner): Promise {