Skip to content

Commit

Permalink
Lisätty onnistuneiden ajojen kirjanpito
Browse files Browse the repository at this point in the history
  • Loading branch information
Matz Rasmus committed Oct 25, 2024
1 parent 3c11b5d commit 275c6e9
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
5 changes: 4 additions & 1 deletion dbt/dbt_project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ models:
- columns: ['dw_metadata_stg_stored_at']
+docs:
node_color: "#00008b"

+pre-hook:
- "{{ stg_start() }}"
+post-hook:
- "{{ stg_end() }}"
dw:
+schema: dw
# materialized=incremental set in dw macro
Expand Down
20 changes: 20 additions & 0 deletions dbt/macros/helpers/stg_end.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{% macro stg_end() -%}
{%- if target.name == 'prod' %}
with data as (
select
model,
replace(regexp_replace(split_part(model, '.', 3),'stg_',''),'"','') as raw_table,
start_time
from raw.dbt_runs dr
where model = '{{ this }}'
)

merge into raw.completed_dbt_runs as t
using data as s
on t.model = s.model
when matched
then update set start_time=s.start_time
when not matched
then insert values (model,raw_table,start_time)
{% endif %}
{%- endmacro %}
17 changes: 17 additions & 0 deletions dbt/macros/helpers/stg_start.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{% macro stg_start() -%}
{%- if target.name == 'prod' %}
with data as (
select
'{{ this }}' as model,
current_timestamp as start_time
)

merge into raw.dbt_runs as t
using data as s
on t.model = s.model
when matched
then update set start_time=s.start_time
when not matched
then insert values (model,start_time)
{% endif %}
{%- endmacro %}

0 comments on commit 275c6e9

Please sign in to comment.