mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-09-07 17:45:42 +00:00
fix
This commit is contained in:
@@ -0,0 +1,25 @@
|
|||||||
|
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||||
|
|
||||||
|
export class FixOrphanedRoutes1718549500000 implements MigrationInterface {
|
||||||
|
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
// 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<void> {
|
||||||
|
// No rollback needed for data cleanup
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user