scripts/loaders/miami/metric_definitions.ts
Served verbatim from the project repository. Internal working document conventions apply: documents may reference file paths, branch names, and findings-ledger anchors from the repo.
// Seed miami_metric_definitions with every metric key the Miami loaders
// write. The registry itself lives in data/cities/miami/metric-definitions.ts
// (shared with the app). Idempotent — re-running upserts.
//
// Run: npx tsx scripts/loaders/miami/metric_definitions.ts
import { prisma, runMain } from "./_lib";
import type { MetricDomain, MetricUnit, MetricDirection } from "@prisma/client";
import { MIAMI_METRIC_DEFINITIONS } from "../../../data/cities/miami/metric-definitions";
async function main() {
let n = 0;
for (const d of MIAMI_METRIC_DEFINITIONS) {
const fields = {
displayName: d.displayName, domain: d.domain as MetricDomain, subdomain: d.subdomain, sourceName: d.sourceName, sourceUrl: d.sourceUrl,
unit: d.unit as MetricUnit, direction: d.direction as MetricDirection, description: d.description, derived: d.derived ?? false,
};
await prisma.miamiMetricDefinition.upsert({ where: { key: d.key }, update: fields, create: { key: d.key, ...fields } });
n++;
}
console.log(`[metric_definitions] upserted ${n} Miami metric definitions`);
}
runMain(main);