diff --git a/CHANGELOG.md b/CHANGELOG.md index 7fc40d6279a..d70224b917a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ ## dbt 0.20.0 (Release TBD) +### Features +- Support optional `updated_at` config parameter with `check` strategy snapshots. If not supplied, will use current timestamp (default). ([#1844](https://github.com/fishtown-analytics/dbt/issues/1844), [#3376](https://github.com/fishtown-analytics/dbt/pull/3376)) + ### Fixes - Fix compiled sql for ephemeral models ([#3317](https://github.com/fishtown-analytics/dbt/issues/3317), [#3318](https://github.com/fishtown-analytics/dbt/pull/3318)) - Now generating `run_results.json` even when no nodes are selected ([#3313](https://github.com/fishtown-analytics/dbt/issues/3313), [#3315](https://github.com/fishtown-analytics/dbt/pull/3315)) @@ -23,6 +26,7 @@ Contributors: - [@elikastelein](https://github.com/elikastelein) ([#3149](https://github.com/fishtown-analytics/dbt/pull/3149)) - [@majidaldo](https://github.com/majidaldo) ([#3134](https://github.com/fishtown-analytics/dbt/issues/3134)) - [@jaypeedevlin](https://github.com/jaypeedevlin) ([#2999](https://github.com/fishtown-analytics/dbt/issues/2999)) +- [@PJGaetan](https://github.com/PJGaetan) ([#3315](https://github.com/fishtown-analytics/dbt/pull/3376)) ## dbt 0.20.0b1 (May 03, 2021) diff --git a/core/dbt/include/global_project/macros/materializations/snapshot/strategies.sql b/core/dbt/include/global_project/macros/materializations/snapshot/strategies.sql index 569e213e227..1d35c71290c 100644 --- a/core/dbt/include/global_project/macros/materializations/snapshot/strategies.sql +++ b/core/dbt/include/global_project/macros/materializations/snapshot/strategies.sql @@ -144,7 +144,7 @@ {% if now is none or now is undefined -%} {%- do exceptions.raise_compiler_error('Could not get a snapshot start time from the database') -%} {%- endif %} - {% set updated_at = snapshot_string_as_time(now) %} + {% set updated_at = config.get('updated_at', snapshot_string_as_time(now)) %} {% set column_added = false %} diff --git a/test/integration/004_simple_snapshot_test/test_simple_snapshot.py b/test/integration/004_simple_snapshot_test/test_simple_snapshot.py index a2130f742bd..ffd8dbf2028 100644 --- a/test/integration/004_simple_snapshot_test/test_simple_snapshot.py +++ b/test/integration/004_simple_snapshot_test/test_simple_snapshot.py @@ -577,6 +577,53 @@ def project_config(self): } +class TestUpdatedAtCheckCols(TestCheckCols): + def _assertTablesEqualSql(self, relation_a, relation_b, columns=None): + revived_records = self.run_sql( + ''' + select + id, + updated_at, + dbt_valid_from + from {} + '''.format(relation_b), + fetch='all' + ) + + for result in revived_records: + # result is a tuple, the updated_at is second and dbt_valid_from is latest + self.assertIsInstance(result[1], datetime) + self.assertIsInstance(result[2], datetime) + self.assertEqual(result[1].replace(tzinfo=pytz.UTC), result[2].replace(tzinfo=pytz.UTC)) + + if columns is None: + columns = [c for c in self.get_relation_columns(relation_a) if not c[0].lower().startswith('dbt_')] + return super()._assertTablesEqualSql(relation_a, relation_b, columns=columns) + + def assert_expected(self): + super().assert_expected() + self.assertTablesEqual('snapshot_checkall', 'snapshot_expected') + + + @property + def project_config(self): + return { + 'config-version': 2, + "data-paths": ['data'], + "snapshot-paths": ['test-check-col-snapshots-noconfig'], + "snapshots": { + "test": { + "target_schema": self.unique_schema(), + "unique_key": "id || '-' || first_name", + "strategy": "check", + "check_cols" : "all", + "updated_at": "updated_at", + }, + }, + 'macro-paths': ['macros'], + } + + class TestCheckColsBigquery(TestSimpleSnapshotFilesBigquery): def _assertTablesEqualSql(self, relation_a, relation_b, columns=None): # When building the equality tests, only test columns that don't start