diff --git a/core/actions/table.ts b/core/actions/table.ts index a21306615..52fe1c4f5 100644 --- a/core/actions/table.ts +++ b/core/actions/table.ts @@ -469,8 +469,8 @@ export class Table extends ActionBuilder { if (config.disabled) { this.disabled(); } - if (config.protected) { - this.protected(); + if (config.type === "incremental") { + this.protected(config.protected); } if (config.bigquery && Object.keys(config.bigquery).length > 0) { this.bigquery(config.bigquery); @@ -536,8 +536,12 @@ export class Table extends ActionBuilder { return this; } - public protected() { - this.proto.protected = true; + public protected(defaultsToTrueProtected: boolean) { + // To prevent accidental data deletion, protected defaults to true if unspecified. + if (defaultsToTrueProtected === undefined || defaultsToTrueProtected === null) { + defaultsToTrueProtected = true; + } + this.proto.protected = defaultsToTrueProtected; return this; } diff --git a/core/main_test.ts b/core/main_test.ts index 3e1448aa3..f21d0c8c0 100644 --- a/core/main_test.ts +++ b/core/main_test.ts @@ -1603,8 +1603,6 @@ SELECT 1` }, type: "table", disabled: true, - // TODO(ekrekr): finish fixing this in https://github.com/dataform-co/dataform/pull/1718. - // protected: false, hermeticity: "HERMETIC", bigquery: { additionalOptions: { @@ -1697,8 +1695,6 @@ SELECT 1` }, type: "view", disabled: true, - // TODO(ekrekr): finish fixing this in https://github.com/dataform-co/dataform/pull/1718. - // protected: false, hermeticity: "HERMETIC", bigquery: { additionalOptions: { @@ -1794,8 +1790,7 @@ SELECT 1` }, type: "incremental", disabled: true, - // TODO(ekrekr): finish fixing this in https://github.com/dataform-co/dataform/pull/1718. - // protected: false, + protected: false, hermeticity: "HERMETIC", bigquery: { additionalOptions: { diff --git a/tests/core/core.spec.ts b/tests/core/core.spec.ts index 20f6b5269..ac7af1f94 100644 --- a/tests/core/core.spec.ts +++ b/tests/core/core.spec.ts @@ -247,7 +247,8 @@ suite("@dataform/core", () => { disabled: false, fileName: path.basename(__filename), type: "incremental", - enumType: "INCREMENTAL" + enumType: "INCREMENTAL", + protected: true } ]); });