-
-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* [#141] Support Microsoft SQL Server 17 and 19
- Loading branch information
Showing
63 changed files
with
578 additions
and
1,104 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
include README.md | ||
include *.txt | ||
include *.txt | ||
include river/sql/mssql/get_available_approvals.sql |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,5 +7,6 @@ Migration Guide | |
:maxdepth: 2 | ||
|
||
migration_2_to_3 | ||
migration_31_to_32 | ||
hooking | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
.. _migration_31_to_32: | ||
|
||
3.1.X to 3.2.X | ||
============== | ||
|
||
``django-river`` started to support **Microsoft SQL Server 17 and 19** after version 3.2.0 but the previous migrations didn't get along with it. We needed to reset all | ||
the migrations to have fresh start. If you have already migrated to version `3.1.X` all you need to do is to pull your migrations back to the beginning. | ||
|
||
|
||
.. code:: bash | ||
python manage.py migrate --fake river zero | ||
python manage.py migrate --fake river |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,10 @@ | ||
__author__ = 'ahmetdal' | ||
|
||
|
||
#!/usr/bin/env python | ||
import os | ||
# !/usr/bin/env python | ||
import os | ||
import sys | ||
|
||
if __name__ == "__main__": | ||
if __name__ == "__main__": | ||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings.with_sqlite3") | ||
|
||
from django.core.management import execute_from_command_line | ||
|
||
execute_from_command_line(sys.argv) | ||
execute_from_command_line(sys.argv) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1 @@ | ||
__author__ = 'ahmetdal' | ||
|
||
default_app_config = 'river.apps.RiverApp' |
This file contains 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
This file contains 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
This file contains 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
Empty file.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import os | ||
from os.path import dirname | ||
|
||
import six | ||
from django.db import connection | ||
from django.contrib.auth.models import Permission | ||
|
||
from river.driver.river_driver import RiverDriver | ||
from river.models import TransitionApproval | ||
|
||
|
||
class MsSqlDriver(RiverDriver): | ||
|
||
def __init__(self, *args, **kwargs): | ||
super(MsSqlDriver, self).__init__(*args, **kwargs) | ||
with open(os.path.join(dirname(dirname(__file__)), "sql", "mssql", "get_available_approvals.sql")) as f: | ||
self.available_approvals_sql_template = f.read().replace("river.dbo.", "") | ||
self.cursor = connection.cursor() | ||
|
||
def get_available_approvals(self, as_user): | ||
with connection.cursor() as cursor: | ||
cursor.execute(self._clean_sql % { | ||
"workflow_id": self.workflow.pk, | ||
"transactioner_id": as_user.pk, | ||
"field_name": self.field_name, | ||
"permission_ids": self._permission_ids_str(as_user), | ||
"group_ids": self._group_ids_str(as_user), | ||
"workflow_object_table": self.wokflow_object_class._meta.db_table, | ||
"object_pk_name": self.wokflow_object_class._meta.pk.name | ||
}) | ||
|
||
return TransitionApproval.objects.filter(pk__in=[row[0] for row in cursor.fetchall()]) | ||
|
||
@staticmethod | ||
def _permission_ids_str(as_user): | ||
permissions = as_user.user_permissions.all() | Permission.objects.filter(group__user=as_user) | ||
return ",".join(list(six.moves.map(str, permissions.values_list("pk", flat=True))) or ["-1"]) | ||
|
||
@staticmethod | ||
def _group_ids_str(as_user): | ||
return ",".join(list(six.moves.map(str, as_user.groups.all().values_list("pk", flat=True))) or ["-1"]) | ||
|
||
@property | ||
def _clean_sql(self): | ||
return self.available_approvals_sql_template \ | ||
.replace("'%(workflow_id)s'", "%(workflow_id)s") \ | ||
.replace("'%(transactioner_id)s'", "%(transactioner_id)s") \ | ||
.replace("'%(field_name)s'", "%(field_name)s") \ | ||
.replace("'%(permission_ids)s'", "%(permission_ids)s") \ | ||
.replace("'%(group_ids)s'", "%(group_ids)s") \ | ||
.replace("'%(workflow_object_table)s'", "%(workflow_object_table)s") \ | ||
.replace("'%(object_pk_name)s'", "%(object_pk_name)s") |
Oops, something went wrong.