Skip to content

fix(admin): sync identity sequences after restore - #3844

Open
r266-tech wants to merge 1 commit into
vectorize-io:mainfrom
r266-tech:r266/admin-restore-identity-sequences
Open

fix(admin): sync identity sequences after restore#3844
r266-tech wants to merge 1 commit into
vectorize-io:mainfrom
r266-tech:r266/admin-restore-identity-sequences

Conversation

@r266-tech

Copy link
Copy Markdown
Contributor

Fixes #3841.

Admin restore copies explicit IDs back into the history tables but previously left their identity sequences at the pre-restore position. The next consolidation write could then collide with restored rows and fail permanently.

This change discovers non-cyclic PostgreSQL identity sequences owned by restored columns, then synchronizes them inside the existing restore transaction. It uses catalog-constrained identity dependencies, quoted identifiers, transactional ALTER SEQUENCE ... RESTART, and an in-transaction nextval to preserve exhausted sequence bounds without non-transactional setval. Cyclic and manually-owned non-generating sequences are deliberately left untouched because table extrema cannot reconstruct their cursor safely.

Regression coverage includes both affected history tables with restored ID 337, transaction rollback, empty tables, ascending and descending exhaustion, explicit values outside sequence bounds, cyclic exclusion, quoted identifiers, and manually-owned sequence exclusion.

Verification:

  • pytest -q hindsight-api-slim/tests/test_admin_backup_restore.py (21 passed)
  • ruff format --check hindsight-api-slim/hindsight_api/admin/cli.py hindsight-api-slim/tests/test_admin_backup_restore.py
  • ruff check hindsight-api-slim/hindsight_api/admin/cli.py hindsight-api-slim/tests/test_admin_backup_restore.py
  • git diff --check

@strix-security

strix-security Bot commented Aug 27, 2026

Copy link
Copy Markdown

Strix Security Review

No security issues found.

Updated for 9431b33.


Reviewed by Strix
Re-run review · Configure security review settings

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] hindsight-admin restore leaves identity sequences behind restored data — post-restore inserts fail with UniqueViolationError

1 participant