-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata.json
More file actions
54 lines (48 loc) · 1.54 KB
/
Copy pathdata.json
File metadata and controls
54 lines (48 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/* /home/ass/src/fastify-prisma-backend/scripts/upload-reports.js */
const fs = require("node:fs");
const path = require("node:path");
const { PrismaClient } = require("@prisma/client");
const prisma = new PrismaClient();
async function main() {
const filePath = path.join(__dirname, "..", "data.json");
const raw = fs.readFileSync(filePath, "utf-8");
const parsed = JSON.parse(raw);
const reports = parsed.heatmap ?? [];
if (!reports.length) {
throw new Error("No heatmap data found in data.json");
}
// Upsert so existing rows are updated and new rows are inserted.
for (const r of reports) {
await prisma.report.upsert({
where: { id: r.id }, // requires id to be unique in Report model
update: {
lat: r.lat,
lng: r.lng,
intensity: r.intensity,
label: r.label,
city: r.city,
state: r.state,
category: r.category,
},
create: {
id: r.id,
lat: r.lat,
lng: r.lng,
intensity: r.intensity,
label: r.label,
city: r.city,
state: r.state,
category: r.category,
},
});
}
console.log(`Uploaded ${reports.length} reports successfully.`);
}
main()
.catch((e) => {
console.error("Upload failed:", e);
process.exit(1);
})
.finally(async () => {
await prisma.$disconnect();
});