forked from CopilotKit/CopilotKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathseed-baseline.ts
More file actions
89 lines (74 loc) · 2.39 KB
/
Copy pathseed-baseline.ts
File metadata and controls
89 lines (74 loc) · 2.39 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/env tsx
/**
* seed-baseline.ts — Seeds PocketBase `baseline` collection from baseline-seed.json.
*
* Run: npx tsx scripts/seed-baseline.ts
*
* Env vars:
* POCKETBASE_URL — PB instance URL (default: http://127.0.0.1:8090)
* PB_ADMIN_EMAIL — admin/superuser email (required)
* PB_ADMIN_PASSWORD — admin/superuser password (required)
*/
import PocketBase from "pocketbase";
import seedData from "../src/data/baseline-seed.json";
const PB_URL = process.env.POCKETBASE_URL ?? "http://127.0.0.1:8090";
const PB_EMAIL = process.env.PB_ADMIN_EMAIL;
const PB_PASSWORD = process.env.PB_ADMIN_PASSWORD;
const BATCH_SIZE = 50;
async function main() {
if (!PB_EMAIL || !PB_PASSWORD) {
console.error("Set PB_ADMIN_EMAIL and PB_ADMIN_PASSWORD env vars");
process.exit(1);
}
const pb = new PocketBase(PB_URL);
// Authenticate: try PB 0.22+ _superusers first, fall back to PB 0.21 admins
try {
await pb.collection("_superusers").authWithPassword(PB_EMAIL, PB_PASSWORD);
} catch {
await (pb as any).admins.authWithPassword(PB_EMAIL, PB_PASSWORD);
}
console.log(`Authenticated. Seeding ${seedData.length} baseline records...`);
let created = 0;
let skipped = 0;
let errors = 0;
for (let i = 0; i < seedData.length; i += BATCH_SIZE) {
const batch = seedData.slice(i, i + BATCH_SIZE);
const promises = batch.map(async (entry) => {
const key = `${entry.partnerSlug}:${entry.featureSlug}`;
try {
const existing = await pb
.collection("baseline")
.getFirstListItem(`key="${key}"`)
.catch(() => null);
if (existing) {
skipped++;
return;
}
await pb.collection("baseline").create({
key,
partner: entry.partnerSlug,
feature: entry.featureSlug,
status: entry.status,
tags: entry.tags,
updated_at: new Date().toISOString(),
updated_by: "seed-script",
});
created++;
} catch (err) {
errors++;
console.error(
` Failed: ${key}:`,
err instanceof Error ? err.message : err,
);
}
});
await Promise.all(promises);
console.log(
` Progress: ${Math.min(i + BATCH_SIZE, seedData.length)}/${seedData.length}`,
);
}
console.log(
`\nDone. Created: ${created}, Skipped: ${skipped}, Errors: ${errors}`,
);
}
main();