- Fixed a state corruption bug in
import_job_processing_phasewhereerrorstates could be incorrectly overwritten withprocessed. - All import procedures for sub-entities now use the modern pattern (passing natural keys to
temporal_merge) following an upstream bug fix insql_saga. - Fixed a persistent "duplicate key" violation in
analyse_external_identsby correcting a faulty JOIN condition that was causing data fan-out when joining to temporal tables.
-
Refactor: Standardize JSONB
errors,invalid_codes, andmerge_statuscolumns- Problem: The
errors,invalid_codes, andmerge_statusJSONB columns inimport_*_datatables are nullable. The procedures are inconsistent in treatingNULLvs an empty object ('{}') as "no errors". - Solution: Standardize on
'{}'as the representation for "no errors" and enforce this at the database level. - Plan:
- Create Migration: The
import_job_generatefunction now correctly creates these columns asNOT NULL DEFAULT '{}'::jsonb. Procedures are being updated to remove redundantCOALESCEcalls.
- Create Migration: The
- Problem: The
-
Refactor: Add
_pathcolumns for code lookups: The import system'sanalyse_*procedures currently only look up codes (e.g.,sector_code) by their simple code value. To properly support hierarchical code lists (likesector), a parallel_pathcolumn (e.g.,sector_path) should be added to theimport_data_columndefinitions for each code list. Theanalyse_*procedures should then be updated to intelligently choose the lookup method: if a_pathcolumn is present and has a value, it should be used to look up against thepathcolumn; otherwise, the_codecolumn should be used to look up against thecodecolumn. -
Design Review
- The
tagtable (migrations/20240116000000_create_table_tag.up.sql) was skipped during the temporal upgrade pending a design review of its custom date logic.
- The
-
DevOps: Document and standardize query plan generation in tests
- Problem: Query plans can change unexpectedly.
EXPLAIN ANALYZEis not test-stable. - Solution: A pattern has been established in test
303to useEXPLAIN(withoutANALYZE) and save the output totest/expected/. This makes plan changes visible ingit diff. - Plan:
- Document this convention in
CONVENTIONS.md. - Apply this pattern to other key integration tests.
- Document this convention in
- Problem: Query plans can change unexpectedly.
-
Refactor: Use GIST indexes in timeline views
- Problem: The
timeline_legal_unit_defandtimeline_establishment_defviews are not using GIST indexes for temporal subqueries, leading to slow sequential scans. - Solution: Refactor the subqueries in these views to use
daterangetypes and the&&(overlaps) operator to enable index usage. - Plan:
- Locate the migration files that define these views.
- Refactor the subqueries for
activity,location,contact, andstat_for_unitto usedaterangeoperators. - Verify the query plans are updated to use Index Scans.
- Problem: The