mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-29 19:58:11 +00:00
Merge pull request #1063 from Tria-plc/freight_feature/usermanagement
Freight feature/usermanagement
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
|
||||
/**
|
||||
* Break-bulk (PER_ITEM) cargo needs a physical items-fit per allowed wagon
|
||||
* type (e.g. cars → NW5: 4, NW7: 6): a wagon runs out of floor space before it
|
||||
* runs out of rated tonnage, so allocation must respect BOTH limits. Stored as
|
||||
* a jsonb map { [wagonTypeId]: itemsFit } on cargo_types — keys mirror the
|
||||
* cargo_type_wagon_types join rows, kept in sync by the cargo-types service.
|
||||
*/
|
||||
export class AddCargoTypeItemsPerWagonMap3120000000000 implements MigrationInterface {
|
||||
name = 'AddCargoTypeItemsPerWagonMap3120000000000';
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "freight"."cargo_types" ADD COLUMN IF NOT EXISTS "items_per_wagon_map" jsonb`,
|
||||
);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "freight"."cargo_types" DROP COLUMN IF EXISTS "items_per_wagon_map"`,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
|
||||
/**
|
||||
* Rates created before their commodity's unit_of_measure was flipped kept the
|
||||
* old bulk-quantity unit, so bookings of a PER_ITEM commodity (e.g. Machinery)
|
||||
* quoted "per ton". PER_TON and PER_ITEM bill the same stored quantity — only
|
||||
* the name differs — so renaming is safe. Going forward the cargo-types
|
||||
* service syncs rates on every uom change; this backfills the drift.
|
||||
*/
|
||||
export class SyncBulkRateUnitsToCargoUom3140000000000 implements MigrationInterface {
|
||||
name = 'SyncBulkRateUnitsToCargoUom3140000000000';
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(
|
||||
`UPDATE "freight"."rates" r
|
||||
SET "rate_unit" = 'PER_ITEM'
|
||||
FROM "freight"."cargo_types" ct
|
||||
WHERE ct."id" = r."cargo_type_id"
|
||||
AND ct."unit_of_measure" = 'PER_ITEM'
|
||||
AND r."rate_unit" = 'PER_TON'`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`UPDATE "freight"."rates" r
|
||||
SET "rate_unit" = 'PER_TON'
|
||||
FROM "freight"."cargo_types" ct
|
||||
WHERE ct."id" = r."cargo_type_id"
|
||||
AND ct."unit_of_measure" = 'PER_TON'
|
||||
AND r."rate_unit" = 'PER_ITEM'`,
|
||||
);
|
||||
}
|
||||
|
||||
public async down(): Promise<void> {
|
||||
// Irreversible rename-by-join: the pre-sync unit is not recorded. Both
|
||||
// units bill identically, so rolling back the code needs no data change.
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user