Files
edr-platform/apps/edr-freight-api/src/migrations/3060000000000-AddExportPaymentWindow.ts
2026-07-30 11:30:34 +00:00

48 lines
2.1 KiB
TypeScript

import { MigrationInterface, QueryRunner } from 'typeorm';
/**
* Export bookings get their own pay window, separately tunable from import:
* - global_rules.export_payment_window_minutes — global default for EXPORT
* (payment_window_minutes keeps governing IMPORT/DOMESTIC).
* - train_schedules.rule_payment_window_minutes — per-schedule override; until
* now the DTO accepted paymentWindowMinutes but only folded it into the
* reopen-delay sum, so the override never reached the actual pay window.
* - bookings.requested_train_schedule_id — the export train the customer picked
* at day-commit; pickExportSchedule honors it instead of earliest-first.
* - bookings.payment_reminder_sent_at — marks the one pre-deadline pay
* reminder so the 10s window tick doesn't re-send it.
*/
export class AddExportPaymentWindow3060000000000 implements MigrationInterface {
name = 'AddExportPaymentWindow3060000000000';
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE freight.train_scheduling_global_rules ADD COLUMN IF NOT EXISTS export_payment_window_minutes int NOT NULL DEFAULT 60;`,
);
await queryRunner.query(
`ALTER TABLE freight.train_schedules ADD COLUMN IF NOT EXISTS rule_payment_window_minutes int;`,
);
await queryRunner.query(
`ALTER TABLE freight.bookings ADD COLUMN IF NOT EXISTS requested_train_schedule_id uuid;`,
);
await queryRunner.query(
`ALTER TABLE freight.bookings ADD COLUMN IF NOT EXISTS payment_reminder_sent_at timestamptz;`,
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE freight.bookings DROP COLUMN IF EXISTS payment_reminder_sent_at;`,
);
await queryRunner.query(
`ALTER TABLE freight.bookings DROP COLUMN IF EXISTS requested_train_schedule_id;`,
);
await queryRunner.query(
`ALTER TABLE freight.train_schedules DROP COLUMN IF EXISTS rule_payment_window_minutes;`,
);
await queryRunner.query(
`ALTER TABLE freight.train_scheduling_global_rules DROP COLUMN IF EXISTS export_payment_window_minutes;`,
);
}
}