mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-27 00:52:50 +00:00
fix
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
|
||||
export class FixOrphanedBookings1718549600000 implements MigrationInterface {
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
// Delete orphaned bookings records with invalid origin_yard_id
|
||||
await queryRunner.query(`
|
||||
DELETE FROM "freight"."bookings"
|
||||
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"."bookings"
|
||||
WHERE "destination_yard_id" IS NOT NULL
|
||||
AND "destination_yard_id" NOT IN (SELECT "id" FROM "freight"."yards")
|
||||
`);
|
||||
|
||||
console.log('✅ Deleted orphaned bookings records');
|
||||
}
|
||||
|
||||
public async down(_queryRunner: QueryRunner): Promise<void> {
|
||||
// No rollback needed for data cleanup
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user