Snowflake-Labs / dbt_constraints

This package generates database constraints based on the tests in a dbt project
Apache License 2.0
143 stars 28 forks source link

Disable constraint creation, after tests are run. #38

Closed hhagblom closed 1 year ago

hhagblom commented 1 year ago

Normally when one runs say the production build nightly or whatever you'd like the constraints to be added as normal so one could generate diagrams with the relations e.t.c.

There might be the case however that you're developing some new test-cases or want to rerun for whatever reason, then you might have the test cases on your local machine and just want to run the tests against the production-environment where we don't have write access.

It would be great then if it would be possible to turn off the hook that runs at the end of the test-suite that creates the constraints so that it doesn't fail at that point with an access error preventing the test-error details to be displayed.

Thanks for creating this package, it is very useful!

sfc-gh-dflippo commented 1 year ago

@hhagblom , Could you please clarify how your request is different from the existing flags that disable constraint generation? It seems like you should set dbt_constraints_enabled to false in your dbt_project.yml and then it will skip creating constraints in the macro called by the hook. That parameter doesn't change whether or not the tests are executed, only the constraint generation at the end.

vars:
  # The package can be temporarily disabled using this variable
  dbt_constraints_enabled: true

  # The package can also add constraints on sources if you have sufficient privileges
  dbt_constraints_sources_enabled: false

  # You can also be specific on which constraints are enabled for sources
  # You must also enable dbt_constraints_sources_enabled above
  dbt_constraints_sources_pk_enabled: true
  dbt_constraints_sources_uk_enabled: true
  dbt_constraints_sources_fk_enabled: true
  dbt_constraints_sources_nn_enabled: true