seed vehicle

This commit is contained in:
natib21
2026-07-17 11:30:25 +00:00
parent 35303ece58
commit 149e4105f4
3 changed files with 57 additions and 2 deletions

View File

@@ -0,0 +1,42 @@
import { AppDataSource } from '../data-source';
import { EdrTruckFleetSeeder } from '../seed/edr-truck-fleet.seeder';
/**
* Seeds the 62-truck EDR fleet used by first-mile / last-mile.
*
* The seeder is idempotent (`ON CONFLICT (plate_number) DO NOTHING`), so a
* re-run will NOT overwrite a truck whose rate was corrected by hand — the
* seeded rate is a placeholder and is meant to be replaced.
*/
async function seedEdrTrucks() {
await AppDataSource.initialize();
try {
await new EdrTruckFleetSeeder(AppDataSource).run();
const summary = await AppDataSource.query(`
SELECT
COUNT(*)::int AS trucks,
COUNT(*) FILTER (WHERE status = 'ACTIVE')::int AS active,
COUNT(*) FILTER (WHERE availability = 'FREE')::int AS free,
COUNT(*) FILTER (WHERE price_per_km > 0)::int AS priced,
COUNT(*) FILTER (WHERE price_per_km IS NULL OR price_per_km <= 0)::int AS unpriced,
MIN(price_per_km)::text AS min_rate,
MAX(price_per_km)::text AS max_rate
FROM freight.vehicles
WHERE vehicle_type = 'TRUCK';
`);
console.table(summary);
console.log(
'Seeded EDR truck fleet. NOTE: price_per_km is DEMO DATA — replace with the real tariff before billing.',
);
} finally {
await AppDataSource.destroy();
}
}
seedEdrTrucks().catch((error) => {
console.error('Failed to seed EDR truck fleet:', error);
process.exit(1);
});