From 1bb6a60ee1d38ce59c7bfcc4dac5dc77f5ed41a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Monteiro?= Date: Tue, 17 Mar 2026 19:58:24 +0000 Subject: [PATCH 1/7] add table visibility control via dune_public config --- dbt_project.yml | 2 ++ .../set_table_visibility.sql | 32 +++++++++++++++++++ .../dbt_template_append_incremental_model.sql | 1 + ...mplate_delete_insert_incremental_model.sql | 1 + .../dbt_template_merge_incremental_model.sql | 1 + models/templates/dbt_template_table_model.sql | 1 + 6 files changed, 38 insertions(+) create mode 100644 macros/dune_dbt_overrides/set_table_visibility.sql diff --git a/dbt_project.yml b/dbt_project.yml index da479fa..a6c5e84 100644 --- a/dbt_project.yml +++ b/dbt_project.yml @@ -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) }}" diff --git a/macros/dune_dbt_overrides/set_table_visibility.sql b/macros/dune_dbt_overrides/set_table_visibility.sql new file mode 100644 index 0000000..270d246 --- /dev/null +++ b/macros/dune_dbt_overrides/set_table_visibility.sql @@ -0,0 +1,32 @@ +{%- macro dune_properties(properties) -%} + map_from_entries(ARRAY[ + {%- for key, value in properties.items() %} + ROW('{{ key }}', '{{ value }}') + {%- if not loop.last -%},{%- endif -%} + {%- endfor %} + ]) +{%- endmacro -%} + +{# + set_table_visibility: post-hook macro that sets the dune.public extra property on tables/incrementals. + + Configure per model via config(): + , dune_public = true -- make table publicly visible on Dune + , dune_public = false -- (default) keep table private + + Or set for an entire folder in dbt_project.yml: + models: + my_project: + public_models: + +dune_public: true + + Only runs in prod. Views are not supported yet. +#} +{% macro set_table_visibility(this, materialization) %} +{%- if target.name == 'prod' and materialization in ('table', 'incremental') -%} + {%- set dune_public = config.get('dune_public', false) -%} + {%- set properties = {'dune.public': 'true' if dune_public else 'false'} -%} + ALTER TABLE {{ this }} + SET PROPERTIES extra_properties = {{ dune_properties(properties) }} +{%- endif -%} +{%- endmacro -%} diff --git a/models/templates/dbt_template_append_incremental_model.sql b/models/templates/dbt_template_append_incremental_model.sql index 1191758..4dd0319 100644 --- a/models/templates/dbt_template_append_incremental_model.sql +++ b/models/templates/dbt_template_append_incremental_model.sql @@ -9,6 +9,7 @@ alias = 'dbt_template_append_incremental_model' , materialized = 'incremental' , incremental_strategy = 'append' + -- , dune_public = true -- uncomment to make this table publicly visible on Dune , properties = { "partitioned_by": "ARRAY['block_date']" } diff --git a/models/templates/dbt_template_delete_insert_incremental_model.sql b/models/templates/dbt_template_delete_insert_incremental_model.sql index 8b7c0cb..c1b71a1 100644 --- a/models/templates/dbt_template_delete_insert_incremental_model.sql +++ b/models/templates/dbt_template_delete_insert_incremental_model.sql @@ -4,6 +4,7 @@ , incremental_strategy = 'delete+insert' , unique_key = ['block_number', 'block_date'] , incremental_predicates = ["block_date >= now() - interval '1' day"] + -- , dune_public = true -- uncomment to make this table publicly visible on Dune , properties = { "partitioned_by": "ARRAY['block_date']" } diff --git a/models/templates/dbt_template_merge_incremental_model.sql b/models/templates/dbt_template_merge_incremental_model.sql index 38b15c2..d0e4505 100644 --- a/models/templates/dbt_template_merge_incremental_model.sql +++ b/models/templates/dbt_template_merge_incremental_model.sql @@ -4,6 +4,7 @@ , incremental_strategy = 'merge' , unique_key = ['block_number', 'block_date'] , incremental_predicates = ["DBT_INTERNAL_DEST.block_date >= now() - interval '1' day"] + -- , dune_public = true -- uncomment to make this table publicly visible on Dune , properties = { "partitioned_by": "ARRAY['block_date']" } diff --git a/models/templates/dbt_template_table_model.sql b/models/templates/dbt_template_table_model.sql index bf3952f..da965b0 100644 --- a/models/templates/dbt_template_table_model.sql +++ b/models/templates/dbt_template_table_model.sql @@ -1,6 +1,7 @@ {{ config( alias = 'dbt_template_table_model' , materialized = 'table' + -- , dune_public = true -- uncomment to make this table publicly visible on Dune , properties = { "partitioned_by": "ARRAY['block_date']" } From 211e82ac4b9449bc88e07033390f33d3f1b641cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Monteiro?= Date: Wed, 18 Mar 2026 00:54:26 +0000 Subject: [PATCH 2/7] set extra_properties at create time via properties() override, alter on incremental runs --- macros/dune_dbt_overrides/properties.sql | 81 +++++++++++++++++++ .../set_table_visibility.sql | 12 ++- .../dbt_template_append_incremental_model.sql | 2 +- ...mplate_delete_insert_incremental_model.sql | 2 +- .../dbt_template_merge_incremental_model.sql | 2 +- models/templates/dbt_template_table_model.sql | 2 +- 6 files changed, 94 insertions(+), 7 deletions(-) create mode 100644 macros/dune_dbt_overrides/properties.sql diff --git a/macros/dune_dbt_overrides/properties.sql b/macros/dune_dbt_overrides/properties.sql new file mode 100644 index 0000000..bb9a406 --- /dev/null +++ b/macros/dune_dbt_overrides/properties.sql @@ -0,0 +1,81 @@ +{# + Override of the dbt-trino adapter's properties() macro to inject dune.public + into extra_properties at CREATE TABLE time. + + Configure per model via config(): + , dune_public = true -- make table publicly visible on Dune + , dune_public = false -- (default) keep table private + + Or set for an entire folder in dbt_project.yml: + models: + my_project: + public_models: + +dune_public: true + + Only runs in prod. On incremental (non-full-refresh) runs, set_table_visibility + handles it via ALTER TABLE instead. +#} +{% macro properties(temporary=False) %} + {%- set _properties = config.get('properties') -%} + {%- set table_format = config.get('table_format') -%} + {%- set file_format = config.get('file_format') -%} + + {%- if file_format -%} + {%- if _properties -%} + {%- if _properties.format -%} + {% set msg %} + You can specify either 'file_format' or 'properties.format' configurations, but not both. + {% endset %} + {% do exceptions.raise_compiler_error(msg) %} + {%- else -%} + {%- do _properties.update({'format': "'" ~ file_format ~ "'"}) -%} + {%- endif -%} + {%- else -%} + {%- set _properties = {'format': "'" ~ file_format ~ "'"} -%} + {%- endif -%} + {%- endif -%} + + {%- if table_format -%} + {%- if _properties -%} + {%- if _properties.type -%} + {% set msg %} + You can specify either 'table_format' or 'properties.type' configurations, but not both. + {% endset %} + {% do exceptions.raise_compiler_error(msg) %} + {%- else -%} + {%- do _properties.update({'type': "'" ~ table_format ~ "'"}) -%} + {%- endif -%} + {%- else -%} + {%- set _properties = {'type': "'" ~ table_format ~ "'"} -%} + {%- endif -%} + {%- endif -%} + + {%- if temporary -%} + {%- if _properties -%} + {%- if _properties.location -%} + {%- do _properties.update({'location': _properties.location[:-1] ~ "__dbt_tmp'"}) -%} + {%- endif -%} + {%- endif -%} + {%- endif -%} + + {#-- Inject dune.public into extra_properties at CREATE time (prod only) --#} + {%- set dune_public = config.get('dune_public') -%} + {%- if dune_public is not none and target.name == 'prod' -%} + {%- set visibility_value = 'true' if dune_public else 'false' -%} + {%- set extra_props_sql = "map_from_entries(ARRAY[ROW('dune.public', '" ~ visibility_value ~ "')])" -%} + {%- if _properties is none -%} + {%- set _properties = {'extra_properties': extra_props_sql} -%} + {%- else -%} + {%- do _properties.update({'extra_properties': extra_props_sql}) -%} + {%- endif -%} + {%- endif -%} + + {%- if _properties is not none -%} + WITH ( + {%- for key, value in _properties.items() -%} + {{ key }} = {{ value }} + {%- if not loop.last -%}{{ ',\n ' }}{%- endif -%} + {%- endfor -%} + ) + {%- endif -%} +{%- endmacro -%} diff --git a/macros/dune_dbt_overrides/set_table_visibility.sql b/macros/dune_dbt_overrides/set_table_visibility.sql index 270d246..a1537d8 100644 --- a/macros/dune_dbt_overrides/set_table_visibility.sql +++ b/macros/dune_dbt_overrides/set_table_visibility.sql @@ -8,7 +8,11 @@ {%- endmacro -%} {# - set_table_visibility: post-hook macro that sets the dune.public extra property on tables/incrementals. + set_table_visibility: post-hook that sets dune.public on incremental (non-full-refresh) runs. + + For table materializations and incremental full-refreshes, extra_properties is set + at CREATE TABLE time via the overridden properties() macro. This hook handles the + incremental case where no CREATE is issued (INSERT/MERGE only). Configure per model via config(): , dune_public = true -- make table publicly visible on Dune @@ -20,10 +24,12 @@ public_models: +dune_public: true - Only runs in prod. Views are not supported yet. + Only runs in prod. Views are not supported. #} {% macro set_table_visibility(this, materialization) %} -{%- if target.name == 'prod' and materialization in ('table', 'incremental') -%} +{%- if target.name == 'prod' + and materialization == 'incremental' + and not flags.FULL_REFRESH -%} {%- set dune_public = config.get('dune_public', false) -%} {%- set properties = {'dune.public': 'true' if dune_public else 'false'} -%} ALTER TABLE {{ this }} diff --git a/models/templates/dbt_template_append_incremental_model.sql b/models/templates/dbt_template_append_incremental_model.sql index 4dd0319..15e580a 100644 --- a/models/templates/dbt_template_append_incremental_model.sql +++ b/models/templates/dbt_template_append_incremental_model.sql @@ -9,7 +9,7 @@ alias = 'dbt_template_append_incremental_model' , materialized = 'incremental' , incremental_strategy = 'append' - -- , dune_public = true -- uncomment to make this table publicly visible on Dune + , dune_public = false , properties = { "partitioned_by": "ARRAY['block_date']" } diff --git a/models/templates/dbt_template_delete_insert_incremental_model.sql b/models/templates/dbt_template_delete_insert_incremental_model.sql index c1b71a1..7877dfd 100644 --- a/models/templates/dbt_template_delete_insert_incremental_model.sql +++ b/models/templates/dbt_template_delete_insert_incremental_model.sql @@ -4,7 +4,7 @@ , incremental_strategy = 'delete+insert' , unique_key = ['block_number', 'block_date'] , incremental_predicates = ["block_date >= now() - interval '1' day"] - -- , dune_public = true -- uncomment to make this table publicly visible on Dune + , dune_public = false , properties = { "partitioned_by": "ARRAY['block_date']" } diff --git a/models/templates/dbt_template_merge_incremental_model.sql b/models/templates/dbt_template_merge_incremental_model.sql index d0e4505..ae91441 100644 --- a/models/templates/dbt_template_merge_incremental_model.sql +++ b/models/templates/dbt_template_merge_incremental_model.sql @@ -4,7 +4,7 @@ , incremental_strategy = 'merge' , unique_key = ['block_number', 'block_date'] , incremental_predicates = ["DBT_INTERNAL_DEST.block_date >= now() - interval '1' day"] - -- , dune_public = true -- uncomment to make this table publicly visible on Dune + , dune_public = false , properties = { "partitioned_by": "ARRAY['block_date']" } diff --git a/models/templates/dbt_template_table_model.sql b/models/templates/dbt_template_table_model.sql index da965b0..2f8938e 100644 --- a/models/templates/dbt_template_table_model.sql +++ b/models/templates/dbt_template_table_model.sql @@ -1,7 +1,7 @@ {{ config( alias = 'dbt_template_table_model' , materialized = 'table' - -- , dune_public = true -- uncomment to make this table publicly visible on Dune + , dune_public = false , properties = { "partitioned_by": "ARRAY['block_date']" } From d20197421cb70bb8b57831fb2f0bced4d8581d31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Monteiro?= Date: Wed, 18 Mar 2026 00:59:23 +0000 Subject: [PATCH 3/7] clarify dune_public makes table publicly accessible (not just visible) --- macros/dune_dbt_overrides/set_table_visibility.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/macros/dune_dbt_overrides/set_table_visibility.sql b/macros/dune_dbt_overrides/set_table_visibility.sql index a1537d8..4137fc0 100644 --- a/macros/dune_dbt_overrides/set_table_visibility.sql +++ b/macros/dune_dbt_overrides/set_table_visibility.sql @@ -15,7 +15,7 @@ incremental case where no CREATE is issued (INSERT/MERGE only). Configure per model via config(): - , dune_public = true -- make table publicly visible on Dune + , dune_public = true -- make table publicly accessible on Dune (visible and queryable by anyone) , dune_public = false -- (default) keep table private Or set for an entire folder in dbt_project.yml: From de1a94c30b29f03df4111fa72e60e9de6325df6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Monteiro?= Date: Wed, 18 Mar 2026 12:31:40 +0000 Subject: [PATCH 4/7] use meta.dune.public for table visibility config --- README.md | 28 +++++++++++++++++++ macros/dune_dbt_overrides/properties.sql | 21 ++------------ .../set_table_visibility.sql | 22 ++------------- .../dbt_template_append_incremental_model.sql | 2 +- ...mplate_delete_insert_incremental_model.sql | 2 +- .../dbt_template_merge_incremental_model.sql | 2 +- models/templates/dbt_template_table_model.sql | 2 +- 7 files changed, 36 insertions(+), 43 deletions(-) diff --git a/README.md b/README.md index 8a889b6..24f3a94 100644 --- a/README.md +++ b/README.md @@ -152,6 +152,34 @@ 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. Views are not supported. + ## GitHub Actions ### CI Workflow (Pull Requests) diff --git a/macros/dune_dbt_overrides/properties.sql b/macros/dune_dbt_overrides/properties.sql index bb9a406..a64b0ab 100644 --- a/macros/dune_dbt_overrides/properties.sql +++ b/macros/dune_dbt_overrides/properties.sql @@ -1,20 +1,4 @@ -{# - Override of the dbt-trino adapter's properties() macro to inject dune.public - into extra_properties at CREATE TABLE time. - - Configure per model via config(): - , dune_public = true -- make table publicly visible on Dune - , dune_public = false -- (default) keep table private - - Or set for an entire folder in dbt_project.yml: - models: - my_project: - public_models: - +dune_public: true - - Only runs in prod. On incremental (non-full-refresh) runs, set_table_visibility - handles it via ALTER TABLE instead. -#} +{# Override of the dbt-trino adapter's properties() macro to inject dune.public into extra_properties at CREATE TABLE time. #} {% macro properties(temporary=False) %} {%- set _properties = config.get('properties') -%} {%- set table_format = config.get('table_format') -%} @@ -58,8 +42,7 @@ {%- endif -%} {%- endif -%} - {#-- Inject dune.public into extra_properties at CREATE time (prod only) --#} - {%- set dune_public = config.get('dune_public') -%} + {%- set dune_public = config.get('meta', {}).get('dune', {}).get('public') -%} {%- if dune_public is not none and target.name == 'prod' -%} {%- set visibility_value = 'true' if dune_public else 'false' -%} {%- set extra_props_sql = "map_from_entries(ARRAY[ROW('dune.public', '" ~ visibility_value ~ "')])" -%} diff --git a/macros/dune_dbt_overrides/set_table_visibility.sql b/macros/dune_dbt_overrides/set_table_visibility.sql index 4137fc0..b8e103e 100644 --- a/macros/dune_dbt_overrides/set_table_visibility.sql +++ b/macros/dune_dbt_overrides/set_table_visibility.sql @@ -7,30 +7,12 @@ ]) {%- endmacro -%} -{# - set_table_visibility: post-hook that sets dune.public on incremental (non-full-refresh) runs. - - For table materializations and incremental full-refreshes, extra_properties is set - at CREATE TABLE time via the overridden properties() macro. This hook handles the - incremental case where no CREATE is issued (INSERT/MERGE only). - - Configure per model via config(): - , dune_public = true -- make table publicly accessible on Dune (visible and queryable by anyone) - , dune_public = false -- (default) keep table private - - Or set for an entire folder in dbt_project.yml: - models: - my_project: - public_models: - +dune_public: true - - Only runs in prod. Views are not supported. -#} +{# post-hook that keeps dune.public in sync on incremental (non-full-refresh) runs where no CREATE TABLE is issued #} {% macro set_table_visibility(this, materialization) %} {%- if target.name == 'prod' and materialization == 'incremental' and not flags.FULL_REFRESH -%} - {%- set dune_public = config.get('dune_public', false) -%} + {%- 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) }} diff --git a/models/templates/dbt_template_append_incremental_model.sql b/models/templates/dbt_template_append_incremental_model.sql index 15e580a..13bae25 100644 --- a/models/templates/dbt_template_append_incremental_model.sql +++ b/models/templates/dbt_template_append_incremental_model.sql @@ -9,7 +9,7 @@ alias = 'dbt_template_append_incremental_model' , materialized = 'incremental' , incremental_strategy = 'append' - , dune_public = false + , meta = {"dune": {"public": false}} , properties = { "partitioned_by": "ARRAY['block_date']" } diff --git a/models/templates/dbt_template_delete_insert_incremental_model.sql b/models/templates/dbt_template_delete_insert_incremental_model.sql index 7877dfd..0952f73 100644 --- a/models/templates/dbt_template_delete_insert_incremental_model.sql +++ b/models/templates/dbt_template_delete_insert_incremental_model.sql @@ -4,7 +4,7 @@ , incremental_strategy = 'delete+insert' , unique_key = ['block_number', 'block_date'] , incremental_predicates = ["block_date >= now() - interval '1' day"] - , dune_public = false + , meta = {"dune": {"public": false}} , properties = { "partitioned_by": "ARRAY['block_date']" } diff --git a/models/templates/dbt_template_merge_incremental_model.sql b/models/templates/dbt_template_merge_incremental_model.sql index ae91441..f672e51 100644 --- a/models/templates/dbt_template_merge_incremental_model.sql +++ b/models/templates/dbt_template_merge_incremental_model.sql @@ -4,7 +4,7 @@ , incremental_strategy = 'merge' , unique_key = ['block_number', 'block_date'] , incremental_predicates = ["DBT_INTERNAL_DEST.block_date >= now() - interval '1' day"] - , dune_public = false + , meta = {"dune": {"public": false}} , properties = { "partitioned_by": "ARRAY['block_date']" } diff --git a/models/templates/dbt_template_table_model.sql b/models/templates/dbt_template_table_model.sql index 2f8938e..1f4446c 100644 --- a/models/templates/dbt_template_table_model.sql +++ b/models/templates/dbt_template_table_model.sql @@ -1,7 +1,7 @@ {{ config( alias = 'dbt_template_table_model' , materialized = 'table' - , dune_public = false + , meta = {"dune": {"public": false}} , properties = { "partitioned_by": "ARRAY['block_date']" } From 465f7cee6cdd295a6c0c51edfa57bc17d8f668aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Monteiro?= Date: Wed, 18 Mar 2026 12:37:12 +0000 Subject: [PATCH 5/7] format meta config block consistently with properties --- README.md | 6 +++++- models/templates/dbt_template_append_incremental_model.sql | 6 +++++- .../dbt_template_delete_insert_incremental_model.sql | 6 +++++- models/templates/dbt_template_merge_incremental_model.sql | 6 +++++- models/templates/dbt_template_table_model.sql | 6 +++++- 5 files changed, 25 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 24f3a94..55cb568 100644 --- a/README.md +++ b/README.md @@ -160,7 +160,11 @@ By default, all tables are **private** — only your team can query them. To mak {{ config( alias = 'my_model' , materialized = 'table' - , meta = {"dune": {"public": true}} + , meta = { + "dune": { + "public": true + } + } , properties = { "partitioned_by": "ARRAY['block_date']" } diff --git a/models/templates/dbt_template_append_incremental_model.sql b/models/templates/dbt_template_append_incremental_model.sql index 13bae25..7b865e9 100644 --- a/models/templates/dbt_template_append_incremental_model.sql +++ b/models/templates/dbt_template_append_incremental_model.sql @@ -9,7 +9,11 @@ alias = 'dbt_template_append_incremental_model' , materialized = 'incremental' , incremental_strategy = 'append' - , meta = {"dune": {"public": false}} + , meta = { + "dune": { + "public": false + } + } , properties = { "partitioned_by": "ARRAY['block_date']" } diff --git a/models/templates/dbt_template_delete_insert_incremental_model.sql b/models/templates/dbt_template_delete_insert_incremental_model.sql index 0952f73..7b727d9 100644 --- a/models/templates/dbt_template_delete_insert_incremental_model.sql +++ b/models/templates/dbt_template_delete_insert_incremental_model.sql @@ -4,7 +4,11 @@ , incremental_strategy = 'delete+insert' , unique_key = ['block_number', 'block_date'] , incremental_predicates = ["block_date >= now() - interval '1' day"] - , meta = {"dune": {"public": false}} + , meta = { + "dune": { + "public": false + } + } , properties = { "partitioned_by": "ARRAY['block_date']" } diff --git a/models/templates/dbt_template_merge_incremental_model.sql b/models/templates/dbt_template_merge_incremental_model.sql index f672e51..daa48bc 100644 --- a/models/templates/dbt_template_merge_incremental_model.sql +++ b/models/templates/dbt_template_merge_incremental_model.sql @@ -4,7 +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}} + , meta = { + "dune": { + "public": false + } + } , properties = { "partitioned_by": "ARRAY['block_date']" } diff --git a/models/templates/dbt_template_table_model.sql b/models/templates/dbt_template_table_model.sql index 1f4446c..68561d2 100644 --- a/models/templates/dbt_template_table_model.sql +++ b/models/templates/dbt_template_table_model.sql @@ -1,7 +1,11 @@ {{ config( alias = 'dbt_template_table_model' , materialized = 'table' - , meta = {"dune": {"public": false}} + , meta = { + "dune": { + "public": false + } + } , properties = { "partitioned_by": "ARRAY['block_date']" } From 60aca129ab575791b6ca9d778ce9d4902e4c5365 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Monteiro?= Date: Wed, 18 Mar 2026 12:39:10 +0000 Subject: [PATCH 6/7] clarify view visibility limitation --- README.md | 2 +- macros/dune_dbt_overrides/set_table_visibility.sql | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 55cb568..aad5e04 100644 --- a/README.md +++ b/README.md @@ -182,7 +182,7 @@ models: public: true ``` -Visibility is only applied in the `prod` target and has no effect in development. Views are not supported. +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 diff --git a/macros/dune_dbt_overrides/set_table_visibility.sql b/macros/dune_dbt_overrides/set_table_visibility.sql index b8e103e..b42d0c2 100644 --- a/macros/dune_dbt_overrides/set_table_visibility.sql +++ b/macros/dune_dbt_overrides/set_table_visibility.sql @@ -7,7 +7,7 @@ ]) {%- endmacro -%} -{# post-hook that keeps dune.public in sync on incremental (non-full-refresh) runs where no CREATE TABLE is issued #} +{# post-hook that keeps dune.public in sync on incremental (non-full-refresh) runs where no CREATE TABLE is issued. Setting visibility for views is not supported at this time. #} {% macro set_table_visibility(this, materialization) %} {%- if target.name == 'prod' and materialization == 'incremental' From 11449b3f7abb8c06c3c1f0b30e38883383e2c1ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Monteiro?= Date: Wed, 18 Mar 2026 13:46:15 +0000 Subject: [PATCH 7/7] remove properties() override, use alter table for all visibility changes --- macros/dune_dbt_overrides/properties.sql | 64 ------------------- .../set_table_visibility.sql | 5 +- 2 files changed, 2 insertions(+), 67 deletions(-) delete mode 100644 macros/dune_dbt_overrides/properties.sql diff --git a/macros/dune_dbt_overrides/properties.sql b/macros/dune_dbt_overrides/properties.sql deleted file mode 100644 index a64b0ab..0000000 --- a/macros/dune_dbt_overrides/properties.sql +++ /dev/null @@ -1,64 +0,0 @@ -{# Override of the dbt-trino adapter's properties() macro to inject dune.public into extra_properties at CREATE TABLE time. #} -{% macro properties(temporary=False) %} - {%- set _properties = config.get('properties') -%} - {%- set table_format = config.get('table_format') -%} - {%- set file_format = config.get('file_format') -%} - - {%- if file_format -%} - {%- if _properties -%} - {%- if _properties.format -%} - {% set msg %} - You can specify either 'file_format' or 'properties.format' configurations, but not both. - {% endset %} - {% do exceptions.raise_compiler_error(msg) %} - {%- else -%} - {%- do _properties.update({'format': "'" ~ file_format ~ "'"}) -%} - {%- endif -%} - {%- else -%} - {%- set _properties = {'format': "'" ~ file_format ~ "'"} -%} - {%- endif -%} - {%- endif -%} - - {%- if table_format -%} - {%- if _properties -%} - {%- if _properties.type -%} - {% set msg %} - You can specify either 'table_format' or 'properties.type' configurations, but not both. - {% endset %} - {% do exceptions.raise_compiler_error(msg) %} - {%- else -%} - {%- do _properties.update({'type': "'" ~ table_format ~ "'"}) -%} - {%- endif -%} - {%- else -%} - {%- set _properties = {'type': "'" ~ table_format ~ "'"} -%} - {%- endif -%} - {%- endif -%} - - {%- if temporary -%} - {%- if _properties -%} - {%- if _properties.location -%} - {%- do _properties.update({'location': _properties.location[:-1] ~ "__dbt_tmp'"}) -%} - {%- endif -%} - {%- endif -%} - {%- endif -%} - - {%- set dune_public = config.get('meta', {}).get('dune', {}).get('public') -%} - {%- if dune_public is not none and target.name == 'prod' -%} - {%- set visibility_value = 'true' if dune_public else 'false' -%} - {%- set extra_props_sql = "map_from_entries(ARRAY[ROW('dune.public', '" ~ visibility_value ~ "')])" -%} - {%- if _properties is none -%} - {%- set _properties = {'extra_properties': extra_props_sql} -%} - {%- else -%} - {%- do _properties.update({'extra_properties': extra_props_sql}) -%} - {%- endif -%} - {%- endif -%} - - {%- if _properties is not none -%} - WITH ( - {%- for key, value in _properties.items() -%} - {{ key }} = {{ value }} - {%- if not loop.last -%}{{ ',\n ' }}{%- endif -%} - {%- endfor -%} - ) - {%- endif -%} -{%- endmacro -%} diff --git a/macros/dune_dbt_overrides/set_table_visibility.sql b/macros/dune_dbt_overrides/set_table_visibility.sql index b42d0c2..b6fc8d2 100644 --- a/macros/dune_dbt_overrides/set_table_visibility.sql +++ b/macros/dune_dbt_overrides/set_table_visibility.sql @@ -7,11 +7,10 @@ ]) {%- endmacro -%} -{# post-hook that keeps dune.public in sync on incremental (non-full-refresh) runs where no CREATE TABLE is issued. Setting visibility for views is not supported at this time. #} +{# 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 == 'incremental' - and not flags.FULL_REFRESH -%} + 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 }}