This commit is contained in:
natib21
2026-06-16 06:39:59 +00:00
parent 0198b545c9
commit 8362bd94c5

View File

@@ -2,15 +2,14 @@ import { MigrationInterface, QueryRunner } from 'typeorm';
export class FixOrphanedRouteMilestones1718549400000 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
// 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<void> {