Skip to content

Commit

Permalink
Fix snapshot refs (#36)
Browse files Browse the repository at this point in the history
* Add snapshot tests

* Fix snapshot refs

* Bump version
  • Loading branch information
LewisDavies authored Apr 22, 2024
1 parent 235dfc9 commit acbb79b
Show file tree
Hide file tree
Showing 36 changed files with 445 additions and 9 deletions.
2 changes: 1 addition & 1 deletion dbt_project.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: 'upstream_prod'
version: '0.8.1'
version: '0.8.2'
config-version: 2

require-dbt-version: [">=1.5.0", "<2.0.0"]
Expand Down
11 changes: 11 additions & 0 deletions integration_tests/_template/models/marts/snapshot_example.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
select
source_target,
source_database,
source_schema,
source_model,
'{{ target.name }}' as this_target,
'{{ this.database }}' as this_database,
'{{ this.schema }}' as this_schema,
'{{ this.name }}' as this_model
from
{{ ref('snp__example') }}
3 changes: 2 additions & 1 deletion integration_tests/_template/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ dbt deps
dbt run-operation create_test_db --args '{db: upstream__prod_db}'
dbt run-operation create_test_db --args '{db: upstream__dev_db}'

# Create staging model in appropriate envs
# Create staging models in appropriate envs
echo ""
echo "## BUILDING STAGING MODELS"
echo ""
dbt snapshot --target prod
dbt build -s stg__defer_prod stg__defer_vers stg__dev_newer --target prod
dbt build -s stg__dev_fallback stg__dev_newer

Expand Down
11 changes: 11 additions & 0 deletions integration_tests/_template/snapshots/snp__example.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{% snapshot snp__example %}

select
'{{ target.name }}' as source_target,
'{{ this.database }}' as source_database,
'{{ this.schema }}' as source_schema,
'{{ this.name }}' as source_model,
1 as id,
current_timestamp as updated_at

{% endsnapshot %}
7 changes: 7 additions & 0 deletions integration_tests/dev_db/dbt_project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ models:
staging:
+schema: stg

snapshots:
upstream_prod_integration_tests:
target_schema: snapshots
unique_key: id
strategy: timestamp
updated_at: updated_at

vars:
upstream_prod_database: upstream__prod_db
upstream_prod_fallback: true
Expand Down
38 changes: 38 additions & 0 deletions integration_tests/dev_db/models/marts/_dev_db_models.yml
Original file line number Diff line number Diff line change
Expand Up @@ -235,3 +235,41 @@ models:
tests:
- accepted_values:
values: ['ephem']


- name: snapshot_example
columns:
# Source
- name: source_target
tests:
- accepted_values:
values: ['prod']
- name: source_database
tests:
- accepted_values:
values: ['upstream__prod_db']
- name: source_schema
tests:
- accepted_values:
values: ['snapshots']
- name: source_model
tests:
- accepted_values:
values: ['snp__example']
# This
- name: this_target
tests:
- accepted_values:
values: ['dev']
- name: this_database
tests:
- accepted_values:
values: ['upstream__dev_db']
- name: this_schema
tests:
- accepted_values:
values: ['prod_marts']
- name: this_model
tests:
- accepted_values:
values: ['snapshot_example']
11 changes: 11 additions & 0 deletions integration_tests/dev_db/models/marts/snapshot_example.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
select
source_target,
source_database,
source_schema,
source_model,
'{{ target.name }}' as this_target,
'{{ this.database }}' as this_database,
'{{ this.schema }}' as this_schema,
'{{ this.name }}' as this_model
from
{{ ref('snp__example') }}
3 changes: 2 additions & 1 deletion integration_tests/dev_db/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ dbt deps
dbt run-operation create_test_db --args '{db: upstream__prod_db}'
dbt run-operation create_test_db --args '{db: upstream__dev_db}'

# Create staging model in appropriate envs
# Create staging models in appropriate envs
echo ""
echo "## BUILDING STAGING MODELS"
echo ""
dbt snapshot --target prod
dbt build -s stg__defer_prod stg__defer_vers stg__dev_newer --target prod
dbt build -s stg__dev_fallback stg__dev_newer

Expand Down
11 changes: 11 additions & 0 deletions integration_tests/dev_db/snapshots/snp__example.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{% snapshot snp__example %}

select
'{{ target.name }}' as source_target,
'{{ this.database }}' as source_database,
'{{ this.schema }}' as source_schema,
'{{ this.name }}' as source_model,
1 as id,
current_timestamp as updated_at

{% endsnapshot %}
7 changes: 7 additions & 0 deletions integration_tests/dev_db_dev_sch/dbt_project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ models:
staging:
+schema: stg

snapshots:
upstream_prod_integration_tests:
target_schema: snapshots
unique_key: id
strategy: timestamp
updated_at: updated_at

vars:
upstream_prod_database: upstream__prod_db
upstream_prod_schema: prod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,3 +235,41 @@ models:
tests:
- accepted_values:
values: ['ephem']


- name: snapshot_example
columns:
# Source
- name: source_target
tests:
- accepted_values:
values: ['prod']
- name: source_database
tests:
- accepted_values:
values: ['upstream__prod_db']
- name: source_schema
tests:
- accepted_values:
values: ['snapshots']
- name: source_model
tests:
- accepted_values:
values: ['snp__example']
# This
- name: this_target
tests:
- accepted_values:
values: ['dev']
- name: this_database
tests:
- accepted_values:
values: ['upstream__dev_db']
- name: this_schema
tests:
- accepted_values:
values: ['dev_marts']
- name: this_model
tests:
- accepted_values:
values: ['snapshot_example']
11 changes: 11 additions & 0 deletions integration_tests/dev_db_dev_sch/models/marts/snapshot_example.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
select
source_target,
source_database,
source_schema,
source_model,
'{{ target.name }}' as this_target,
'{{ this.database }}' as this_database,
'{{ this.schema }}' as this_schema,
'{{ this.name }}' as this_model
from
{{ ref('snp__example') }}
3 changes: 2 additions & 1 deletion integration_tests/dev_db_dev_sch/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ dbt deps
dbt run-operation create_test_db --args '{db: upstream__prod_db}'
dbt run-operation create_test_db --args '{db: upstream__dev_db}'

# Create staging model in appropriate envs
# Create staging models in appropriate envs
echo ""
echo "## BUILDING STAGING MODELS"
echo ""
dbt snapshot --target prod
dbt build -s stg__defer_prod stg__defer_vers stg__dev_newer --target prod
dbt build -s stg__dev_fallback stg__dev_newer

Expand Down
11 changes: 11 additions & 0 deletions integration_tests/dev_db_dev_sch/snapshots/snp__example.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{% snapshot snp__example %}

select
'{{ target.name }}' as source_target,
'{{ this.database }}' as source_database,
'{{ this.schema }}' as source_schema,
'{{ this.name }}' as source_model,
1 as id,
current_timestamp as updated_at

{% endsnapshot %}
7 changes: 7 additions & 0 deletions integration_tests/dev_db_env_sch/dbt_project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ models:
staging:
+schema: stg

snapshots:
upstream_prod_integration_tests:
target_schema: snapshots
unique_key: id
strategy: timestamp
updated_at: updated_at

vars:
upstream_prod_database: upstream__prod_db
upstream_prod_fallback: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,3 +235,41 @@ models:
tests:
- accepted_values:
values: ['ephem']


- name: snapshot_example
columns:
# Source
- name: source_target
tests:
- accepted_values:
values: ['prod']
- name: source_database
tests:
- accepted_values:
values: ['upstream__prod_db']
- name: source_schema
tests:
- accepted_values:
values: ['snapshots']
- name: source_model
tests:
- accepted_values:
values: ['snp__example']
# This
- name: this_target
tests:
- accepted_values:
values: ['dev']
- name: this_database
tests:
- accepted_values:
values: ['upstream__dev_db']
- name: this_schema
tests:
- accepted_values:
values: ['dev']
- name: this_model
tests:
- accepted_values:
values: ['snapshot_example']
11 changes: 11 additions & 0 deletions integration_tests/dev_db_env_sch/models/marts/snapshot_example.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
select
source_target,
source_database,
source_schema,
source_model,
'{{ target.name }}' as this_target,
'{{ this.database }}' as this_database,
'{{ this.schema }}' as this_schema,
'{{ this.name }}' as this_model
from
{{ ref('snp__example') }}
3 changes: 2 additions & 1 deletion integration_tests/dev_db_env_sch/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ dbt deps
dbt run-operation create_test_db --args '{db: upstream__prod_db}'
dbt run-operation create_test_db --args '{db: upstream__dev_db}'

# Create staging model in appropriate envs
# Create staging models in appropriate envs
echo ""
echo "## BUILDING STAGING MODELS"
echo ""
dbt snapshot --target prod
dbt build -s stg__defer_prod stg__defer_vers stg__dev_newer --target prod
dbt build -s stg__dev_fallback stg__dev_newer

Expand Down
11 changes: 11 additions & 0 deletions integration_tests/dev_db_env_sch/snapshots/snp__example.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{% snapshot snp__example %}

select
'{{ target.name }}' as source_target,
'{{ this.database }}' as source_database,
'{{ this.schema }}' as source_schema,
'{{ this.name }}' as source_model,
1 as id,
current_timestamp as updated_at

{% endsnapshot %}
7 changes: 7 additions & 0 deletions integration_tests/dev_db_replace/dbt_project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ models:
staging:
+schema: stg

snapshots:
upstream_prod_integration_tests:
target_schema: snapshots
unique_key: id
strategy: timestamp
updated_at: updated_at

vars:
upstream_prod_database_replace: [dev, prod]
upstream_prod_fallback: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,3 +235,41 @@ models:
tests:
- accepted_values:
values: ['ephem']


- name: snapshot_example
columns:
# Source
- name: source_target
tests:
- accepted_values:
values: ['prod']
- name: source_database
tests:
- accepted_values:
values: ['upstream__prod_db']
- name: source_schema
tests:
- accepted_values:
values: ['snapshots']
- name: source_model
tests:
- accepted_values:
values: ['snp__example']
# This
- name: this_target
tests:
- accepted_values:
values: ['dev']
- name: this_database
tests:
- accepted_values:
values: ['upstream__dev_db']
- name: this_schema
tests:
- accepted_values:
values: ['prod_marts']
- name: this_model
tests:
- accepted_values:
values: ['snapshot_example']
11 changes: 11 additions & 0 deletions integration_tests/dev_db_replace/models/marts/snapshot_example.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
select
source_target,
source_database,
source_schema,
source_model,
'{{ target.name }}' as this_target,
'{{ this.database }}' as this_database,
'{{ this.schema }}' as this_schema,
'{{ this.name }}' as this_model
from
{{ ref('snp__example') }}
Loading

0 comments on commit acbb79b

Please sign in to comment.