51 lines
1.6 KiB
JavaScript
51 lines
1.6 KiB
JavaScript
|
|
#!/usr/bin/env node
|
||
|
|
import PocketBase from "pocketbase";
|
||
|
|
|
||
|
|
const PB_URL = "https://pb.jeistk.apphub.co.za";
|
||
|
|
const PB_EMAIL = "david@wfsales.co.za";
|
||
|
|
const PB_PASSWORD = "1234567890";
|
||
|
|
|
||
|
|
const pb = new PocketBase(PB_URL);
|
||
|
|
pb.autoCancellation(false);
|
||
|
|
await pb.admins.authWithPassword(PB_EMAIL, PB_PASSWORD);
|
||
|
|
|
||
|
|
const COL_ID = "pbc_134296766";
|
||
|
|
const col = await pb.collections.getOne(COL_ID);
|
||
|
|
console.log("Loaded collection. Field names:", col.fields.map(f => f.name).join(","));
|
||
|
|
|
||
|
|
// Remove the broken relation field
|
||
|
|
col.fields = col.fields.filter(f => f.name !== "items");
|
||
|
|
|
||
|
|
// Add new items field as JSON
|
||
|
|
col.fields.push({
|
||
|
|
name: "items",
|
||
|
|
type: "json",
|
||
|
|
required: false,
|
||
|
|
options: { maxSize: 2000000 },
|
||
|
|
});
|
||
|
|
|
||
|
|
console.log("Sending update...");
|
||
|
|
try {
|
||
|
|
const updated = await pb.collections.update(COL_ID, col);
|
||
|
|
console.log("Update succeeded, items field now:");
|
||
|
|
const itemsField = updated.fields.find(f => f.name === "items");
|
||
|
|
console.log(JSON.stringify(itemsField, null, 2));
|
||
|
|
|
||
|
|
// Test
|
||
|
|
const test = await pb.collection("quotes").create({
|
||
|
|
quote_number: "QT-SCHEMA-FIX-TEST",
|
||
|
|
customerName: ["dgv6gxgcj2f2o14"],
|
||
|
|
quoteDate: "2026-09-14",
|
||
|
|
status: "Draft",
|
||
|
|
items: ["oz9zgj5xp72m77s", "gfcfv9mkveq95co", "9lfcwus2w5w9h84"],
|
||
|
|
quantities: [1, 2, 1],
|
||
|
|
unitPrices: [1, 2, 3],
|
||
|
|
});
|
||
|
|
console.log("Test quote items:", JSON.stringify(test.items));
|
||
|
|
await pb.collection("quotes").delete(test.id);
|
||
|
|
console.log("✅ schema fix verified");
|
||
|
|
} catch (e) {
|
||
|
|
console.error("Update failed:", e.status, JSON.stringify(e.response || e.data, null, 2));
|
||
|
|
console.error("URL:", e.url);
|
||
|
|
}
|