dbt_constraints
dbt_constraints copied to clipboard
always_create_constraint is not working properly
always_create_constraint config is working only with thresholds (warn_if and error_if) .. It is not forcing the constraint with just severity: warn.
-- Not setting the FK
- name: col_fk tests: - dbt_constraints.foreign_key: pk_table_name: ref('pk_table') pk_column_name: col_pk config: severity: warn always_create_constraint: true
-- Setting the FK
- name: col_fk tests: - dbt_constraints.foreign_key: pk_table_name: ref('pk_table') pk_column_name: col_pk config: warn_if: ">100" always_create_constraint: true
Unfortunately, it is not working for us either. Maybe we got the syntax wrong? Any ideas are welcome!
- name: account_id
tests:
- relationships:
to: ref('account')
field: account_id
config:
always_create_constraint: true
- name: address_id
tests:
- dbt_constraints.foreign_key:
pk_table_name: ref('address')
pk_column_name: address_id
config:
severity: warn
warn_if: ">621692"
always_create_constraint: true
@cos-pet-learn any luck regarding this issue ? how can we force dbt to create FK constraint in the table if even the FK test fails?
I have completely overhauled the logic for always_create_constraint
in version 1.0.0, just released. Now it isn't even necessary to use that parameter if you want to create a constraint for a test you executed but failed. dbt Constraints 1.0.0 will now always create NORELY constraints or alter a constraint from RELY to NORELY if a test is executed and fails.
You now only need always_create_constraint
if you want to generate the constraint when you haven't even executed the test at all, for example with a dbt run
.