Skip to content

Commit d5eddfe

Browse files
authored
add table visibility control via dune_public config (#57)
1 parent 3556d9d commit d5eddfe

File tree

7 files changed

+73
-0
lines changed

7 files changed

+73
-0
lines changed

README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,38 @@ 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 = {
164+
"dune": {
165+
"public": true
166+
}
167+
}
168+
, properties = {
169+
"partitioned_by": "ARRAY['block_date']"
170+
}
171+
) }}
172+
```
173+
174+
To make all models in a folder public, set it in `dbt_project.yml`:
175+
176+
```yaml
177+
models:
178+
my_project:
179+
public_models:
180+
+meta:
181+
dune:
182+
public: true
183+
```
184+
185+
Visibility is only applied in the `prod` target and has no effect in development. Setting visibility for views is not supported at this time.
186+
155187
## GitHub Actions
156188

157189
### CI Workflow (Pull Requests)

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: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
{# post-hook that sets dune.public via ALTER TABLE on every table/incremental run (prod only). Setting visibility for views is not supported at this time. #}
11+
{% macro set_table_visibility(this, materialization) %}
12+
{%- if target.name == 'prod'
13+
and materialization in ('table', 'incremental') -%}
14+
{%- set dune_public = config.get('meta', {}).get('dune', {}).get('public', false) -%}
15+
{%- set properties = {'dune.public': 'true' if dune_public else 'false'} -%}
16+
ALTER TABLE {{ this }}
17+
SET PROPERTIES extra_properties = {{ dune_properties(properties) }}
18+
{%- endif -%}
19+
{%- endmacro -%}

models/templates/dbt_template_append_incremental_model.sql

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
alias = 'dbt_template_append_incremental_model'
1010
, materialized = 'incremental'
1111
, incremental_strategy = 'append'
12+
, meta = {
13+
"dune": {
14+
"public": false
15+
}
16+
}
1217
, properties = {
1318
"partitioned_by": "ARRAY['block_date']"
1419
}

models/templates/dbt_template_delete_insert_incremental_model.sql

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
, incremental_strategy = 'delete+insert'
55
, unique_key = ['block_number', 'block_date']
66
, incremental_predicates = ["block_date >= now() - interval '1' day"]
7+
, meta = {
8+
"dune": {
9+
"public": false
10+
}
11+
}
712
, properties = {
813
"partitioned_by": "ARRAY['block_date']"
914
}

models/templates/dbt_template_merge_incremental_model.sql

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
, incremental_strategy = 'merge'
55
, unique_key = ['block_number', 'block_date']
66
, incremental_predicates = ["DBT_INTERNAL_DEST.block_date >= now() - interval '1' day"]
7+
, meta = {
8+
"dune": {
9+
"public": false
10+
}
11+
}
712
, properties = {
813
"partitioned_by": "ARRAY['block_date']"
914
}

models/templates/dbt_template_table_model.sql

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
{{ config(
22
alias = 'dbt_template_table_model'
33
, materialized = 'table'
4+
, meta = {
5+
"dune": {
6+
"public": false
7+
}
8+
}
49
, properties = {
510
"partitioned_by": "ARRAY['block_date']"
611
}

0 commit comments

Comments
 (0)