bettersight-statement-extra.../pocketbase/pb_migrations/5_add_layout_mapping_fields.js

28 lines
1.4 KiB
JavaScript

/// <reference path="../pb_data/types.d.ts" />
/**
* Tracks which (if any) layout mapping a document was extracted with -
* null/"auto" for every statement the keyword/geometry detector (or the
* layout_quirks fallback) resolved on its own, which is every document
* before this migration and will stay true for HSBC/RBC-shaped layouts
* going forward too. `layoutFingerprintHash` is computed even on the
* auto path (see backend layout_fingerprint.py's own fingerprint_hash) -
* kept for future analytics, not read by anything yet.
*/
migrate((app) => {
let documents = app.findCollectionByNameOrId('documents')
let layoutMappings = app.findCollectionByNameOrId('layoutMappings')
documents.fields.add(new Field({ type: 'relation', name: 'layoutMappingUsed', collectionId: layoutMappings.id, maxSelect: 1 }))
documents.fields.add(new Field({ type: 'number', name: 'layoutMappingVersionUsed' }))
documents.fields.add(new Field({ type: 'select', name: 'layoutApplied', maxSelect: 1, values: ['auto', 'mapping'] }))
documents.fields.add(new Field({ type: 'text', name: 'layoutFingerprintHash' }))
app.save(documents)
}, (app) => {
let documents = app.findCollectionByNameOrId('documents')
documents.fields.removeByName('layoutMappingUsed')
documents.fields.removeByName('layoutMappingVersionUsed')
documents.fields.removeByName('layoutApplied')
documents.fields.removeByName('layoutFingerprintHash')
app.save(documents)
})