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

Add generic rule: models should implement uniqueness test for their PK #90

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

matthieucan
Copy link
Contributor

For models materialized as table or incremental:

  • Loop over their columns to extract PK
  • Loop over their tests to find a uniqueness test matching the PK columns

Consider both table- and column-level constraints and tests.

Copy link
Contributor

@druzhinin-kirill druzhinin-kirill left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💪

Comment on lines +58 to +59
if model.config.get("materialized") not in {"table", "incremental"}:
return None
Copy link
Contributor

@druzhinin-kirill druzhinin-kirill Dec 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you like us to implement this with a rule filter? Maybe even the whole pk discovery can be a filter, and this filter can be also part of the public dbt-score API on par with default rules 🤔

So people who implement their own rules for pk'ed tables but use the same filter implementation💡

return None

# Extract PK
pk_columns = None
Copy link
Contributor

@druzhinin-kirill druzhinin-kirill Dec 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can it be an empty list, and we only verify pk_columns if the length is >0 (=1)?
I think this way we can ensure pk_columns is always a list

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants