Skip to content

Commit 1bb6a60

Browse files
committed
add table visibility control via dune_public config
1 parent 3556d9d commit 1bb6a60

File tree

6 files changed

+38
-0
lines changed

6 files changed

+38
-0
lines changed

dbt_project.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ models:
3434
+materialized: view # fallback default, materialized should be overriden in model specific configs
3535
+view_security: invoker # required security setting for views
3636
+post-hook:
37+
- sql: "{{ set_table_visibility(this, model.config.materialized) }}"
38+
transaction: true
3739
- sql: "{{ optimize_table(this, model.config.materialized) }}"
3840
transaction: true
3941
- sql: "{{ vacuum_table(this, model.config.materialized) }}"
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{%- macro dune_properties(properties) -%}
2+
map_from_entries(ARRAY[
3+
{%- for key, value in properties.items() %}
4+
ROW('{{ key }}', '{{ value }}')
5+
{%- if not loop.last -%},{%- endif -%}
6+
{%- endfor %}
7+
])
8+
{%- endmacro -%}
9+
10+
{#
11+
set_table_visibility: post-hook macro that sets the dune.public extra property on tables/incrementals.
12+
13+
Configure per model via config():
14+
, dune_public = true -- make table publicly visible on Dune
15+
, dune_public = false -- (default) keep table private
16+
17+
Or set for an entire folder in dbt_project.yml:
18+
models:
19+
my_project:
20+
public_models:
21+
+dune_public: true
22+
23+
Only runs in prod. Views are not supported yet.
24+
#}
25+
{% macro set_table_visibility(this, materialization) %}
26+
{%- if target.name == 'prod' and materialization in ('table', 'incremental') -%}
27+
{%- set dune_public = config.get('dune_public', false) -%}
28+
{%- set properties = {'dune.public': 'true' if dune_public else 'false'} -%}
29+
ALTER TABLE {{ this }}
30+
SET PROPERTIES extra_properties = {{ dune_properties(properties) }}
31+
{%- endif -%}
32+
{%- endmacro -%}

models/templates/dbt_template_append_incremental_model.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
alias = 'dbt_template_append_incremental_model'
1010
, materialized = 'incremental'
1111
, incremental_strategy = 'append'
12+
-- , dune_public = true -- uncomment to make this table publicly visible on Dune
1213
, properties = {
1314
"partitioned_by": "ARRAY['block_date']"
1415
}

models/templates/dbt_template_delete_insert_incremental_model.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
, incremental_strategy = 'delete+insert'
55
, unique_key = ['block_number', 'block_date']
66
, incremental_predicates = ["block_date >= now() - interval '1' day"]
7+
-- , dune_public = true -- uncomment to make this table publicly visible on Dune
78
, properties = {
89
"partitioned_by": "ARRAY['block_date']"
910
}

models/templates/dbt_template_merge_incremental_model.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
, incremental_strategy = 'merge'
55
, unique_key = ['block_number', 'block_date']
66
, incremental_predicates = ["DBT_INTERNAL_DEST.block_date >= now() - interval '1' day"]
7+
-- , dune_public = true -- uncomment to make this table publicly visible on Dune
78
, properties = {
89
"partitioned_by": "ARRAY['block_date']"
910
}

models/templates/dbt_template_table_model.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{{ config(
22
alias = 'dbt_template_table_model'
33
, materialized = 'table'
4+
-- , dune_public = true -- uncomment to make this table publicly visible on Dune
45
, properties = {
56
"partitioned_by": "ARRAY['block_date']"
67
}

0 commit comments

Comments
 (0)