Skip to content

fix(codegen): lineage table CHECK refuses self-references#78

Merged
hyperpolymath merged 1 commit into
mainfrom
fix/lineage-self-ref-check
May 14, 2026
Merged

fix(codegen): lineage table CHECK refuses self-references#78
hyperpolymath merged 1 commit into
mainfrom
fix/lineage-self-ref-check

Conversation

@hyperpolymath
Copy link
Copy Markdown
Owner

Summary

Per V-L2-I1: lineage edges accepted source == target, so the README's DAG claim was unenforced at the structural level. Add CHECK:

CHECK (source_entity <> target_entity OR source_table <> target_table)

Multi-hop cycle prevention is a runtime concern (tracked as the V-L2-I2 follow-up).

Closes

Test plan

  • cargo clippy --all-targets -- -D warnings clean
  • cargo test --lib --bins 35/35 (1 new: test_lineage_table_has_self_reference_check)

Closes #42.

`verisimdb_lineage_graph` had no constraint preventing
`(source_entity, source_table) == (target_entity, target_table)`. Any
row inserted with matching source/target tuples is a self-loop and
falsifies the README's "DAG" framing at the structural level.

Add a CHECK constraint:

    CHECK (source_entity <> target_entity
           OR source_table <> target_table)

i.e. at least one component of the (entity, table) pair must differ.
Two entities with the same id across different tables (a legitimate
cross-table derivation) still pass.

Multi-hop cycle prevention is a runtime concern (any number of CHECKs
can't catch chains); kept as a separate follow-up (V-L2-I2).

Test `test_lineage_table_has_self_reference_check` asserts the exact
CHECK clause appears in the emitted DDL with lineage enabled.

`cargo clippy --all-targets -- -D warnings` clean; 35 unit tests pass.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@hyperpolymath hyperpolymath merged commit edbfa90 into main May 14, 2026
16 of 18 checks passed
@hyperpolymath hyperpolymath deleted the fix/lineage-self-ref-check branch May 14, 2026 14:31
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.

V-L2-I1: lineage edges allow self-references; add CHECK source != target

1 participant