fix(codegen): temporal current-version UNIQUE; valid_to CHECK#81
Merged
Conversation
Closes #41. `verisimdb_temporal_versions` had a non-unique partial index on `(entity_id, table_name) WHERE valid_to IS NULL`. Two concurrent writers could both successfully insert a row with `valid_to=NULL` for the same entity, leaving two "current" versions and breaking the point-in-time query semantics. There was also no constraint that `valid_to` (when set) couldn't precede `valid_from`. - Promote the partial index to `CREATE UNIQUE INDEX` so the storage layer enforces "at most one current version per (entity, table)". - Add `CHECK (valid_to IS NULL OR valid_to >= valid_from)` so a version interval can't be backwards. Test `test_temporal_table_has_unique_partial_index_and_valid_to_check` asserts both clauses appear in the emitted DDL with temporal enabled. `cargo clippy --all-targets -- -D warnings` clean; 37 unit tests pass. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Per V-L2-H1: two concurrent writers could both leave
valid_to=NULLfor the same entity (the partial index wasn't UNIQUE), and there was no ordering check on the validity interval.idx_temporal_currenttoCREATE UNIQUE INDEX ... WHERE valid_to IS NULL.CHECK (valid_to IS NULL OR valid_to >= valid_from).Closes
Test plan
cargo clippy --all-targets -- -D warningscleancargo test --lib --bins37/37 (1 new:test_temporal_table_has_unique_partial_index_and_valid_to_check)