Skip to content
Open
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
22 changes: 22 additions & 0 deletions dbt-redshift/src/dbt/include/redshift/macros/apply_grants.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{%- macro quote_grantees(grantees) -%}
{%- set quoted_grantees = [] -%}
{%- for grantee in grantees -%}
{%- set grantee_parts = grantee.split() -%}
{%- if grantee_parts | length > 1 and grantee_parts[0].upper() in ('GROUP', 'ROLE') -%}
{%- set reserved_keyword = grantee_parts[0].upper() -%}
{%- set identifier = grantee_parts[1:] | join(' ') -%}
{%- do quoted_grantees.append(reserved_keyword ~ ' ' ~ adapter.quote(identifier)) -%}
{%- else -%}
{%- do quoted_grantees.append(adapter.quote(grantee)) -%}
{%- endif -%}
{% endfor -%}
{%- do return(quoted_grantees) -%}
{%- endmacro -%}

{%- macro redshift__get_revoke_sql(relation, privilege, grantees) -%}
revoke {{ privilege }} on {{ relation.type }} {{ relation }} from {{ quote_grantees(grantees) | join(', ') }}
{%- endmacro -%}

{%- macro redshift__get_grant_sql(relation, privilege, grantees) -%}
grant {{ privilege }} on {{ relation.type }} {{ relation }} to {{ quote_grantees(grantees) | join(', ') }}
{%- endmacro -%}
Loading