Skip to content

Commit

Permalink
Fix required vars check & prefer recent config (#35)
Browse files Browse the repository at this point in the history
* Update tests

* Fix database vars check

* Update boolean checks

* Update test script

* Bump version & clean up
  • Loading branch information
LewisDavies authored Apr 16, 2024
1 parent 0379c10 commit 235dfc9
Show file tree
Hide file tree
Showing 46 changed files with 574 additions and 99 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ Now that your dev models are using prod data, you DAG would look like this:
```

## Compatibility
`upstream-prod` was initially designed on Snowflake and is now primarily tested on Databricks. Based on my experience and user reports, it is known to work on:
`upstream-prod` is built and tested on Snowflake. Based on my experience and user reports, it is known to work on:
- Snowflake
- Databricks
- BigQuery
Expand Down
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.0'
version: '0.8.1'
config-version: 2

require-dbt-version: [">=1.5.0", "<2.0.0"]
Expand Down
3 changes: 2 additions & 1 deletion integration_tests/_template/macros/ref.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
fallback=var("upstream_prod_fallback", False),
env_schemas=var("upstream_prod_env_schemas", False),
version=None,
prefer_recent=var("upstream_prod_prefer_recent", False)
prefer_recent=var("upstream_prod_prefer_recent", False),
prod_database_replace=var("upstream_prod_database_replace", None)
) %}

{% do return(upstream_prod.ref(parent_model, prod_database, prod_schema, enabled, fallback, env_schemas, version)) %}
Expand Down
12 changes: 9 additions & 3 deletions integration_tests/_template/run_tests.sh
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
# Setup
set -e
echo "\nSETTING UP ENVIRONMENT\n"
echo ""
echo "## SETTING UP ENVIRONMENT"
echo ""
dbt clean
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
echo "\nBUILDING STAGING MODELS\n"
echo ""
echo "## BUILDING STAGING MODELS"
echo ""
dbt build -s stg__defer_prod stg__defer_vers stg__dev_newer --target prod
dbt build -s stg__dev_fallback stg__dev_newer

# Build & test downstream models
echo "\nBUILDING DOWNSTREAM MODELS\n"
echo ""
echo "## BUILDING DOWNSTREAM MODELS"
echo ""
dbt build -s models/marts

# Check dbt-codegen compatibility
Expand Down
11 changes: 0 additions & 11 deletions integration_tests/create_symlinks.sh

This file was deleted.

3 changes: 2 additions & 1 deletion integration_tests/dev_db/macros/ref.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
fallback=var("upstream_prod_fallback", False),
env_schemas=var("upstream_prod_env_schemas", False),
version=None,
prefer_recent=var("upstream_prod_prefer_recent", False)
prefer_recent=var("upstream_prod_prefer_recent", False),
prod_database_replace=var("upstream_prod_database_replace", None)
) %}

{% do return(upstream_prod.ref(parent_model, prod_database, prod_schema, enabled, fallback, env_schemas, version)) %}
Expand Down
12 changes: 9 additions & 3 deletions integration_tests/dev_db/run_tests.sh
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
# Setup
set -e
echo "\nSETTING UP ENVIRONMENT\n"
echo ""
echo "## SETTING UP ENVIRONMENT"
echo ""
dbt clean
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
echo "\nBUILDING STAGING MODELS\n"
echo ""
echo "## BUILDING STAGING MODELS"
echo ""
dbt build -s stg__defer_prod stg__defer_vers stg__dev_newer --target prod
dbt build -s stg__dev_fallback stg__dev_newer

# Build & test downstream models
echo "\nBUILDING DOWNSTREAM MODELS\n"
echo ""
echo "## BUILDING DOWNSTREAM MODELS"
echo ""
dbt build -s models/marts

# Check dbt-codegen compatibility
Expand Down
3 changes: 2 additions & 1 deletion integration_tests/dev_db_dev_sch/macros/ref.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
fallback=var("upstream_prod_fallback", False),
env_schemas=var("upstream_prod_env_schemas", False),
version=None,
prefer_recent=var("upstream_prod_prefer_recent", False)
prefer_recent=var("upstream_prod_prefer_recent", False),
prod_database_replace=var("upstream_prod_database_replace", None)
) %}

{% do return(upstream_prod.ref(parent_model, prod_database, prod_schema, enabled, fallback, env_schemas, version)) %}
Expand Down
12 changes: 9 additions & 3 deletions integration_tests/dev_db_dev_sch/run_tests.sh
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
# Setup
set -e
echo "\nSETTING UP ENVIRONMENT\n"
echo ""
echo "## SETTING UP ENVIRONMENT"
echo ""
dbt clean
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
echo "\nBUILDING STAGING MODELS\n"
echo ""
echo "## BUILDING STAGING MODELS"
echo ""
dbt build -s stg__defer_prod stg__defer_vers stg__dev_newer --target prod
dbt build -s stg__dev_fallback stg__dev_newer

# Build & test downstream models
echo "\nBUILDING DOWNSTREAM MODELS\n"
echo ""
echo "## BUILDING DOWNSTREAM MODELS"
echo ""
dbt build -s models/marts

# Check dbt-codegen compatibility
Expand Down
3 changes: 2 additions & 1 deletion integration_tests/dev_db_env_sch/macros/ref.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
fallback=var("upstream_prod_fallback", False),
env_schemas=var("upstream_prod_env_schemas", False),
version=None,
prefer_recent=var("upstream_prod_prefer_recent", False)
prefer_recent=var("upstream_prod_prefer_recent", False),
prod_database_replace=var("upstream_prod_database_replace", None)
) %}

{% do return(upstream_prod.ref(parent_model, prod_database, prod_schema, enabled, fallback, env_schemas, version)) %}
Expand Down
12 changes: 9 additions & 3 deletions integration_tests/dev_db_env_sch/run_tests.sh
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
# Setup
set -e
echo "\nSETTING UP ENVIRONMENT\n"
echo ""
echo "## SETTING UP ENVIRONMENT"
echo ""
dbt clean
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
echo "\nBUILDING STAGING MODELS\n"
echo ""
echo "## BUILDING STAGING MODELS"
echo ""
dbt build -s stg__defer_prod stg__defer_vers stg__dev_newer --target prod
dbt build -s stg__dev_fallback stg__dev_newer

# Build & test downstream models
echo "\nBUILDING DOWNSTREAM MODELS\n"
echo ""
echo "## BUILDING DOWNSTREAM MODELS"
echo ""
dbt build -s models/marts

# Check dbt-codegen compatibility
Expand Down
27 changes: 27 additions & 0 deletions integration_tests/dev_db_replace/dbt_project.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: 'upstream_prod_integration_tests'
version: '1.0.0'
config-version: 2

profile: 'upstream_prod_db'

model-paths: ["models"]
test-paths: ["tests"]
macro-paths: ["macros"]

target-path: "target" # directory which will store compiled SQL files
clean-targets: # directories to be removed by `dbt clean`
- "target"
- "dbt_packages"


models:
upstream_prod_integration_tests:
marts:
+schema: marts
staging:
+schema: stg

vars:
upstream_prod_database_replace: [dev, prod]
upstream_prod_fallback: true
upstream_prod_prefer_recent: true
10 changes: 10 additions & 0 deletions integration_tests/dev_db_replace/macros/create_test_db.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{% macro create_test_db(db) -%}

{% if target.type == "snowflake" %}
{% do run_query("create or replace database " ~ db) %}
{% elif target.type == "databricks" %}
{% do run_query("drop catalog if exists " ~ db ~ " cascade") %}
{% do run_query("create catalog " ~ db) %}
{% endif %}

{%- endmacro %}
15 changes: 15 additions & 0 deletions integration_tests/dev_db_replace/macros/ref.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{% macro ref(
parent_model,
prod_database=var("upstream_prod_database", None),
prod_schema=var("upstream_prod_schema", None),
enabled=var("upstream_prod_enabled", True),
fallback=var("upstream_prod_fallback", False),
env_schemas=var("upstream_prod_env_schemas", False),
version=None,
prefer_recent=var("upstream_prod_prefer_recent", False),
prod_database_replace=var("upstream_prod_database_replace", None)
) %}

{% do return(upstream_prod.ref(parent_model, prod_database, prod_schema, enabled, fallback, env_schemas, version)) %}

{% endmacro %}
Loading

0 comments on commit 235dfc9

Please sign in to comment.