[Constraints] Add parse-time validation that ensures only a single primary_key constraint is defined #9581
Closed
1 task done
Labels
Milestone
Housekeeping
Short description
Currently, no parse-time error is raised when dbt sees a contract that defines a primary_key at both the model-level and the column-level. Additionally, no parse-time error is raised when multiple primary_keys are defined at the column-level.
In both cases, this will lead to a database error across many (probably all) data warehouses. Validated here: dbt-labs/jaffle-shop-classic#106
Additionally, our documented guidance in dbt is to define tests/constraints that work across multiple columns at the model-level. If a warehouse supports defining multiple primary keys at the column-level, it is really working by coincidence from the perspective of dbt.
Acceptance criteria
We raise an error at parse-time if:
Suggested Tests
Impact to Other Teams
N/A
Will backports be required?
No.
Context
Additionally, I believe we only parse + serialize constraints if the contract is enforced currently. So if config.contract is False, we don't even store the constraints as provided. This was probably done to avoid raising errors related to warehouse-specific errors related to constraint prerequisites at parse time. However, we should probably still be parsing the constraints (storing constraints defined in project spec onto internal node + serializing them) and running any parse-time validation against them at least.
The text was updated successfully, but these errors were encountered: