Skip to content

Commit 86f35b3

Browse files
authored
Merge pull request #1 from duneanalytics/test-ci
fix CI pipeline, update model naming standards, import dbt_utils
2 parents dbd9673 + b24fd69 commit 86f35b3

File tree

8 files changed

+64
-24
lines changed

8 files changed

+64
-24
lines changed

.github/workflows/dbt_run.yml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,27 @@ jobs:
2626
- name: Install dependencies with uv
2727
run: uv sync
2828

29+
- name: Setup variables
30+
run: |
31+
echo "PROFILE=--profiles-dir $HOME/.dbt --profile dunesql" >> $GITHUB_ENV
32+
2933
- name: Run dbt deps
3034
run: uv run dbt deps
3135

3236
- name: Activate Trino cluster
3337
run: "./scripts/activate-trino-cluster.sh"
3438

3539
- name: Run dbt compile
36-
run: uv run dbt compile
40+
run: uv run dbt compile $PROFILE
3741

3842
- name: Run dbt run (full refresh)
39-
run: uv run dbt run --full-refresh
43+
run: uv run dbt run $PROFILE --full-refresh
4044

4145
- name: Run dbt test (after full refresh)
42-
run: uv run dbt test
46+
run: uv run dbt test $PROFILE
4347

4448
- name: Run dbt run (incremental update)
45-
run: uv run dbt run
49+
run: uv run dbt run $PROFILE
4650

4751
- name: Run dbt test (after incremental)
48-
run: uv run dbt test
52+
run: uv run dbt test $PROFILE

macros/dune_dbt_overrides/get_custom_schema.sql

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{#
2-
goal: depending on how we handle dev vs. prod environments (i.e. s3 bucket names), we may not need this macro override
2+
goal: depending on how we handle dev vs. prod environments (i.e. s3), we may not need this macro override
33

44
Custom schema naming logic for dev vs prod environments
55

@@ -19,19 +19,22 @@
1919
{% macro generate_schema_name(custom_schema_name, node) -%}
2020
2121
{%- set default_schema = target.schema -%}
22-
{%- if custom_schema_name is none -%}
23-
24-
{{ default_schema }}
22+
{%- if target.name == 'prod' and custom_schema_name is not none -%}
23+
{# prod environment #}
24+
{{ custom_schema_name | trim }}
2525
26-
{%- elif target.name == 'prod' -%}
26+
{%- elif target.schema.startswith("github_actions") -%}
27+
{# test environment, CI pipeline #}
28+
{{ 'test_schema' }}
2729
28-
{{ custom_schema_name | trim }}
30+
{%- elif custom_schema_name is none -%}
31+
32+
{{ default_schema }}
2933
3034
{%- else -%}
31-
35+
{# dev environment, running locally #}
3236
{{ default_schema }}_{{ custom_schema_name | trim }}
3337
3438
{%- endif -%}
3539
36-
{%- endmacro %}
37-
40+
{%- endmacro %}

models/_schema.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,30 @@ models:
66
columns:
77
- name: block_number
88
description: "The unique block number in last 1 day"
9+
- name: block_date
10+
description: "The date of the block"
11+
- name: total_tx_per_block
12+
description: "The total number of transactions per block"
13+
- name: dbt_template_table_model
14+
description: "A starter dbt table model"
15+
columns:
16+
- name: block_number
17+
description: "The unique block number in last 1 day"
18+
- name: block_date
19+
description: "The date of the block"
20+
- name: total_tx_per_block
21+
description: "The total number of transactions per block"
22+
- name: dbt_template_incremental_model
23+
description: "A starter dbt incremental model"
24+
data_tests:
25+
- dbt_utils.unique_combination_of_columns:
26+
combination_of_columns:
27+
- block_number
28+
- block_date
29+
columns:
30+
- name: block_number
31+
description: "The unique block number in last 1 day"
32+
- name: block_date
33+
description: "The date of the block"
934
- name: total_tx_per_block
1035
description: "The total number of transactions per block"

models/dbt_template_incremental_model.sql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
#}
66

77
{{ config(
8-
schema = 'dbt_template'
9-
, alias = 'incremental_model'
8+
schema = 'test_schema'
9+
, alias = 'dbt_template_incremental_model'
1010
, materialized = 'incremental'
1111
, incremental_strategy = 'merge'
1212
, unique_key = ['block_number', 'block_date']
@@ -18,7 +18,7 @@
1818
select
1919
block_number
2020
, block_date
21-
, count(1) as total_tx_per_block
21+
, count(1) as total_tx_per_block -- count per block
2222
from
2323
{{ source('ethereum', 'transactions') }}
2424
where

models/dbt_template_table_model.sql

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,21 @@
77
#}
88
99
{{ config(
10-
schema = 'dbt_template'
11-
, alias = 'table_model'
10+
schema = 'test_schema'
11+
, alias = 'dbt_template_table_model'
1212
, materialized = 'table'
1313
, on_table_exists = 'replace'
1414
)
1515
}}
1616
1717
select
1818
block_number
19+
, block_date
1920
, count(1) as total_tx_per_block
2021
from
2122
{{ source('ethereum', 'transactions') }}
2223
where
2324
block_date >= now() - interval '1' day
2425
group by
25-
block_number
26+
block_number
27+
, block_date

models/dbt_template_view_model.sql

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
{{ config(
2-
schema = 'dbt_template'
3-
, alias = 'view_model'
2+
schema = 'test_schema'
3+
, alias = 'dbt_template_view_model'
44
, materialized = 'view'
55
)
66
}}
77

88
select
99
block_number
10+
, block_date
1011
, count(1) as total_tx_per_block
1112
from
1213
{{ source('ethereum', 'transactions') }}
1314
where
1415
block_date >= now() - interval '1' day
1516
group by
16-
block_number
17+
block_number
18+
, block_date

packages.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
packages:
2+
- package: dbt-labs/dbt_utils
3+
version: [">=1.0.0", "<2.0.0"]
4+

scripts/activate-trino-cluster.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ WAIT_TIME=15
99

1010
until [ "$RETRY_COUNT" -ge "$MAX_RETRIES" ]
1111
do
12-
uv run dbt debug && break
12+
uv run dbt debug $PROFILE && break
1313
RETRY_COUNT=$((RETRY_COUNT+1))
1414
if [ "$RETRY_COUNT" -ge "$MAX_RETRIES" ]; then
1515
echo "Max retries reached, failing..."

0 commit comments

Comments
 (0)