From ad38989f00ba6c105dfbad5b33e1742f012b3f07 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 2 Sep 2026 22:10:31 +0200 Subject: [PATCH] notices: add the created/updated fields everything sorts by MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The collection was declared with exactly the fields it needs -- message, active, endsAt -- and PocketBase adds no created/updated unless asked. Both readers sort by -created, so both got 400 for the life of the feature: the app's NoticeService caught it and swallowed it, and the dashboard's own listing showed 'zatím žádné' however many notices existed. Writing worked throughout; nothing could read what was written. Additive and reversible. created is onCreate only; updated moves on every save, which costs nothing and is what a pull cursor wants. --- pb_migrations/1793500000_notices_autodate.js | 36 ++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 pb_migrations/1793500000_notices_autodate.js diff --git a/pb_migrations/1793500000_notices_autodate.js b/pb_migrations/1793500000_notices_autodate.js new file mode 100644 index 0000000..26f7ab0 --- /dev/null +++ b/pb_migrations/1793500000_notices_autodate.js @@ -0,0 +1,36 @@ +/// + +// Give `notices` the `created` field everything already sorts by. +// +// The collection was declared with exactly the fields it needs -- message, +// active, endsAt -- and PocketBase does not add `created`/`updated` unless they +// are asked for. Both readers ask for `sort=-created`: +// +// - the app's NoticeService, which caught the resulting 400 and swallowed it, +// so a notice never appeared and nothing said why; +// - the status dashboard's own listing, which therefore always showed "zatím +// žádné" no matter how many notices existed. +// +// So the feature had never once worked end to end, and the failure was +// invisible from both ends. Writing worked; nothing could read what was written. +// +// `onCreate` only for `created`; `updated` moves on every save, which is what a +// pull cursor wants and costs nothing here. +migrate( + (app) => { + const c = app.findCollectionByNameOrId("notices"); + c.fields.add( + new Field({ type: "autodate", name: "created", onCreate: true, onUpdate: false }), + ); + c.fields.add( + new Field({ type: "autodate", name: "updated", onCreate: true, onUpdate: true }), + ); + app.save(c); + }, + (app) => { + const c = app.findCollectionByNameOrId("notices"); + c.fields.removeByName("created"); + c.fields.removeByName("updated"); + app.save(c); + }, +);