bettersight-statement-extra.../pocketbase/pb_migrations/12_add_pending_mapping_fiel...

48 lines
2.5 KiB
JavaScript

/// <reference path="../pb_data/types.d.ts" />
/**
* Persists a statement that still needs manual layout mapping (or value
* confirmation) across a page reload - previously these lived ONLY in
* memory (extractionStore's own `pendingMapping` field on a placeholder
* document, see CLAUDE.md's "Per-document mapping queue for batch
* uploads"), which meant a reload mid-session silently lost them,
* forcing a full re-upload - reported directly by the user.
*
* `result` relaxed to optional - a placeholder genuinely has no result
* yet, the same category of "nothing to store here" gap migration 10
* already found and fixed for layoutMappings.columnMap. `needsMapping`/
* `needsValueConfirmation` mark a placeholder as such (both false for
* every ordinary, already-resolved document); `pendingFingerprint`/
* `pendingFingerprintHash` are the raw fingerprint LayoutMappingRequired/
* ValueRecognitionRequired already computed, saved so the mapper doesn't
* need to recompute it after a reload; `pendingCandidateRow`/
* `pendingFieldOrder` are the value-confirmation case's own one-row
* preview, saved for the same reason. Deliberately NOT reusing the
* existing `layoutFingerprintHash` field - that one means "the hash of
* whichever mapping was actually APPLIED," a different thing from "the
* hash of an UNRESOLVED fingerprint still waiting on one."
*/
migrate((app) => {
let documents = app.findCollectionByNameOrId('documents')
let result = documents.fields.getByName('result')
result.required = false
documents.fields.add(new Field({ type: 'bool', name: 'needsMapping' }))
documents.fields.add(new Field({ type: 'bool', name: 'needsValueConfirmation' }))
documents.fields.add(new Field({ type: 'json', name: 'pendingFingerprint' }))
documents.fields.add(new Field({ type: 'text', name: 'pendingFingerprintHash' }))
documents.fields.add(new Field({ type: 'json', name: 'pendingCandidateRow' }))
documents.fields.add(new Field({ type: 'json', name: 'pendingFieldOrder' }))
app.save(documents)
}, (app) => {
let documents = app.findCollectionByNameOrId('documents')
let result = documents.fields.getByName('result')
result.required = true
documents.fields.removeByName('needsMapping')
documents.fields.removeByName('needsValueConfirmation')
documents.fields.removeByName('pendingFingerprint')
documents.fields.removeByName('pendingFingerprintHash')
documents.fields.removeByName('pendingCandidateRow')
documents.fields.removeByName('pendingFieldOrder')
app.save(documents)
})