This commit is contained in:
natib21
2026-06-16 06:33:43 +00:00
parent ba4ebee59d
commit 2b5db67bcd

View File

@@ -0,0 +1,19 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
export class FixOrphanedRouteMilestones1718549400000 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
// 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<void> {
// No rollback needed for data cleanup
}
}