Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CT-2441] [Feature] Support expression for all constraint types #7416

Closed
Tracked by #7372
jtcohen6 opened this issue Apr 20, 2023 · 0 comments · Fixed by #7512
Closed
Tracked by #7372

[CT-2441] [Feature] Support expression for all constraint types #7416

jtcohen6 opened this issue Apr 20, 2023 · 0 comments · Fixed by #7512
Assignees
Labels
enhancement New feature or request model_contracts Team:Adapters Issues designated for the adapter area of the code user docs [docs.getdbt.com] Needs better documentation
Milestone

Comments

@jtcohen6
Copy link
Contributor

For model-level and column-level constraints, only check and custom constraints will include the expression field in their templated DDL.

I think all constraints should support the custom expression field. This is:

  • Relevant to support additional options on some constraint types — e.g. UNIQUE NULLS NOT DISTINCT instead of UNIQUE, the user could configure with expression: nulls not distinct
  • Necessary for foreign key / references constraints — although the user can't really do things like stick ref in here, since we kicked that out of scope (rationale: [CT-1922] Support 'constraints' as a model-level property #6754 (comment)), so I wouldn't consider these constraints high-priority

This is on me - I didn't do a good job of making this clear in the revised spec (#7066)! The words I used were free for all, which really had two meanings:

  • the user is free to put whatever text they want in here
  • the user is free to define this for any constraint type, and expect it will propagate

I'm opening this issue to track the gap, but the more I write, the less I feel this is something we need to go do right away.

  • While primary and foreign key constraints are nice for annotation (e.g. metadata to power ERD diagrams), they aren't enforced by the majority of analytical data platforms. In practice, their precise functionality is irrelevant for the vast majority of dbt users.
  • There is a valid workaround: users can always opt for the type: custom constraint, which is just a free text entry.

Relevant methods:

def render_raw_columns_constraints(cls, raw_columns: Dict[str, Dict[str, Any]]) -> List:

def render_model_constraint(cls, constraint: ModelLevelConstraint) -> Optional[str]:

@jtcohen6 jtcohen6 added enhancement New feature or request Team:Adapters Issues designated for the adapter area of the code model_contracts labels Apr 20, 2023
@github-actions github-actions bot changed the title Support expression for all constraint types [CT-2441] Support expression for all constraint types Apr 20, 2023
@jtcohen6 jtcohen6 changed the title [CT-2441] Support expression for all constraint types [CT-2441] [Feature] Support expression for all constraint types Apr 20, 2023
@MichelleArk MichelleArk self-assigned this May 4, 2023
@jtcohen6 jtcohen6 added this to the v1.5.x milestone May 6, 2023
@MichelleArk MichelleArk added the user docs [docs.getdbt.com] Needs better documentation label May 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request model_contracts Team:Adapters Issues designated for the adapter area of the code user docs [docs.getdbt.com] Needs better documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants