mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-30 14:38:12 +00:00
Merge branch 'contrat-backup2' of github.com:Tria-plc/edr-platform into contrat-backup2
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||
|
||||
export class AddBookingWindowGlobalRules1861000000000 implements MigrationInterface {
|
||||
name = "AddBookingWindowGlobalRules1861000000000";
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`
|
||||
ALTER TABLE freight.train_scheduling_global_rules
|
||||
ADD COLUMN import_window_lead_days integer NOT NULL DEFAULT 3,
|
||||
ADD COLUMN export_booking_lead_hours integer NOT NULL DEFAULT 24,
|
||||
ADD COLUMN window_open_hour integer NOT NULL DEFAULT 8,
|
||||
ADD COLUMN window_duration_hours numeric(4, 2) NOT NULL DEFAULT 3,
|
||||
ADD COLUMN doc_review_minutes integer NOT NULL DEFAULT 30,
|
||||
ADD COLUMN payment_window_minutes integer NOT NULL DEFAULT 60,
|
||||
ADD COLUMN reopen_delay_minutes integer NOT NULL DEFAULT 90;
|
||||
`);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`
|
||||
ALTER TABLE freight.train_scheduling_global_rules
|
||||
DROP COLUMN IF EXISTS import_window_lead_days,
|
||||
DROP COLUMN IF EXISTS export_booking_lead_hours,
|
||||
DROP COLUMN IF EXISTS window_open_hour,
|
||||
DROP COLUMN IF EXISTS window_duration_hours,
|
||||
DROP COLUMN IF EXISTS doc_review_minutes,
|
||||
DROP COLUMN IF EXISTS payment_window_minutes,
|
||||
DROP COLUMN IF EXISTS reopen_delay_minutes;
|
||||
`);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||
|
||||
/**
|
||||
* arriveSchedule used to release only the primary locomotive of a train set, leaving
|
||||
* secondary locomotives ASSIGNED forever. Locomotives are now only ASSIGNED while out
|
||||
* on a dispatched train — release every ASSIGNED locomotive that is not attached to a
|
||||
* currently-DISPATCHED schedule.
|
||||
*/
|
||||
export class ReleaseStuckAssignedLocomotives1861000000001 implements MigrationInterface {
|
||||
name = "ReleaseStuckAssignedLocomotives1861000000001";
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`
|
||||
UPDATE freight.locomotives l
|
||||
SET status = 'AVAILABLE'
|
||||
WHERE l.status = 'ASSIGNED'
|
||||
AND NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM freight.train_schedules ts
|
||||
JOIN freight.train_sets tset ON tset.id = ts.train_set_id
|
||||
JOIN (
|
||||
SELECT tsl.train_set_id, tsl.locomotive_id
|
||||
FROM freight.train_set_locomotives tsl
|
||||
WHERE tsl.deleted_at IS NULL
|
||||
UNION
|
||||
SELECT t.id AS train_set_id, t.locomotive_id
|
||||
FROM freight.train_sets t
|
||||
WHERE t.locomotive_id IS NOT NULL
|
||||
) loco ON loco.train_set_id = tset.id
|
||||
WHERE ts.status = 'DISPATCHED'
|
||||
AND ts.deleted_at IS NULL
|
||||
AND loco.locomotive_id = l.id
|
||||
);
|
||||
`);
|
||||
}
|
||||
|
||||
public async down(): Promise<void> {
|
||||
// Data fix — not reversible.
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||
|
||||
export class AddScheduleWindowPhases1862000000000 implements MigrationInterface {
|
||||
name = "AddScheduleWindowPhases1862000000000";
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`
|
||||
ALTER TABLE freight.train_schedules
|
||||
ADD COLUMN window_phase varchar(20) NULL,
|
||||
ADD COLUMN window_opens_at timestamptz NULL,
|
||||
ADD COLUMN window_closes_at timestamptz NULL,
|
||||
ADD COLUMN doc_review_ends_at timestamptz NULL,
|
||||
ADD COLUMN doc_review_completed_at timestamptz NULL,
|
||||
ADD COLUMN payment_phase_ends_at timestamptz NULL,
|
||||
ADD COLUMN booking_cycle_no integer NOT NULL DEFAULT 0;
|
||||
`);
|
||||
await queryRunner.query(`
|
||||
CREATE INDEX idx_train_schedules_window_phase
|
||||
ON freight.train_schedules (window_phase)
|
||||
WHERE window_phase IS NOT NULL;
|
||||
`);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`DROP INDEX IF EXISTS freight.idx_train_schedules_window_phase;`);
|
||||
await queryRunner.query(`
|
||||
ALTER TABLE freight.train_schedules
|
||||
DROP COLUMN IF EXISTS window_phase,
|
||||
DROP COLUMN IF EXISTS window_opens_at,
|
||||
DROP COLUMN IF EXISTS window_closes_at,
|
||||
DROP COLUMN IF EXISTS doc_review_ends_at,
|
||||
DROP COLUMN IF EXISTS doc_review_completed_at,
|
||||
DROP COLUMN IF EXISTS payment_phase_ends_at,
|
||||
DROP COLUMN IF EXISTS booking_cycle_no;
|
||||
`);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||
|
||||
export class CreateBookingBatchOffers1863000000000 implements MigrationInterface {
|
||||
name = "CreateBookingBatchOffers1863000000000";
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`
|
||||
CREATE TABLE freight.booking_batch_offers (
|
||||
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
booking_id uuid NOT NULL REFERENCES freight.bookings(id) ON DELETE CASCADE,
|
||||
train_schedule_id uuid NOT NULL REFERENCES freight.train_schedules(id) ON DELETE CASCADE,
|
||||
offered_wagons integer NOT NULL,
|
||||
total_wagons integer NOT NULL,
|
||||
offered_lines jsonb NULL,
|
||||
offered_weight_tons numeric(12, 3) NOT NULL,
|
||||
offered_amount numeric(14, 2) NOT NULL,
|
||||
offered_pricing_breakdown jsonb NULL,
|
||||
invoice_id uuid NULL,
|
||||
payment_deadline timestamptz NOT NULL,
|
||||
status varchar(10) NOT NULL DEFAULT 'OFFERED',
|
||||
created_at timestamptz NOT NULL DEFAULT now(),
|
||||
updated_at timestamptz NOT NULL DEFAULT now(),
|
||||
deleted_at timestamptz NULL
|
||||
);
|
||||
`);
|
||||
await queryRunner.query(
|
||||
`CREATE INDEX idx_booking_batch_offers_booking ON freight.booking_batch_offers (booking_id);`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`CREATE INDEX idx_booking_batch_offers_schedule ON freight.booking_batch_offers (train_schedule_id);`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`CREATE INDEX idx_booking_batch_offers_status ON freight.booking_batch_offers (status);`,
|
||||
);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`DROP TABLE IF EXISTS freight.booking_batch_offers;`);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user