bettersight-statement-extra.../pocketbase/pb_migrations/3_add_export_file.js

24 lines
1.1 KiB
JavaScript

/// <reference path="../pb_data/types.d.ts" />
/**
* exportFile holds the latest generated Excel workbook for a document -
* stored in R2 same as sourceFile, once configure-secrets.sh has run.
* Deliberately the LATEST one only, overwritten on every new export, not
* a historical list - re-exporting after an edit already produces an
* updated file (the frontend's own "a downloaded file always reflects
* whatever is on screen" behavior), so keeping every past version would
* just be the same unbounded-growth problem this was meant to solve,
* moved from the VPS to R2 instead of actually fixed. A real retention
* policy (how long an export - or anything else - should be kept) is a
* separate, not-yet-made decision; this is the interim shape until then.
*/
migrate((app) => {
let documents = app.findCollectionByNameOrId('documents')
documents.fields.add(new Field({ type: 'file', name: 'exportFile', maxSelect: 1 }))
app.save(documents)
}, (app) => {
let documents = app.findCollectionByNameOrId('documents')
documents.fields.removeByName('exportFile')
app.save(documents)
})