chore: squash the freight migration

This commit is contained in:
ghost2023
2026-08-05 10:46:02 +03:00
parent eb0f071d89
commit 97eca6bed9
301 changed files with 5565 additions and 17932 deletions

View File

@@ -1,9 +1,5 @@
import { AppDataSource } from '../data-source';
import { SeedEdrWagonFleetErNumbering2260000000000 } from '../migrations/2260000000000-SeedEdrWagonFleetErNumbering';
import { AddWagonTrainNumbers2270000000000 } from '../migrations/2270000000000-AddWagonTrainNumbers';
import { SeedWagonRunNumbers2280000000000 } from '../migrations/2280000000000-SeedWagonRunNumbers';
import { WagonNumberPartialUnique2280000000000 } from '../migrations/2280000000000-WagonNumberPartialUnique';
import { SeedWagonYardDoraleh2290000000000 } from '../migrations/2290000000000-SeedWagonYardDoraleh';
import { AppDataSource } from "../data-source";
import { FREIGHT_SEED_SQL } from "../migrations/3250000000000-FreightBaseline";
async function seedEdRWagons() {
await AppDataSource.initialize();
@@ -14,18 +10,13 @@ async function seedEdRWagons() {
await queryRunner.connect();
await queryRunner.startTransaction();
// Fleet first (recreates every wagon with NULL yard + NULL runs), then the
// columns are ensured to exist, then the run roster and the yard are applied
// on top. Same order the migrations run in, so the script and a fresh
// migrate agree.
await new SeedEdrWagonFleetErNumbering2260000000000().up(queryRunner);
await new AddWagonTrainNumbers2270000000000().up(queryRunner);
// Not a wagon seed, but it owns wagon_number uniqueness — included so this
// script leaves the same schema a real `migration:run` would, rather than a
// database missing the partial unique index.
await new WagonNumberPartialUnique2280000000000().up(queryRunner);
await new SeedWagonRunNumbers2280000000000().up(queryRunner);
await new SeedWagonYardDoraleh2290000000000().up(queryRunner);
// Replays the fleet exactly as the baseline migration seeds it on a fresh
// database — wagon numbers, types, run roster and yard already in their final
// state. Wipes first, so this is a reset rather than a top-up. The wagon-seed
// migrations this used to call one by one are now folded into
// `3250000000000-FreightBaseline`.
await queryRunner.query(`DELETE FROM freight.wagons`);
await queryRunner.query(FREIGHT_SEED_SQL.wagons);
const summary = await queryRunner.query(`
SELECT
@@ -74,11 +65,11 @@ async function seedEdRWagons() {
await queryRunner.commitTransaction();
console.log('\nFleet by wagon type:');
console.log("\nFleet by wagon type:");
console.table(summary);
console.log('Run roster (export/import pairs):');
console.log("Run roster (export/import pairs):");
console.table(runs);
console.log('Fleet by yard:');
console.log("Fleet by yard:");
console.table(yards);
console.log(
`Seeded EDR wagon fleet — ${totals.total} wagons total (expected 1100), ` +
@@ -94,6 +85,6 @@ async function seedEdRWagons() {
}
seedEdRWagons().catch((error) => {
console.error('Failed to seed EDR wagon fleet:', error);
console.error("Failed to seed EDR wagon fleet:", error);
process.exit(1);
});