Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,38 @@ select * from dune.dune__tmp_.dbt_template_view_model

All templates are in `models/templates/`.

## Table Visibility

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:

```sql
{{ config(
alias = 'my_model'
, materialized = 'table'
, meta = {
"dune": {
"public": true
}
}
, properties = {
"partitioned_by": "ARRAY['block_date']"
}
) }}
```

To make all models in a folder public, set it in `dbt_project.yml`:

```yaml
models:
my_project:
public_models:
+meta:
dune:
public: true
```

Visibility is only applied in the `prod` target and has no effect in development. Setting visibility for views is not supported at this time.

## GitHub Actions

### CI Workflow (Pull Requests)
Expand Down
2 changes: 2 additions & 0 deletions dbt_project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ models:
+materialized: view # fallback default, materialized should be overriden in model specific configs
+view_security: invoker # required security setting for views
+post-hook:
- sql: "{{ set_table_visibility(this, model.config.materialized) }}"
transaction: true
- sql: "{{ optimize_table(this, model.config.materialized) }}"
transaction: true
- sql: "{{ vacuum_table(this, model.config.materialized) }}"
Expand Down
19 changes: 19 additions & 0 deletions macros/dune_dbt_overrides/set_table_visibility.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{%- macro dune_properties(properties) -%}
map_from_entries(ARRAY[
{%- for key, value in properties.items() %}
ROW('{{ key }}', '{{ value }}')
{%- if not loop.last -%},{%- endif -%}
{%- endfor %}
])
{%- endmacro -%}

{# 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. #}
{% macro set_table_visibility(this, materialization) %}
{%- if target.name == 'prod'
and materialization in ('table', 'incremental') -%}
{%- set dune_public = config.get('meta', {}).get('dune', {}).get('public', false) -%}
{%- set properties = {'dune.public': 'true' if dune_public else 'false'} -%}
ALTER TABLE {{ this }}
SET PROPERTIES extra_properties = {{ dune_properties(properties) }}
{%- endif -%}
{%- endmacro -%}
5 changes: 5 additions & 0 deletions models/templates/dbt_template_append_incremental_model.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
alias = 'dbt_template_append_incremental_model'
, materialized = 'incremental'
, incremental_strategy = 'append'
, meta = {
"dune": {
"public": false
}
}
, properties = {
"partitioned_by": "ARRAY['block_date']"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
, incremental_strategy = 'delete+insert'
, unique_key = ['block_number', 'block_date']
, incremental_predicates = ["block_date >= now() - interval '1' day"]
, meta = {
"dune": {
"public": false
}
}
, properties = {
"partitioned_by": "ARRAY['block_date']"
}
Expand Down
5 changes: 5 additions & 0 deletions models/templates/dbt_template_merge_incremental_model.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
, incremental_strategy = 'merge'
, unique_key = ['block_number', 'block_date']
, incremental_predicates = ["DBT_INTERNAL_DEST.block_date >= now() - interval '1' day"]
, meta = {
"dune": {
"public": false
}
}
, properties = {
"partitioned_by": "ARRAY['block_date']"
}
Expand Down
5 changes: 5 additions & 0 deletions models/templates/dbt_template_table_model.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
{{ config(
alias = 'dbt_template_table_model'
, materialized = 'table'
, meta = {
"dune": {
"public": false
}
}
, properties = {
"partitioned_by": "ARRAY['block_date']"
}
Expand Down