feat(experimental): add official support for model grants#5275
Merged
newtonapple merged 42 commits intomainfrom Oct 3, 2025
Merged
feat(experimental): add official support for model grants#5275newtonapple merged 42 commits intomainfrom
newtonapple merged 42 commits intomainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR introduces experimental support for grants configuration, allowing users to specify database permissions for SQLMesh models. The feature includes grants parsing, validation, and application across different evaluation strategies.
- Adds grants configuration support to models with validation for compatible model types
- Implements grants application logic in snapshot evaluators for physical and virtual layers
- Provides PostgreSQL engine adapter implementation with grants management functionality
Reviewed Changes
Copilot reviewed 19 out of 20 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/dbt/test_model.py | Tests dbt model grants conversion to SQLMesh format and validation |
| tests/core/test_snapshot_evaluator.py | Tests grants application in snapshot evaluation strategies |
| tests/core/test_model.py | Tests model grants parsing, validation, and rendering functionality |
| tests/core/engine_adapter/test_postgres.py | Unit tests for PostgreSQL grants operations (apply, revoke, sync) |
| tests/core/engine_adapter/test_base_postgres.py | Tests PostgreSQL current schema retrieval functionality |
| tests/core/engine_adapter/test_base.py | Tests base engine adapter grants configuration diffing logic |
| tests/core/engine_adapter/integration/test_integration_postgres.py | Integration tests for PostgreSQL grants with real database operations |
| sqlmesh/dbt/model.py | Adds grants field to SQLMesh model conversion |
| sqlmesh/dbt/basemodel.py | Updates grants field validation to handle optional grants |
| sqlmesh/core/snapshot/evaluator.py | Implements grants application in evaluation strategies |
| sqlmesh/core/model/meta.py | Defines grants target layer enum and grants property parsing |
| sqlmesh/core/model/definition.py | Adds grants to model metadata hash and table type determination |
| sqlmesh/core/model/common.py | Registers grants field for property parsing |
| sqlmesh/core/engine_adapter/postgres.py | Implements PostgreSQL-specific grants operations |
| sqlmesh/core/engine_adapter/base_postgres.py | Adds current schema retrieval for grants queries |
| sqlmesh/core/engine_adapter/base.py | Defines base grants interface and configuration diffing |
| sqlmesh/core/engine_adapter/_typing.py | Adds GrantsConfig type definition |
| sqlmesh/core/_typing.py | Minor formatting change |
| pyproject.toml | Updates sqlglot dependency version |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
1019d57 to
ada2040
Compare
izeigerman
reviewed
Sep 2, 2025
izeigerman
reviewed
Sep 2, 2025
izeigerman
reviewed
Sep 2, 2025
izeigerman
reviewed
Sep 2, 2025
izeigerman
reviewed
Sep 2, 2025
izeigerman
reviewed
Sep 2, 2025
izeigerman
reviewed
Sep 2, 2025
izeigerman
reviewed
Sep 2, 2025
izeigerman
reviewed
Sep 2, 2025
8a93de3 to
ef2ca9b
Compare
izeigerman
reviewed
Sep 9, 2025
54ca124 to
a7e72f5
Compare
eakmanrq
reviewed
Sep 16, 2025
653e987 to
9da034d
Compare
eakmanrq
reviewed
Sep 18, 2025
2905b8e to
391ede2
Compare
Physical grants are applied in migration when there are metadata only changes.
since seed models don't support migration
Co-authored-by: eakmanrq <6326532+eakmanrq@users.noreply.github.com>
actual materialized views
for grants / revoke statements are optional
This reverts commit 357b0f5.
63746ab to
28e6156
Compare
Contributor
Author
@izeigerman I think we can |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Native grants for SQLMesh models
SQLMesh now supports configuring model-level grants directly in model definitions. Use the new
grantsandgrants_target_layerproperties to assign privileges to specific roles.grants: maps each privilege to the list of grantees.grants_target_layer: selects the data layer object that receives the grant (virtualdefault view,physicaltable, orall).This PR comes with grants support for the following engine adapters:
Model configuration example
MODEL ( name prod.user_ids, kind FULL, grants ( 'select' = ['readonly_user', 'dashboard_user'] ), grants_target_layer virtual, ); SELECT 1 AS id;See
tests/core/test_model.pyfor additional scenarios.Fixes #569.