feat: add created and updated autodate fields to sources collection via migration
This commit is contained in:
45
pb_migrations/1779200000_updated_sources.js
Normal file
45
pb_migrations/1779200000_updated_sources.js
Normal 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)
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user