Skip to content

Commit c329b9e

Browse files
authored
Merge pull request #10 from DanCardin/dc/define-more-grants
2 parents b9f1cc9 + d4be892 commit c329b9e

3 files changed

Lines changed: 20 additions & 4 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "sqlalchemy-declarative-extensions"
3-
version = "0.3.0"
3+
version = "0.3.1"
44
description = "Library to declare additional kinds of objects not natively supported by SqlAlchemy/Alembic."
55

66
authors = ["Dan Cardin <ddcardin@gmail.com>"]

src/sqlalchemy_declarative_extensions/grant/compare.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,12 @@ def compare_object_grants(
100100
):
101101
result: list[Operation] = []
102102

103-
expected_grants = [g for g in grants if isinstance(g, GrantStatement)]
103+
expected_grants = [
104+
sub_g
105+
for grant in grants
106+
for sub_g in grant.explode()
107+
if isinstance(sub_g, GrantStatement)
108+
]
104109

105110
existing_tables = get_objects(connection)
106111
existing_tables_by_schema = {

tests/grant/test_grant_schema.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,13 @@
2121
class Base(Base_):
2222
__abstract__ = True
2323

24-
schemas = Schemas().are("bar")
24+
schemas = Schemas().are("bar", "baz")
2525
roles = Roles(ignore_unspecified=True).are("access", "noaccess")
2626
grants = Grants().are(
2727
DefaultGrant.on_tables_in_schema("bar").grant("select", to="access"),
28+
DefaultGrant.on_tables_in_schema("baz").grant("select", to="access"),
2829
DefaultGrant.on_tables_in_schema("bar").grant("select", to="noaccess"),
29-
Grant.new("usage", to="access").on_schemas("bar"),
30+
Grant.new("usage", to="access").on_schemas("bar", "baz"),
3031
)
3132

3233

@@ -37,6 +38,13 @@ class Bar(Base):
3738
id = Column(types.Integer(), autoincrement=True, primary_key=True)
3839

3940

41+
class Baz(Base):
42+
__tablename__ = "baz"
43+
__table_args__ = {"schema": "baz"}
44+
45+
id = Column(types.Integer(), autoincrement=True, primary_key=True)
46+
47+
4048
pg = create_postgres_fixture(scope="function", engine_kwargs={"echo": True})
4149

4250

@@ -61,3 +69,6 @@ def test_createall_grant(pg):
6169
# There should be no diffs detected after running `create_all`
6270
diff = compare_grants(pg, grants, roles)
6371
assert len(diff) == 0
72+
73+
# Ensure we're exploding common grants.
74+
pg.execute(text("SET ROLE access; SELECT * from baz.baz"))

0 commit comments

Comments
 (0)