From f8508e3e2a4b875c7416971d8b54a02e9d3ff287 Mon Sep 17 00:00:00 2001 From: Njuguna Ndung'u Date: Wed, 24 Jan 2024 15:42:42 +0300 Subject: [PATCH] make ANC module incremental --- dbt_project.yml | 3 --- models/brac/impact/ANC/impact_ancview_danger_sign.sql | 8 +++++++- models/brac/impact/ANC/impact_ancview_delivery.sql | 8 +++++++- models/brac/impact/ANC/impact_ancview_pregnancy_visit.sql | 8 +++++++- 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/dbt_project.yml b/dbt_project.yml index af47e092..9a440526 100644 --- a/dbt_project.yml +++ b/dbt_project.yml @@ -27,9 +27,6 @@ clean-targets: # directories to be removed by `dbt clean` - 'target' - 'dbt_modules' -vars: - end_date: "2020-12-12" - models: type_partitions: root: diff --git a/models/brac/impact/ANC/impact_ancview_danger_sign.sql b/models/brac/impact/ANC/impact_ancview_danger_sign.sql index ae411b31..af02fa21 100644 --- a/models/brac/impact/ANC/impact_ancview_danger_sign.sql +++ b/models/brac/impact/ANC/impact_ancview_danger_sign.sql @@ -1,5 +1,5 @@ {{ config( - materialized='view', + materialized='incremental', description='ANC Danger Signs view for Brac Uganda' ) }} @@ -44,3 +44,9 @@ SELECT reported FROM danger_sign_CTE + +{% if is_incremental() %} + + where reported > (select max(reported) from {{ this }}) + +{% endif %} diff --git a/models/brac/impact/ANC/impact_ancview_delivery.sql b/models/brac/impact/ANC/impact_ancview_delivery.sql index ab167afc..997ff4e1 100644 --- a/models/brac/impact/ANC/impact_ancview_delivery.sql +++ b/models/brac/impact/ANC/impact_ancview_delivery.sql @@ -1,5 +1,5 @@ {{ config( - materialized='view', + materialized='incremental', description='ANC Delivery view for Brac Uganda' ) }} @@ -37,3 +37,9 @@ WHERE pnc.follow_up_count = '1' AND (pnc.pregnancy_outcome IN (VALUES ('healthy'), ('still_birth'))) AND pnc.patient_id IS NOT NULL AND pnc.patient_id <> '' + +{% if is_incremental() %} + + where reported > (select max(reported) from {{ this }}) + +{% endif %} diff --git a/models/brac/impact/ANC/impact_ancview_pregnancy_visit.sql b/models/brac/impact/ANC/impact_ancview_pregnancy_visit.sql index 78d8bb19..70779ade 100644 --- a/models/brac/impact/ANC/impact_ancview_pregnancy_visit.sql +++ b/models/brac/impact/ANC/impact_ancview_pregnancy_visit.sql @@ -1,5 +1,5 @@ {{ config( - materialized='view', + materialized='incremental', description='ANC Pregnancy Visit view for Brac Uganda' ) }} @@ -16,3 +16,9 @@ FROM {{ ref('useview_visit') }} WHERE visit_type = 'anc' + +{% if is_incremental() %} + + where reported > (select max(reported) from {{ this }}) + +{% endif %}