vereinshaus/pocketbase/pb_migrations/1779230900_neuigkeiten.js

83 lines
2.9 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/// <reference path="../pb_data/types.d.ts" />
migrate((app) => {
// neuigkeiten Vereins-Feed mit Medien
{
const c = new Collection({
"createRule": "@request.auth.verein_id = verein_id",
"deleteRule": "@request.auth.verein_id = verein_id && autor_id = @request.auth.id",
"listRule": "@request.auth.verein_id = verein_id",
"viewRule": "@request.auth.verein_id = verein_id",
"updateRule": "@request.auth.verein_id = verein_id && autor_id = @request.auth.id",
"fields": [
{
"type": "relation", "name": "verein_id",
"required": true, "cascadeDelete": true,
"collectionId": "pbc_3589557411", "maxSelect": 1
},
{
"type": "relation", "name": "autor_id",
"required": true, "cascadeDelete": false,
"collectionId": "_pb_users_auth_", "maxSelect": 1
},
{ "type": "text", "name": "autor_name" },
{ "type": "text", "name": "text" },
{
"type": "file", "name": "medien",
"maxSelect": 10, "maxSize": 15728640,
"mimeTypes": ["image/jpeg","image/png","image/gif","image/webp","video/mp4","video/quicktime"]
},
{
"type": "relation", "name": "gruppe_ids",
"cascadeDelete": false,
"collectionId": "pbc_3099069179", "maxSelect": 99
},
{
"type": "relation", "name": "termin_id",
"cascadeDelete": false,
"collectionId": "pbc_2279568741", "maxSelect": 1
}
],
"name": "neuigkeiten",
"system": false,
"type": "base"
})
app.save(c)
// Re-save erzwingt Rule-Recompilation in PocketBase v0.38
const n2 = app.findCollectionByNameOrId("neuigkeiten")
app.save(n2)
}
// reaktionen 👍 pro User pro Beitrag
{
const neuigkeitenId = app.findCollectionByNameOrId("neuigkeiten").id
const c = new Collection({
"createRule": "@request.auth.id != ''",
"deleteRule": "@request.auth.id = user_id",
"listRule": "@request.auth.verein_id = beitrag_id.verein_id",
"viewRule": "@request.auth.verein_id = beitrag_id.verein_id",
"updateRule": null,
"fields": [
{
"type": "relation", "name": "beitrag_id",
"required": true, "cascadeDelete": true,
"collectionId": neuigkeitenId, "maxSelect": 1
},
{
"type": "relation", "name": "user_id",
"required": true, "cascadeDelete": true,
"collectionId": "_pb_users_auth_", "maxSelect": 1
}
],
"indexes": ["CREATE UNIQUE INDEX idx_reaktion_unique ON reaktionen (beitrag_id, user_id)"],
"name": "reaktionen",
"system": false,
"type": "base"
})
app.save(c)
}
}, (app) => {
try { app.delete(app.findCollectionByNameOrId("reaktionen")) } catch(_) {}
try { app.delete(app.findCollectionByNameOrId("neuigkeiten")) } catch(_) {}
})