The problem I’m having
I have an incremental model materialized as a table with column-level constraints defined in my schema.yml:
models:
- name: my_incremental_model
config:
contract:
enforced: true
columns:
- name: id
data_type: bigint
constraints:
- type: primary_key
- name: related_id
data_type: bigint
constraints:
- type: foreign_key
to: ref('other_table')
to_columns: [id]
When I run dbt run on this incremental model, the constraints aren’t being applied to the existing table - they only get created during the initial table creation.
The context of why I’m trying to do this
What are the best practices for ensuring that new constraints get applied to an already materialized incremental model?
- Is there a way to get dbt to apply these column-level constraints on each run without doing a
--full-refresh? - Or do I need to use
post-hookto manually add the constraints after each incremental run?
dbt-core and dbt-postgres versions I’m using
"dbt-core>=1.9.3",
"dbt-postgres>=1.9.0",