Skip to content

Commit de1a94c

Browse files
committed
use meta.dune.public for table visibility config
1 parent d201974 commit de1a94c

7 files changed

Lines changed: 36 additions & 43 deletions

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,34 @@ select * from dune.dune__tmp_.dbt_template_view_model
152152

153153
All templates are in `models/templates/`.
154154

155+
## Table Visibility
156+
157+
By default, all tables are **private** — only your team can query them. To make a table publicly accessible (visible and queryable by anyone on Dune), set `meta.dune.public: true` in the model config:
158+
159+
```sql
160+
{{ config(
161+
alias = 'my_model'
162+
, materialized = 'table'
163+
, meta = {"dune": {"public": true}}
164+
, properties = {
165+
"partitioned_by": "ARRAY['block_date']"
166+
}
167+
) }}
168+
```
169+
170+
To make all models in a folder public, set it in `dbt_project.yml`:
171+
172+
```yaml
173+
models:
174+
my_project:
175+
public_models:
176+
+meta:
177+
dune:
178+
public: true
179+
```
180+
181+
Visibility is only applied in the `prod` target and has no effect in development. Views are not supported.
182+
155183
## GitHub Actions
156184

157185
### CI Workflow (Pull Requests)

macros/dune_dbt_overrides/properties.sql

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,4 @@
1-
{#
2-
Override of the dbt-trino adapter's properties() macro to inject dune.public
3-
into extra_properties at CREATE TABLE time.
4-
5-
Configure per model via config():
6-
, dune_public = true -- make table publicly visible on Dune
7-
, dune_public = false -- (default) keep table private
8-
9-
Or set for an entire folder in dbt_project.yml:
10-
models:
11-
my_project:
12-
public_models:
13-
+dune_public: true
14-
15-
Only runs in prod. On incremental (non-full-refresh) runs, set_table_visibility
16-
handles it via ALTER TABLE instead.
17-
#}
1+
{# Override of the dbt-trino adapter's properties() macro to inject dune.public into extra_properties at CREATE TABLE time. #}
182
{% macro properties(temporary=False) %}
193
{%- set _properties = config.get('properties') -%}
204
{%- set table_format = config.get('table_format') -%}
@@ -58,8 +42,7 @@
5842
{%- endif -%}
5943
{%- endif -%}
6044

61-
{#-- Inject dune.public into extra_properties at CREATE time (prod only) --#}
62-
{%- set dune_public = config.get('dune_public') -%}
45+
{%- set dune_public = config.get('meta', {}).get('dune', {}).get('public') -%}
6346
{%- if dune_public is not none and target.name == 'prod' -%}
6447
{%- set visibility_value = 'true' if dune_public else 'false' -%}
6548
{%- set extra_props_sql = "map_from_entries(ARRAY[ROW('dune.public', '" ~ visibility_value ~ "')])" -%}

macros/dune_dbt_overrides/set_table_visibility.sql

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,12 @@
77
])
88
{%- endmacro -%}
99

10-
{#
11-
set_table_visibility: post-hook that sets dune.public on incremental (non-full-refresh) runs.
12-
13-
For table materializations and incremental full-refreshes, extra_properties is set
14-
at CREATE TABLE time via the overridden properties() macro. This hook handles the
15-
incremental case where no CREATE is issued (INSERT/MERGE only).
16-
17-
Configure per model via config():
18-
, dune_public = true -- make table publicly accessible on Dune (visible and queryable by anyone)
19-
, dune_public = false -- (default) keep table private
20-
21-
Or set for an entire folder in dbt_project.yml:
22-
models:
23-
my_project:
24-
public_models:
25-
+dune_public: true
26-
27-
Only runs in prod. Views are not supported.
28-
#}
10+
{# post-hook that keeps dune.public in sync on incremental (non-full-refresh) runs where no CREATE TABLE is issued #}
2911
{% macro set_table_visibility(this, materialization) %}
3012
{%- if target.name == 'prod'
3113
and materialization == 'incremental'
3214
and not flags.FULL_REFRESH -%}
33-
{%- set dune_public = config.get('dune_public', false) -%}
15+
{%- set dune_public = config.get('meta', {}).get('dune', {}).get('public', false) -%}
3416
{%- set properties = {'dune.public': 'true' if dune_public else 'false'} -%}
3517
ALTER TABLE {{ this }}
3618
SET PROPERTIES extra_properties = {{ dune_properties(properties) }}

models/templates/dbt_template_append_incremental_model.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
alias = 'dbt_template_append_incremental_model'
1010
, materialized = 'incremental'
1111
, incremental_strategy = 'append'
12-
, dune_public = false
12+
, meta = {"dune": {"public": false}}
1313
, properties = {
1414
"partitioned_by": "ARRAY['block_date']"
1515
}

models/templates/dbt_template_delete_insert_incremental_model.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +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 = false
7+
, meta = {"dune": {"public": false}}
88
, properties = {
99
"partitioned_by": "ARRAY['block_date']"
1010
}

models/templates/dbt_template_merge_incremental_model.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +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 = false
7+
, meta = {"dune": {"public": false}}
88
, properties = {
99
"partitioned_by": "ARRAY['block_date']"
1010
}

models/templates/dbt_template_table_model.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{{ config(
22
alias = 'dbt_template_table_model'
33
, materialized = 'table'
4-
, dune_public = false
4+
, meta = {"dune": {"public": false}}
55
, properties = {
66
"partitioned_by": "ARRAY['block_date']"
77
}

0 commit comments

Comments
 (0)