diff --git a/pb_migrations/1788500000_client_logs_flavor.js b/pb_migrations/1788500000_client_logs_flavor.js new file mode 100644 index 0000000..8c26264 --- /dev/null +++ b/pb_migrations/1788500000_client_logs_flavor.js @@ -0,0 +1,44 @@ +/// + +// Add `flavor` to client_logs: which build variant a device runs, clean or adult. +// +// WHY THIS MIGRATION EXISTS: the app was already sending the field and PocketBase +// was silently throwing it away. An unknown key in a create payload is simply +// dropped — no error, no warning, HTTP 200 — which is the same silent-drop +// behaviour already documented for hidden fields in amber-app/CLAUDE.md. So the +// status dashboard's "Podle varianty" row read `neznámá` for every record while the +// client believed it was reporting the variant, and the only way to notice was to +// query the stored rows and find the field missing. +// +// Not folded into `meta`, though that would have needed no migration and the +// dashboard already falls back to reading it there: the variant is a first-class +// dimension of every record, exactly like `platform` and `appVersion` beside it, +// and burying it in a json blob would make the one query it exists for — group the +// errors by variant — awkward for no benefit. +// +// Additive and nullable, so existing rows stay valid and simply have no variant. +// Fourteen days from now the retention cron will have aged all of them out and the +// column will be populated for everything. + +migrate( + (app) => { + const logs = app.findCollectionByNameOrId("client_logs") + logs.fields.add( + new TextField({ + name: "flavor", + // "clean" | "adult". Not required: every row written before the app build + // that sends it, and any future client that omits it, must still be + // accepted — losing a diagnostic record over a missing dimension would be + // a worse trade than not knowing the variant. + required: false, + max: 20, + }), + ) + app.save(logs) + }, + (app) => { + const logs = app.findCollectionByNameOrId("client_logs") + logs.fields.removeByName("flavor") + app.save(logs) + }, +)