Skip to content

fix: reset ID sequences after data import - #52

Merged
rivon0507 merged 4 commits into
mainfrom
fix/reset-sequences-after-import
Feb 24, 2026
Merged

fix: reset ID sequences after data import#52
rivon0507 merged 4 commits into
mainfrom
fix/reset-sequences-after-import

Conversation

@rivon0507

Copy link
Copy Markdown
Member

This pull request implements robust handling and synchronization of database sequences after importing data with explicit primary key values, ensuring that auto-generated IDs do not collide with manually imported ones. It introduces a mechanism to track the maximum imported ID per entity during import, updates the sequence accordingly, and adds integration tests to guarantee sequence integrity for all importable entities.

Sequence synchronization and tracking:

  • Added getMaxImportedId() to the EntityTableAdapter interface and implemented logic in AbstractEntityTableAdapter to track the highest primary key value seen during each import batch. Each concrete adapter now provides an extractId() implementation to extract the ID from DTOs.
  • The import service now collects the maximum imported ID for each entity and, after import, synchronizes the backing sequence to be at least as high as the maximum imported ID to prevent future collisions.

Database migration:

  • Added a new migration script (V9__fix_sequence_values.sql) to retroactively fix sequence values for all relevant tables, ensuring their sequences are set to at least the current maximum ID.

Testing and validation:

  • Introduced a comprehensive test suite (ImportSequenceIntegrityTest) that verifies, for all entity adapters, that after import the sequence is always ahead of or equal to the maximum primary key in the table, preventing duplicate key violations. This includes dynamic tests for all adapters and validation of test data presence.

Minor improvements:

  • Refactored test utility methods for reading metadata files in the import controller tests.

When importing data with explicit IDs, the backing sequences were not
advanced, causing future auto-generated IDs to collide with the
imported ones. The import pipeline now synchronizes each affected
sequence to the maximum imported ID after staging is complete.
@rivon0507 rivon0507 self-assigned this Feb 23, 2026
@rivon0507 rivon0507 added bug Something isn't working fix Fixes something that wasn't working labels Feb 23, 2026
@rivon0507
rivon0507 merged commit 1e8dac3 into main Feb 24, 2026
1 check passed
@rivon0507
rivon0507 deleted the fix/reset-sequences-after-import branch February 24, 2026 06:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working fix Fixes something that wasn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants