Add constraints and descriptions to table

I am a new user of dbt. If you could assist me on some doubts I will be so appreciated.
I need to define constraints at table, but I could not find any way to do it through dbt. I would like to do something like below:
ALTER TABLE dim_customers
ADD CONSTRAINT PK_customer_id PRIMARY KEY (‘company_id’, ‘customer_id’)

Alter table function does not work for dbt. This should be done in config block, right?
If I define them in yml file, it does not appear as primary key at dim_customers table in Snowflake. It only is mentioned at documentation.
Like below:
- name: company_id
primary_key: true
description: The primary.

Also I need to see descriptions of the columns at the table in Snowflake. Once I add descriptions in yml file they only appear in documentation, but they do not appear at the table in Snowflake likewise primary key.

Could you please support me in this?

Hi there Hazal,
To ensure description appear, add persist_docs = {"relation": true, 'columns': true} to the config block.
Or have a read of the documentation.

Can’t help with the Snowflake primary key question, I’m not familiar with Snowflake.

Hi Meurant,

It works very well.

Many thanks for your assistance.

Hi dear dbt users,
Can anybody help on adding constraints a table in Snowflake through dbt please? DBT doesn’t recognize constraints mention and Snowflake doesn’t use indexes.
How do you add constraints to your Snowflake table?
Thanks in advance,

Hi Hazel - you can take a look at hooks and operations. link

1 Like