diff --git a/core/table.ts b/core/table.ts index 7e8941bed..2e1651d0b 100644 --- a/core/table.ts +++ b/core/table.ts @@ -354,6 +354,9 @@ export class Table { private contextablePreOps: Array> = []; private contextablePostOps: Array> = []; + private uniqueKeyAssertion: Assertion; + private rowConditionsAssertion: Assertion; + public config(config: ITableConfig) { checkExcessProperties( (e: Error) => this.session.compileError(e), @@ -443,6 +446,8 @@ export class Table { public disabled() { this.proto.disabled = true; + this.uniqueKeyAssertion?.disabled(); + this.rowConditionsAssertion?.disabled(); return this; } @@ -590,10 +595,14 @@ export class Table { if (!!assertions.uniqueKey) { const indexCols = typeof assertions.uniqueKey === "string" ? [assertions.uniqueKey] : assertions.uniqueKey; - this.session.assert( + this.uniqueKeyAssertion = this.session.assert( `${this.proto.target.schema}_${this.proto.target.name}_assertions_uniqueKey`, ctx => this.session.adapter().indexAssertion(ctx.ref(this.proto.target), indexCols) - ).proto.parentAction = this.proto.target; + ); + this.uniqueKeyAssertion.proto.parentAction = this.proto.target; + if (this.proto.disabled) { + this.uniqueKeyAssertion.disabled(); + } } const mergedRowConditions = assertions.rowConditions || []; if (!!assertions.nonNull) { @@ -602,13 +611,17 @@ export class Table { nonNullCols.forEach(nonNullCol => mergedRowConditions.push(`${nonNullCol} IS NOT NULL`)); } if (!!mergedRowConditions && mergedRowConditions.length > 0) { - this.session.assert( + this.rowConditionsAssertion = this.session.assert( `${this.proto.target.schema}_${this.proto.target.name}_assertions_rowConditions`, ctx => this.session .adapter() .rowConditionsAssertion(ctx.ref(this.proto.target), mergedRowConditions) - ).proto.parentAction = this.proto.target; + ); + this.rowConditionsAssertion.proto.parentAction = this.proto.target; + if (this.proto.disabled) { + this.rowConditionsAssertion.disabled(); + } } return this; } diff --git a/examples/common_v2/definitions/example_table_with_tags.sqlx b/examples/common_v2/definitions/example_table_with_tags.sqlx index 8e8a478bb..6d5723580 100644 --- a/examples/common_v2/definitions/example_table_with_tags.sqlx +++ b/examples/common_v2/definitions/example_table_with_tags.sqlx @@ -4,7 +4,8 @@ config { assertions: { uniqueKey: ["sample"], nonNull: ["sample"] - } + }, + disabled: true } select * from ${ref("sample_data")} diff --git a/examples/common_v2/definitions/has_compile_errors/disabled_assertion.sqlx b/examples/common_v2/definitions/has_compile_errors/disabled_assertion.sqlx deleted file mode 100644 index 291bccba2..000000000 --- a/examples/common_v2/definitions/has_compile_errors/disabled_assertion.sqlx +++ /dev/null @@ -1,2 +0,0 @@ -config { type: "assertion", disabled: true, hermetic: false } -select 1 as test \ No newline at end of file diff --git a/tests/api/examples.spec.ts b/tests/api/examples.spec.ts index c54099862..c7467477f 100644 --- a/tests/api/examples.spec.ts +++ b/tests/api/examples.spec.ts @@ -297,6 +297,7 @@ suite("examples", () => { t.name === "tada-analytics." + schemaWithSuffix("df_integration_test") + ".example_table_with_tags" ); + expect(exampleTableWithTags.disabled).eql(true); expect(exampleTableWithTags.tags).to.eql(["tag1", "tag2", "tag3"]); // Check table-with-tags's unique key assertion @@ -307,6 +308,7 @@ suite("examples", () => { schemaWithSuffix("df_integration_test_assertions") + ".df_integration_test_example_table_with_tags_assertions_uniqueKey" )[0]; + expect(exampleTableWithTagsUniqueKeyAssertion.disabled).eql(true); expect(cleanSql(exampleTableWithTagsUniqueKeyAssertion.query)).equals( "select * from (select sample, count(1) as index_row_count from `tada-analytics." + schemaWithSuffix("df_integration_test") + @@ -331,6 +333,7 @@ suite("examples", () => { schemaWithSuffix("df_integration_test_assertions") + ".df_integration_test_example_table_with_tags_assertions_rowConditions" )[0]; + expect(exampleTableWithTagsRowConditionsAssertion.disabled).eql(true); expect(cleanSql(exampleTableWithTagsRowConditionsAssertion.query)).equals( "select 'sample is not null' as failing_row_condition, * from `tada-analytics." + schemaWithSuffix("df_integration_test") + diff --git a/version.bzl b/version.bzl index 569d74cae..37dda816b 100644 --- a/version.bzl +++ b/version.bzl @@ -1,3 +1,3 @@ # NOTE: If you change the format of this line, you must change the bash command # in /scripts/publish to extract the version string correctly. -DF_VERSION = "1.14.2" +DF_VERSION = "1.14.3"