You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Skip grant statements for non-existent object types and already-granted privileges (v1.0.9) (#37)
* Skip grant statements for non-existent object types and already-granted privileges
Grant macros now detect which object types exist in each schema before
issuing GRANT ON ALL statements. Schemas without a given object type
(e.g. no streams, no stages) no longer receive unnecessary grants.
Also checks existing privileges per role and skips grants already applied.
Affects: grant_schema_read_specific, grant_schema_monitor_specific,
grant_schema_operate_specific. Adds _grants_get_schema_object_types helper.
Bumped version to 1.0.9.
.... Generated with [Cortex Code](https://docs.snowflake.com/en/user-guide/cortex-code/cortex-code)
Co-Authored-By: Cortex Code <noreply@snowflake.com>
* Use bulk object type detection to avoid per-schema SHOW queries
Replaced per-schema SHOW STREAMS/STAGES/PIPES/TASKS with a single
bulk query via _grants_get_all_schema_object_types() that runs just
2 queries total (information_schema.tables + object_privileges).
Also replaced individual SHOW commands in _grants_get_schema_object_types
with information_schema.object_privileges lookup (2 queries vs 5).
.... Generated with [Cortex Code](https://docs.snowflake.com/en/user-guide/cortex-code/cortex-code)
Co-Authored-By: Cortex Code <noreply@snowflake.com>
* Count-based coverage check and bulk view lookup for shares
Replaced naive privilege-exists check with count-based full coverage
check (_grants_get_schema_full_coverage): compares granted object count
vs total object count per type. Only re-grants when a new object was
added that doesn't yet have the privilege.
Replaced per-schema SHOW VIEWS in grant_internal_share_read with a
single bulk query against information_schema.tables for all views.
.... Generated with [Cortex Code](https://docs.snowflake.com/en/user-guide/cortex-code/cortex-code)
Co-Authored-By: Cortex Code <noreply@snowflake.com>
* Update changelog for v1.0.9 with full performance improvements
.... Generated with [Cortex Code](https://docs.snowflake.com/en/user-guide/cortex-code/cortex-code)
Co-Authored-By: Cortex Code <noreply@snowflake.com>
* Fix coverage query: resolve object_type mismatch for views
Snowflake stores views as object_type='TABLE' in object_privileges
but information_schema.tables categorizes them as table_type='VIEW'.
The coverage query now joins granted_counts with information_schema.tables
to resolve the actual object type, ensuring views are correctly matched
and their grants are detected as fully covered.
.... Generated with [Cortex Code](https://docs.snowflake.com/en/user-guide/cortex-code/cortex-code)
Co-Authored-By: Cortex Code <noreply@snowflake.com>
* Bulk coverage check: single query for all schemas instead of per-schema
The per-schema _grants_get_schema_full_coverage query took ~14s each,
totalling ~9 minutes for 38 schemas. Replaced with bulk
_grants_get_all_schema_full_coverage that runs a single database-wide
query and returns results keyed by schema.
grant_schema_read_specific now runs 3 bulk queries upfront (object types,
coverage, roles) then iterates schemas with pure dict lookups.
Only SHOW GRANTS ON SCHEMA remains per-schema (~0.3s each).
.... Generated with [Cortex Code](https://docs.snowflake.com/en/user-guide/cortex-code/cortex-code)
Co-Authored-By: Cortex Code <noreply@snowflake.com>
* Optimize grant_internal_share_read: dict lookups and pre-built schema set
Converted existing_share_objects from list (O(n) scans) to dict (O(1) lookups).
Pre-built schemas_with_table_grants during DESC SHARE parsing to eliminate
the per-schema startswith loop. Added logging for executed statements
to aid debugging share grant timing.
.... Generated with [Cortex Code](https://docs.snowflake.com/en/user-guide/cortex-code/cortex-code)
Co-Authored-By: Cortex Code <noreply@snowflake.com>
* Guard run_query calls with execute check to prevent parse-time failures
All helper macros now return early when not in execute phase,
preventing run_query from being called during dbt compile/parse/docs.
Addresses sourcery-ai review comment on PR #37.
.... Generated with [Cortex Code](https://docs.snowflake.com/en/user-guide/cortex-code/cortex-code)
Co-Authored-By: Cortex Code <noreply@snowflake.com>
---------
Co-authored-by: Cortex Code <noreply@snowflake.com>
Copy file name to clipboardExpand all lines: CHANGELOG.md
+11Lines changed: 11 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,17 @@
1
1
# Data Engineers Snowflake DataOps Utils Project Changelog
2
2
This file contains the changelog for the Data Engineers Snowflake DataOps Utils project, detailing updates, fixes, and enhancements made to the project over time.
3
3
4
+
## v1.0.9 - 2026-06-26 - Conditional Grant Statements & Performance
5
+
6
+
### Changed
7
+
-**Performance**: `grant_schema_read_specific` now detects which object types exist in each schema and only issues grant statements for types that are present. Schemas with no objects of a given type no longer receive unnecessary `GRANT ... ON ALL` statements.
8
+
-**Performance**: `grant_schema_read_specific` uses count-based full coverage checking — compares the number of objects with the privilege granted vs total objects of that type. Only re-issues `GRANT ON ALL` when a new object was added that doesn't yet have the privilege. On steady-state runs (no new objects), zero grant statements are executed.
9
+
-**Performance**: `grant_schema_monitor_specific` and `grant_schema_operate_specific` now skip schemas that have no pipes or tasks, and only issue grants for the specific object types that exist.
10
+
-**Performance**: Object type detection uses bulk database-wide queries (`_grants_get_all_schema_object_types`) — 2 queries total instead of per-schema SHOW commands.
11
+
-**Performance**: `grant_internal_share_read` replaced per-schema `SHOW VIEWS` with a single bulk `information_schema.tables` query for all views across the database.
Copy file name to clipboardExpand all lines: README.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
3
3
A macro-only [dbt](https://github.com/dbt-labs/dbt) package for Snowflake DataOps. Provides utilities for object lifecycle management, RBAC grant orchestration, dimensional modelling helpers, tagging, shares, and more.
0 commit comments