Repository navigation
Conversation
Primary and foreign keys are already first-class in Modelith — a PK is a `pk` KeyGroup with ordered members (composite-capable), an FK is a Relationship whose from/to ends carry paired attribute lists (multi-column-capable). This closes the two validation gaps that model left open: - MDL-W115 (warning): a PK KeyGroup member marked `nullable: true` — a primary key must not be null. A warning, not an error, so legacy models built on the `role: business_key` convention (which carried no nullability contract) don't suddenly fail. - MDL-E114 (error): a foreign key whose paired from/to attributes have mismatched domains — a join that can never work. Only compares when both ends are column-mapped 1:1 and both declare a domain. Deliberately NOT adding a `role: primary_key`/`foreign_key` + `references:` attribute syntax (as the issue proposed): it would be a second, weaker source of truth for the same fact and couldn't express composite keys or multi-column FKs cleanly. The existing KeyGroup/Relationship model already covers the issue's desired effects (validation, dbt constraints/tests, ERD cardinality). Tests: test_key_constraints.py (nullable/composite PK, FK match/mismatch/missing- domain/unmapped). 561 passed, 1 skipped; ruff clean; verified on the CLI. Spec §2.4 documents the codes and the design rationale.
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.
Primary and foreign keys are already first-class in Modelith — a PK is a
pkKeyGroup with ordered members (composite-capable), an FK is a Relationship whose from/to ends carry paired attribute lists (multi-column-capable). This closes the two validation gaps that model left open:nullable: true— a primary key must not be null. A warning, not an error, so legacy models built on therole: business_keyconvention (which carried no nullability contract) don't suddenly fail.Deliberately NOT adding a
role: primary_key/foreign_key+references:attribute syntax (as the issue proposed): it would be a second, weaker source of truth for the same fact and couldn't express composite keys or multi-column FKs cleanly. The existing KeyGroup/Relationship model already covers the issue's desired effects (validation, dbt constraints/tests, ERD cardinality).Tests: test_key_constraints.py (nullable/composite PK, FK match/mismatch/missing- domain/unmapped). 561 passed, 1 skipped; ruff clean; verified on the CLI. Spec §2.4 documents the codes and the design rationale.
What this changes
How it was tested
Checklist
uv run pytest)uv run ruff check packages/)