Skip to content
Open
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
1 change: 1 addition & 0 deletions misc/dbt-materialize/dbt/adapters/materialize/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ class MaterializeConfig(AdapterConfig):
cluster: Optional[str] = None
refresh_interval: Optional[MaterializeRefreshIntervalConfig] = None
retain_history: Optional[str] = None
owner: Optional[str] = None


class MaterializeAdapter(PostgresAdapter, SQLAdapter):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,26 @@
{% endmacro %}

-- In the dbt-adapter we extend the Relation class to include sinks and indexes
{% macro materialize__alter_owner(relation) %}
{%- set owner = config.get('owner') -%}
{% if owner %}
{% set alter_stmt %}
{% if relation.type == 'view' %}
alter view {{ relation }} owner to {{ owner }}
{% elif relation.is_materialized_view %}
alter materialized view {{ relation }} owner to {{ owner }}
{% elif relation.type == 'sink' %}
alter sink {{ relation }} owner to {{ owner }}
{% elif relation.type == 'source' %}
alter source {{ relation }} owner to {{ owner }}
{% elif relation.type == 'table' %}
alter table {{ relation }} owner to {{ owner }}
{% endif %}
{% endset %}
{% do run_query(alter_stmt) %}
{% endif %}
{% endmacro %}

{% macro materialize__list_relations_without_caching(schema_relation) %}
{% call statement('list_relations_without_caching', fetch_result=True) -%}
select
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@

{{ create_indexes(target_relation) }}
{% do persist_docs(target_relation, model) %}
{% do materialize__alter_owner(target_relation) %}

{{ run_hooks(post_hooks, inside_transaction=False) }}
{{ run_hooks(post_hooks, inside_transaction=True) }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
{% set target_relation = this.incorporate(type='table') %}

{% do persist_docs(target_relation, model) %}
{% do materialize__alter_owner(target_relation) %}

{% if full_refresh_mode or not exists_as_table %}
{% do create_indexes(target_relation) %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
{%- endcall %}

{% do persist_docs(target_relation, model) %}
{% do materialize__alter_owner(target_relation) %}

{{ run_hooks(post_hooks, inside_transaction=False) }}
{{ run_hooks(post_hooks, inside_transaction=True) }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@

{{ create_indexes(target_relation) }}
{% do persist_docs(target_relation, model) %}
{% do materialize__alter_owner(target_relation) %}

{{ run_hooks(post_hooks, inside_transaction=False) }}
{{ run_hooks(post_hooks, inside_transaction=True) }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@

{{ create_indexes(target_relation) }}
{% do persist_docs(target_relation, model) %}
{% do materialize__alter_owner(target_relation) %}

{{ run_hooks(post_hooks, inside_transaction=False) }}
{{ run_hooks(post_hooks, inside_transaction=True) }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@

{{ create_indexes(target_relation) }}
{% do persist_docs(target_relation, model) %}
{% do materialize__alter_owner(target_relation) %}

{{ run_hooks(post_hooks, inside_transaction=False) }}
{{ run_hooks(post_hooks, inside_transaction=True) }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@

{{ create_indexes(target_relation) }}
{% do persist_docs(target_relation, model) %}
{% do materialize__alter_owner(target_relation) %}

{{ run_hooks(post_hooks, inside_transaction=False) }}
{{ run_hooks(post_hooks, inside_transaction=True) }}
Expand Down
Loading