From 1a8e7dc75f4cc8cab8594f6dc98cf83cd9cbc833 Mon Sep 17 00:00:00 2001 From: vishreddy01 Date: Wed, 7 Feb 2024 17:24:21 -0800 Subject: [PATCH] Adding config changes --- pmt/dbt/pmt_dbt/Dockerfile | 15 ++++++++ pmt/dbt/pmt_dbt/dbt_project.yml | 13 ++++++- .../pmt_dbt/macros/generate_schema_name.sql | 14 ++++++++ pmt/dbt/pmt_dbt/profiles.yml | 34 +++++++++++++++++++ pmt/dbt/pmt_dbt/snapshots/dpl/dim_org.sql | 34 +++++++++++++++++++ 5 files changed, 109 insertions(+), 1 deletion(-) create mode 100644 pmt/dbt/pmt_dbt/Dockerfile create mode 100644 pmt/dbt/pmt_dbt/macros/generate_schema_name.sql create mode 100644 pmt/dbt/pmt_dbt/profiles.yml create mode 100644 pmt/dbt/pmt_dbt/snapshots/dpl/dim_org.sql diff --git a/pmt/dbt/pmt_dbt/Dockerfile b/pmt/dbt/pmt_dbt/Dockerfile new file mode 100644 index 0000000..e13f320 --- /dev/null +++ b/pmt/dbt/pmt_dbt/Dockerfile @@ -0,0 +1,15 @@ +FROM ghcr.io/dbt-labs/dbt-postgres + +RUN chmod -R g+rwX /usr + +COPY . /usr/app/dbt/ + +COPY profiles.yml /usr/app/dbt/.dbt/profiles.yml + +COPY dbt_project.yml /app/dbt_project.yml + +WORKDIR /usr/app/dbt/ + +# dbt is already initiated + +CMD ["--help"] \ No newline at end of file diff --git a/pmt/dbt/pmt_dbt/dbt_project.yml b/pmt/dbt/pmt_dbt/dbt_project.yml index 8826f34..1ff6e46 100644 --- a/pmt/dbt/pmt_dbt/dbt_project.yml +++ b/pmt/dbt/pmt_dbt/dbt_project.yml @@ -23,7 +23,11 @@ clean-targets: # directories to be removed by `dbt clean` - "target" - "dbt_packages" - +vars: + # The `start_date` variable will be accessible in all resources + db_fdw_rrs: fdw_ods_rrs_replication + + # Configuring models # Full documentation: https://docs.getdbt.com/docs/configuring-models @@ -35,3 +39,10 @@ models: # Config indicated by + and applies to all files under models/example/ example: +materialized: view + dpl: + +schema: pmt_dpl + dal: + +schema: pmt_dal + sandbox: + +schema: pmt_sandbox + diff --git a/pmt/dbt/pmt_dbt/macros/generate_schema_name.sql b/pmt/dbt/pmt_dbt/macros/generate_schema_name.sql new file mode 100644 index 0000000..d9bb818 --- /dev/null +++ b/pmt/dbt/pmt_dbt/macros/generate_schema_name.sql @@ -0,0 +1,14 @@ +{% macro generate_schema_name(custom_schema_name, node) -%} + + {%- set default_schema = target.schema -%} + {%- if custom_schema_name is none -%} + + {{ default_schema }} + + {%- else -%} + + {{ custom_schema_name | trim }} + + {%- endif -%} + +{%- endmacro %} \ No newline at end of file diff --git a/pmt/dbt/pmt_dbt/profiles.yml b/pmt/dbt/pmt_dbt/profiles.yml new file mode 100644 index 0000000..d74470f --- /dev/null +++ b/pmt/dbt/pmt_dbt/profiles.yml @@ -0,0 +1,34 @@ +pmt_dbt: + outputs: + + dev: + type: postgres + threads: 2 + host: theory.bcgov + port: 5443 + user: dlh_admin_user + pass: "{{ env_var('dlh_password') }}" + dbname: lhousedev + schema: public + + test: + type: postgres + threads: 2 + host: theory.bcgov + port: 5444 + user: dlh_admin_user + pass: "{{ env_var('dlh_password') }}" + dbname: lhousetst + schema: public + + prod: + type: postgres + threads: 2 + host: existence.bcgov + port: 5436 + user: dlh_admin_user + pass: "{{ env_var('dlh_password') }}" + dbname: lhouseprd + schema: public + + target: dev diff --git a/pmt/dbt/pmt_dbt/snapshots/dpl/dim_org.sql b/pmt/dbt/pmt_dbt/snapshots/dpl/dim_org.sql new file mode 100644 index 0000000..0e4febc --- /dev/null +++ b/pmt/dbt/pmt_dbt/snapshots/dpl/dim_org.sql @@ -0,0 +1,34 @@ +{% snapshot dim_org %} + + {{ + config( + target_schema='pmt_dpl', + strategy='check', + unique_key='pi_hash_key', + check_cols='all', + bind=False, + ) + }} + + WITH scd_data AS ( + SELECT + 'CORP' as src_sys_code + ,org.org_unit_code as org_unit_code + ,org.org_unit_name as org_unit_description + ,org.rollup_region_code as rollup_region_code + ,null as rollup_region_description + ,org.rollup_dist_code as rollup_district_code + ,null as rollup_district_description + ,null as roll_up_area_code + ,null as roll_up_area_description, + -- Combine multiple keys into a single composite_key + md5(coalesce(cast('COPR' as varchar),'~') || '|'|| + coalesce(cast(org_unit_code as varchar),'~')) as pi_hash_key + FROM fdw_ods_fta_replication.org_unit org +) + +SELECT * +FROM scd_data + + +{% endsnapshot %}