Skip to content

Commit

Permalink
Added Django 4.2 support
Browse files Browse the repository at this point in the history
  • Loading branch information
gurustacks committed Nov 30, 2023
1 parent 765afdb commit d3b02d7
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 2023-11-30 (5.17.19)

* Added support for Django versions > 3.2
* Added GRANT create, usage in _is_valid_sql function
* Use django.db.models.JSONField instead of django.contrib.postgres.fields.jsonb.JSONField

# 2023-11-24 (5.17.18)

* Bugfix: Update nested table when nested field name has underscore.
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = amsterdam-schema-tools
version = 5.17.18
version = 5.17.19
url = https://github.com/amsterdam/schema-tools
license = Mozilla Public 2.0
author = Team Data Diensten, van het Dataplatform onder de Directie Digitale Voorzieningen (Gemeente Amsterdam)
Expand Down
14 changes: 14 additions & 0 deletions src/schematools/contrib/django/management/commands/create_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ def _is_valid_sql(view_sql: str, view_name: str, write_role_name: str) -> bool:
# Check if write role exists and create if it does not
_create_role_if_not_exists(cursor, write_role_name)

cursor.execute(
sql.SQL("GRANT create,usage on schema public TO {write_role_name}").format(
write_role_name=sql.Identifier(write_role_name)
)
)

cursor.execute(
sql.SQL("SET ROLE {write_role_name}").format(
write_role_name=sql.Identifier(write_role_name)
Expand All @@ -39,6 +45,14 @@ def _is_valid_sql(view_sql: str, view_name: str, write_role_name: str) -> bool:
view_name=sql.Identifier(view_name)
)
)

# Remove create and usage from write role
cursor.execute(
sql.SQL("REVOKE create,usage on schema public FROM {write_role_name}").format(
write_role_name=sql.Identifier(write_role_name)
)
)

cursor.execute(view_sql)
transaction.savepoint_rollback(sid)
except Exception as e: # noqa: F841
Expand Down
4 changes: 2 additions & 2 deletions src/schematools/contrib/django/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Generated by Django 3.0.2 on 2020-01-23 11:13

import django.contrib.postgres.fields.jsonb
import django.db.models
from django.db import migrations, models


Expand Down Expand Up @@ -31,7 +31,7 @@ class Migration(migrations.Migration):
("enable_api", models.BooleanField(default=True)),
(
"schema_data",
django.contrib.postgres.fields.jsonb.JSONField(
django.db.models.JSONField(
verbose_name="Amsterdam Schema Contents"
),
),
Expand Down

0 comments on commit d3b02d7

Please sign in to comment.