From 4236276e0447c6fee97692b692f97440a5262ad8 Mon Sep 17 00:00:00 2001 From: JasonFraser Date: Fri, 30 Oct 2026 19:10:01 -0400 Subject: [PATCH] Add valuePatterns field; relax columnMap to optional for value-pattern-only mappings layoutMappings/layoutMappingVersions gain valuePatterns (json, optional) - same incremental pattern as startPage/headerBottom (migrations 7/8). Also relaxes columnMap from required to optional on both collections: confirmed empirically against the real running container that PocketBase's required:true rejects an empty JSON object the same way it rejects a missing one ("Cannot be blank"), and a value-pattern-only mapping (no region-drawing at all) genuinely has no column positions to store. Co-Authored-By: Claude Sonnet 5 --- ...elax_layout_mapping_column_map_required.js | 36 +++++++++++++++++++ .../9_add_layout_mapping_value_patterns.js | 32 +++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 pocketbase/pb_migrations/10_relax_layout_mapping_column_map_required.js create mode 100644 pocketbase/pb_migrations/9_add_layout_mapping_value_patterns.js diff --git a/pocketbase/pb_migrations/10_relax_layout_mapping_column_map_required.js b/pocketbase/pb_migrations/10_relax_layout_mapping_column_map_required.js new file mode 100644 index 0000000..2cc2cd4 --- /dev/null +++ b/pocketbase/pb_migrations/10_relax_layout_mapping_column_map_required.js @@ -0,0 +1,36 @@ +/// + +/** + * A value-pattern-only mapping (see migration 9) genuinely has no + * column positions to store - there's no region-drawing step in that + * flow at all, so `columnMap` stays `{}`. Confirmed empirically against + * the real running container, not assumed: PocketBase's `required: true` + * on a JSON field rejects an empty object the same way it rejects a + * missing one ("Cannot be blank"), so this HAD to be relaxed, not just + * tolerated by existing code (which was already defensive everywhere - + * see LayoutsView.vue/AdminLayoutReviewView.vue's own `mapping.columnMap + * || {}` reads). Relaxed on BOTH collections, for parity with how every + * other field this schema has grown (startPage/headerBottom, migrations + * 7/8) was always added to both at once. + */ +migrate((app) => { + let layoutMappings = app.findCollectionByNameOrId('layoutMappings') + let columnMap = layoutMappings.fields.getByName('columnMap') + columnMap.required = false + app.save(layoutMappings) + + let layoutMappingVersions = app.findCollectionByNameOrId('layoutMappingVersions') + let versionColumnMap = layoutMappingVersions.fields.getByName('columnMap') + versionColumnMap.required = false + app.save(layoutMappingVersions) +}, (app) => { + let layoutMappings = app.findCollectionByNameOrId('layoutMappings') + let columnMap = layoutMappings.fields.getByName('columnMap') + columnMap.required = true + app.save(layoutMappings) + + let layoutMappingVersions = app.findCollectionByNameOrId('layoutMappingVersions') + let versionColumnMap = layoutMappingVersions.fields.getByName('columnMap') + versionColumnMap.required = true + app.save(layoutMappingVersions) +}) diff --git a/pocketbase/pb_migrations/9_add_layout_mapping_value_patterns.js b/pocketbase/pb_migrations/9_add_layout_mapping_value_patterns.js new file mode 100644 index 0000000..89a4251 --- /dev/null +++ b/pocketbase/pb_migrations/9_add_layout_mapping_value_patterns.js @@ -0,0 +1,32 @@ +/// + +/** + * Value-pattern mapping (a narrower layout-mapper tier, 2026-10-31) - + * lets a user teach the extractor to CLEAN a raw value it can't parse + * (strip a currency-code prefix/suffix the general Unicode-symbol + * fallback in table_extract.py doesn't recognize) without drawing a + * single column region. `valuePatterns` is `{field: {stripPrefix?, + * stripSuffix?}}` for any of date/debit/credit/amount/balance - a + * mapping built this way carries THIS field but no real `columnMap` + * at all (it composes with auto-detection instead of replacing it - + * see table_extract.extract_pdf's own docstring), same optional, + * no-default pattern already used for startPage/headerBottom + * (migrations 7/8). + */ +migrate((app) => { + let layoutMappings = app.findCollectionByNameOrId('layoutMappings') + layoutMappings.fields.add(new Field({ type: 'json', name: 'valuePatterns' })) + app.save(layoutMappings) + + let layoutMappingVersions = app.findCollectionByNameOrId('layoutMappingVersions') + layoutMappingVersions.fields.add(new Field({ type: 'json', name: 'valuePatterns' })) + app.save(layoutMappingVersions) +}, (app) => { + let layoutMappings = app.findCollectionByNameOrId('layoutMappings') + layoutMappings.fields.removeByName('valuePatterns') + app.save(layoutMappings) + + let layoutMappingVersions = app.findCollectionByNameOrId('layoutMappingVersions') + layoutMappingVersions.fields.removeByName('valuePatterns') + app.save(layoutMappingVersions) +})