mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-26 18:42:49 +00:00
39 lines
1.5 KiB
TypeScript
39 lines
1.5 KiB
TypeScript
import { MigrationInterface, QueryRunner } from 'typeorm';
|
|
|
|
/**
|
|
* Clearance charges are no longer one-of-each in a fixed order: GL Ethiopia
|
|
* may raise several MISCELLANEOUS charges, and either level may be created
|
|
* first. Port charges stay unique per booking (one port bill per shipment),
|
|
* enforced by a partial index instead of the old blanket (booking_id, type)
|
|
* uniqueness that also capped miscellaneous at one.
|
|
*/
|
|
export class MultipleMiscClearanceCharges3610000000000
|
|
implements MigrationInterface
|
|
{
|
|
name = 'MultipleMiscClearanceCharges3610000000000';
|
|
|
|
public async up(queryRunner: QueryRunner): Promise<void> {
|
|
await queryRunner.query(`
|
|
DROP INDEX IF EXISTS "freight"."uq_booking_clearance_charge_booking_type"
|
|
`);
|
|
await queryRunner.query(`
|
|
CREATE UNIQUE INDEX IF NOT EXISTS "uq_booking_clearance_charge_port"
|
|
ON "freight"."booking_clearance_charge" ("booking_id")
|
|
WHERE "type" = 'PORT_CHARGES' AND "deleted_at" IS NULL
|
|
`);
|
|
await queryRunner.query(`
|
|
CREATE INDEX IF NOT EXISTS "idx_booking_clearance_charge_booking"
|
|
ON "freight"."booking_clearance_charge" ("booking_id")
|
|
`);
|
|
}
|
|
|
|
public async down(queryRunner: QueryRunner): Promise<void> {
|
|
// No-op on the uniqueness: restoring the blanket (booking_id, type) index
|
|
// would fail on any booking that has since raised a second miscellaneous
|
|
// charge, which is exactly what this migration set out to allow.
|
|
await queryRunner.query(`
|
|
DROP INDEX IF EXISTS "freight"."uq_booking_clearance_charge_port"
|
|
`);
|
|
}
|
|
}
|