Snowflake-Labs / dbt_constraints

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

Add for BigQuery, since they now support FK & PK #47

Open MaximusMcCann opened 1 year ago

MaximusMcCann commented 1 year ago

You can now define Foreign and Primary keys on table columns in BigQuery. Would love to see this implemented 🙏 ❤️

Google docs regarding adding FK and PK constraints. https://cloud.google.com/bigquery/docs/reference/standard-sql/data-definition-language#alter_table_add_constraint_statement

Queries to pull the information off the schema about FK & PK.

https://cloud.google.com/bigquery/docs/information-schema-constraint-column-usage

SELECT *
FROM <PROJECT_ID>.<DATASET>.INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE;

https://cloud.google.com/bigquery/docs/information-schema-key-column-usage

SELECT *
FROM <PROJECT_ID>.<DATASET>.INFORMATION_SCHEMA.KEY_COLUMN_USAGE;

https://cloud.google.com/bigquery/docs/information-schema-table-constraints

SELECT *
FROM <PROJECT_ID>.<DATASET>.INFORMATION_SCHEMA.TABLE_CONSTRAINTS;

General spot for BQ schema information: https://cloud.google.com/bigquery/docs/information-schema-intro

adamferguson1 commented 1 year ago

Plus 1 to the above. This would be an awesome addition!

fayaazkhatri commented 1 year ago

Ditto - BigQuery support would be a game changer!

unstoppable-allensun commented 1 year ago

I'd love to see this feature please!

sudoryan commented 1 year ago

Thanks for the issue! I would like to have this as well.

helfi92 commented 1 year ago

+1

jschintz-nytimes commented 1 month ago

Hey everyone - I've got a PR ready for BQ. https://github.com/Snowflake-Labs/dbt_constraints/pull/73. It could use some further testing probably.

@MaximusMcCann @helfi92 @sudoryan @fayaazkhatri @unstoppable-allensun @adamferguson1