// Add `qr_code` to `assets` (idempotent): the text printed in the QR sticker on a vehicle, // typed into the Plant Register. Empty = the sticker just carries the register code. // Usage: node scripts/setup-asset-qr.mjs import PocketBase from "pocketbase"; import { readFileSync } from "node:fs"; for (const l of readFileSync(new URL("../.env.local", import.meta.url), "utf8").split("\n")) { const i = l.indexOf("="); if (i > 0 && !l.trim().startsWith("#")) process.env[l.slice(0, i).trim()] = l.slice(i + 1).trim(); } const pb = new PocketBase(process.env.NEXT_PUBLIC_PB_URL); await pb.collection("_superusers").authWithPassword(process.env.PB_ADMIN, process.env.PB_PASS); const assets = await pb.collections.getOne("assets"); if (assets.fields.some((f) => f.name === "qr_code")) console.log(" · assets.qr_code already present"); else { await pb.collections.update(assets.id, { fields: [...assets.fields, { name: "qr_code", type: "text" }] }); console.log(" ✓ added assets.qr_code"); }