Skip to content

Commit

Permalink
Support --empty option for 'snapshot' command (#10962)
Browse files Browse the repository at this point in the history
  • Loading branch information
gshank authored Nov 1, 2024
1 parent 289d2dd commit bdf28d7
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .changes/unreleased/Features-20241031-163149.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Features
body: Support --empty for snapshots
time: 2024-10-31T16:31:49.926164-04:00
custom:
Author: gshank
Issue: "10372"
1 change: 1 addition & 0 deletions core/dbt/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,7 @@ def seed(ctx, **kwargs):
@cli.command("snapshot")
@click.pass_context
@global_flags
@p.empty
@p.exclude
@p.profiles_dir
@p.project_dir
Expand Down
40 changes: 40 additions & 0 deletions tests/functional/snapshots/test_snapshot_empty.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import pytest

from dbt.tests.util import run_dbt

my_model_sql = """
select 1 as id, {{ dbt.current_timestamp() }} as updated_at
"""

snapshots_yml = """
snapshots:
- name: my_snapshot
relation: "ref('my_model')"
config:
unique_key: id
strategy: check
check_cols: all
dbt_valid_to_current: "date('9999-12-31')"
"""


class TestSnapshotEmpty:
@pytest.fixture(scope="class")
def models(self):
return {
"my_model.sql": my_model_sql,
"snapshots.yml": snapshots_yml,
}

def test_check(self, project):
run_dbt(["run"])
run_dbt(["snapshot", "--empty"])

query = "select id, updated_at, dbt_valid_from, dbt_valid_to from {database}.{schema}.my_snapshot order by updated_at asc"
snapshot_out1 = project.run_sql(query, fetch="all")
assert snapshot_out1 == []

run_dbt(["run"])
run_dbt(["snapshot", "--empty"])
snapshot_out2 = project.run_sql(query, fetch="all")
assert snapshot_out2 == []

0 comments on commit bdf28d7

Please sign in to comment.