From c12108d95369cae27c385e049c4ce284f7e775a9 Mon Sep 17 00:00:00 2001 From: Marshal Date: Mon, 3 Aug 2026 08:49:07 +0000 Subject: [PATCH] expose per-side facility flags --- .../3180000000000-PortYardFacilityRecords.ts | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 apps/edr-freight-api/src/migrations/3180000000000-PortYardFacilityRecords.ts diff --git a/apps/edr-freight-api/src/migrations/3180000000000-PortYardFacilityRecords.ts b/apps/edr-freight-api/src/migrations/3180000000000-PortYardFacilityRecords.ts new file mode 100644 index 000000000..f07252959 --- /dev/null +++ b/apps/edr-freight-api/src/migrations/3180000000000-PortYardFacilityRecords.ts @@ -0,0 +1,40 @@ +import { MigrationInterface, QueryRunner } from 'typeorm'; + +/** + * 3170 backfilled the per-side facility flags onto EXISTING yard_facilities + * rows, but the Djibouti port yards (Negad, the Doraleh terminals) are flagged + * `has_facility` without ever getting a facility record — the seeder only + * covers the inland intercity facilities. With the contract route picker now + * gating on the per-side flags, those yards report false on every side and + * vanish: import contracts lose all origin options, exports all destinations. + * + * Give every facility-flagged yard that has no live record one with both + * freight types open on both sides — exactly the offerability these yards had + * before the gate existed. Ops can narrow a port from the backoffice yards + * page, which now edits these flags. + */ +export class PortYardFacilityRecords3180000000000 implements MigrationInterface { + name = 'PortYardFacilityRecords3180000000000'; + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(` + INSERT INTO freight.yard_facilities + (yard_id, has_warehouse, handles_container, handles_bulk, + has_container_facility_origin, has_bulk_facility_origin, + has_container_facility_destination, has_bulk_facility_destination) + SELECT y.id, false, true, true, true, true, true, true + FROM freight.yards y + WHERE y.deleted_at IS NULL + AND y.has_facility = true + AND NOT EXISTS ( + SELECT 1 FROM freight.yard_facilities f + WHERE f.yard_id = y.id AND f.deleted_at IS NULL + ) + `); + } + + public async down(): Promise { + // Data seed — the inserted rows are indistinguishable from operator edits + // afterwards, so reversing would risk deleting real configuration. + } +}