Skip to content

Commit

Permalink
Fix hard coded dbconnection (#41)
Browse files Browse the repository at this point in the history
* refactor: use env vars

* refactor: testing something

* feat: set schema to read from env variables

* feat: add POSTGRES_USER to the test setup script

* chore: update package and add env variables

* Add the creation of the postgres table

* Stop using seeds as test data, instead insert test data in test setup
---------

Co-authored-by: Maria Lorena Rodriguez Viruel <[email protected]>
  • Loading branch information
njuguna-n and Maria Lorena Rodriguez Viruel authored Jan 24, 2024
1 parent 194b3d5 commit d7e70b7
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 78 deletions.
4 changes: 1 addition & 3 deletions models/root/couchdb.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
{% set import_couchdb_data = select_table(source('couchdb','couchdb'), ref('couchdb_test_data')) %}

{{
config(
materialized = 'view',
Expand All @@ -12,4 +10,4 @@
SELECT
doc->>'type' AS type,
*
FROM {{ import_couchdb_data }}
FROM v1.{{ env_var('POSTGRES_TABLE') }}
10 changes: 5 additions & 5 deletions models/root/root.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
version: 2

sources:
- name: couchdb
database: data
schema: v1
- name: medic
database: "{{ env_var('POSTGRES_DB') }}"
schema: "v1"
tables:
- name: couchdb
- name: medic
models:
- name: couchdb
- name: medic
columns:
- name: _id
tests:
Expand Down
2 changes: 1 addition & 1 deletion packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ packages:
- package: dbt-labs/dbt_utils
version: 1.1.1
- package: calogica/dbt_date
version: 0.9.1
version: 0.10.0
56 changes: 0 additions & 56 deletions seeds/couchdb_test_data.csv

This file was deleted.

9 changes: 0 additions & 9 deletions seeds/properties.yml

This file was deleted.

5 changes: 3 additions & 2 deletions tests/run_dbt_tests.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#!/bin/bash
set -e
export POSTGRES_DB=data
export POSTGRES_USER=root
export POSTGRES_TABLE=couchdb
export POSTGRES_PASSWORD=supercoolpassword
export POSTGRES_SCHEMA=v1
export DBT_POSTGRES_USER=dbt_user
export DBT_POSTGRES_PASSWORD=supercoolpassword
export DBT_POSTGRES_SCHEMA=dbt
Expand All @@ -11,8 +14,6 @@ export ROOT_POSTGRES_SCHEMA=v1
export DBT_PROFILES_DIR=$PWD
echo Install dbt dependencies ...
dbt deps
echo Seeding test data ...
dbt seed --full-refresh
echo Running dbt ...
dbt run
echo Running tests ...
Expand Down
69 changes: 67 additions & 2 deletions tests/setup.sh

Large diffs are not rendered by default.

0 comments on commit d7e70b7

Please sign in to comment.