Skip to content

dbt Constraints v1.0.12

Latest

Choose a tag to compare

@sfc-gh-dflippo sfc-gh-dflippo released this 21 Oct 05:00
57957d1

What's Changed

  • Constraints now use a test's own quote_columns setting. Before, the package quoted columns in the test SQL but created the constraint with the hook's global setting, so the ALTER TABLE failed on a column that needs quotes, such as "OrderKey". A quote_columns: "false" string no longer counts as true. Credit goes to @kokorin for the fix.
  • dbt_constraints_enabled: false now turns a test's constraint off wherever you set it. A test can set the flag under config: or under config: meta:. Before, a false in one place was ignored if the other place still had its default of true. Use meta: dbt Fusion rejects an unknown key directly under a test's config:, and dbt-core 1.5 drops it. Fixes #137.
  • New opt-in var dbt_constraints_skip_tests_if_enforced. When it is true, a primary_key, unique_key or foreign_key test is skipped if the database already enforces a validated constraint that proves it. The test still compiles to its full SQL, wrapped in where 1 = 0, and the package logs the constraint it relied on. This helps large incremental models on PostgreSQL, Oracle and Vertica. A constraint that is NOT VALID, ENABLE NOVALIDATE, DISABLED, RELY-only, or that allows repeated NULLs does not count. Snowflake, Redshift and BigQuery enforce only NOT NULL, so their key tests never skip. See the README section "Skipping tests that the database already enforces". Fixes #114.
  • Vertica fixes.
    • A foreign key is now created only when the parent table has a primary key on the referenced columns. Vertica rejects a foreign key that references a unique key (error 4550), so before, such a constraint failed. Now the package skips it with a log message.
    • The privilege check now reads v_catalog.tables and v_catalog.grants. The previous query used information_schema.table_privileges, which Vertica does not have.
  • The integration tests now include a Vertica 25.4 cell, so the Vertica macros are tested against a real database for the first time.

Full Changelog: 1.0.11...1.0.12