Comments (1)
Any table not in your project should be referenced as a source. The dbt Constraints package optionally allows you to create FK, UK, and PK constraints on sources. As described in the readme, you enable this extra feature by adding this to your dbt_project.yml
vars:
dbt_constraints_sources_enabled: true
It is important to remember that you must have a PK or UK on the parent table. If you have sufficient permissions, you could define those PK/UK on sources in dbt. If you don't you would need to add such constraints outside of dbt before you could create a FK to those tables. Either way, the package will verify whether there is a PK/UK in place before creating a FK.
I have examples using this feature in the integration tests. I recommend reviewing these two YAML that have constraints on sources, between sources, and between models and sources:
https://github.com/Snowflake-Labs/dbt_constraints/blob/main/integration_tests/models/sources.yml
https://github.com/Snowflake-Labs/dbt_constraints/blob/main/integration_tests/models/schema.yml
from dbt_constraints.
Related Issues (20)
- Feature request: add constraints to seeds HOT 2
- Disable constraint creation, after tests are run. HOT 1
- not_null failure where error tolerance HOT 1
- FK not created in Snowflake when you only have OWNERSHIP on a parent table
- Allow specification of custom materialization types for pk/fk/uk constraints HOT 2
- Decouple constraints from tests HOT 1
- Create constraint only on table recreation HOT 1
- Latest version 0.6.0 working on dbt-snowflake 1.4.1 (core version 1.4.5 HOT 2
- Add for BigQuery, since they now support FK & PK HOT 5
- Enhancement: Conditional foreign key test to support data vault HOT 1
- Is this package still needed if `dbt >= 1.5.0` ? HOT 3
- question regarding MATCH option on creating Snowflake constraints HOT 6
- Foreign Key constriants are not created in Snowflake database HOT 2
- Exclusion of a data catalog, database, or directory from a dbt_constraint build
- Foreign key constraints tested more than once HOT 2
- always_create_constraint is not working properly HOT 2
- Using constraints in models without name and column parameters HOT 2
- not_null constraint causing error on severity: warn with warn_if > 0
- Failed to create PK constraint if a table already has PK constraint on another column or columns
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dbt_constraints.