Skip to content

Commit

Permalink
remove python merge and reduce queries to lookup privs
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-dflippo committed Mar 21, 2024
1 parent be416ab commit 375b066
Showing 1 changed file with 2 additions and 15 deletions.
17 changes: 2 additions & 15 deletions macros/snowflake__create_constraints.sql
Original file line number Diff line number Diff line change
Expand Up @@ -272,23 +272,10 @@ SHOW IMPORTED KEYS IN TABLE {{ table_relation }}
upper(tp.table_name) as "table_name",
tp.privilege_type as "privilege_type"
from {{ table_relation.database }}.information_schema.table_privileges tp
where is_role_in_session(tp.grantee)
where (is_role_in_session(tp.grantee) or is_database_role_in_session(tp.grantee))
and tp.privilege_type in ('OWNERSHIP', 'REFERENCES')
{%- endset -%}
{%- set role_privilege_list = run_query(lookup_query) -%}

{%- set lookup_query -%}
select distinct
upper(tp.table_schema) as "table_schema",
upper(tp.table_name) as "table_name",
tp.privilege_type as "privilege_type"
from {{ table_relation.database }}.information_schema.table_privileges tp
where is_database_role_in_session(tp.grantee)
and tp.privilege_type in ('OWNERSHIP', 'REFERENCES')
{%- endset -%}
{%- set db_role_privilege_list = run_query(lookup_query) -%}

{%- set privilege_list = role_privilege_list.merge([role_privilege_list, db_role_privilege_list]).distinct() -%}
{%- set privilege_list = run_query(lookup_query) -%}
{%- do lookup_cache.table_privileges.update({ table_relation.database: privilege_list }) -%}
{%- endif -%}

Expand Down

0 comments on commit 375b066

Please sign in to comment.