mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-28 23:00:57 +00:00
feat(rule-engine): add yard_locations table, seed 5 facility yard GPS coords
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
|
||||
/**
|
||||
* Creates freight.yard_locations (GPS per yard, decimal degrees WGS84) and
|
||||
* seeds the five facility yards: Sebeta, GMP/Indode (KALITY), Mojo, Adama,
|
||||
* Dire Dawa. Also normalizes has_facility — only those five load/unload cargo.
|
||||
*
|
||||
* Coordinates are approximate — adjust rows directly if surveyed values arrive.
|
||||
*/
|
||||
export class YardGpsLocation3270000000000 implements MigrationInterface {
|
||||
name = 'YardGpsLocation3270000000000';
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`
|
||||
CREATE TABLE IF NOT EXISTS freight.yard_locations (
|
||||
id uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
|
||||
yard_id uuid NOT NULL UNIQUE REFERENCES freight.yards(id) ON DELETE CASCADE,
|
||||
latitude double precision NOT NULL,
|
||||
longitude double precision NOT NULL,
|
||||
created_at timestamptz NOT NULL DEFAULT now(),
|
||||
updated_at timestamptz NOT NULL DEFAULT now(),
|
||||
deleted_at timestamptz
|
||||
)
|
||||
`);
|
||||
|
||||
// LEGACY_DEST is the historical code for Sebeta in some environments.
|
||||
await queryRunner.query(`
|
||||
INSERT INTO freight.yard_locations (yard_id, latitude, longitude)
|
||||
SELECT y.id, v.lat, v.lng
|
||||
FROM (VALUES
|
||||
('SEBETA', 8.9096, 38.6360),
|
||||
('LEGACY_DEST', 8.9096, 38.6360),
|
||||
('KALITY', 8.7386, 38.7913),
|
||||
('MOJO', 8.5794, 39.1200),
|
||||
('ADAMA', 8.5622, 39.2440),
|
||||
('DIRE_DAWA', 9.6009, 41.8103)
|
||||
) AS v(code, lat, lng)
|
||||
JOIN freight.yards y ON y.code = v.code AND y.deleted_at IS NULL
|
||||
ON CONFLICT (yard_id) DO NOTHING
|
||||
`);
|
||||
|
||||
await queryRunner.query(`
|
||||
UPDATE freight.yards
|
||||
SET has_facility = (code IN ('SEBETA', 'LEGACY_DEST', 'KALITY', 'MOJO', 'ADAMA', 'DIRE_DAWA'))
|
||||
WHERE deleted_at IS NULL
|
||||
AND has_facility <> (code IN ('SEBETA', 'LEGACY_DEST', 'KALITY', 'MOJO', 'ADAMA', 'DIRE_DAWA'))
|
||||
`);
|
||||
}
|
||||
|
||||
public async down(): Promise<void> {
|
||||
// Additive table + data normalization; no rollback.
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user