feat: add created and updated autodate fields to sources collection via migration

This commit is contained in:
RaymondVerhoef
2026-05-18 20:35:03 +02:00
parent 3afef7785e
commit 07a41938f1

View File

@@ -0,0 +1,45 @@
/// <reference path="../pb_data/types.d.ts" />
migrate((app) => {
const collection = app.findCollectionByNameOrId("pbc_1124997656")
if (collection) {
// Check if created already exists
let hasCreated = false;
for (let f of collection.fields) {
if (f.name === 'created') hasCreated = true;
}
if (!hasCreated) {
collection.fields.addAt(4, new Field({
"hidden": false,
"id": "autodate_sources_created",
"name": "created",
"onCreate": true,
"onUpdate": false,
"presentable": false,
"system": false,
"type": "autodate"
}))
collection.fields.addAt(5, new Field({
"hidden": false,
"id": "autodate_sources_updated",
"name": "updated",
"onCreate": true,
"onUpdate": true,
"presentable": false,
"system": false,
"type": "autodate"
}))
return app.save(collection)
}
}
}, (app) => {
const collection = app.findCollectionByNameOrId("pbc_1124997656")
if (collection) {
collection.fields.removeById("autodate_sources_created")
collection.fields.removeById("autodate_sources_updated")
return app.save(collection)
}
})