Merge pull request #4556 from FinnStutzenstein/postgresAuthGroupSequence
Restart the AuthGroup id sequence on postgres
This commit is contained in:
commit
58e0e4155e
@ -1,5 +1,6 @@
|
|||||||
from django.apps import apps
|
from django.apps import apps
|
||||||
from django.contrib.auth.models import Permission
|
from django.contrib.auth.models import Permission
|
||||||
|
from django.db import connection
|
||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
|
|
||||||
from ..utils.auth import GROUP_ADMIN_PK, GROUP_DEFAULT_PK
|
from ..utils.auth import GROUP_ADMIN_PK, GROUP_DEFAULT_PK
|
||||||
@ -185,3 +186,12 @@ def create_builtin_groups_and_admin(**kwargs):
|
|||||||
# After each group was created, the permissions (many to many fields) where
|
# After each group was created, the permissions (many to many fields) where
|
||||||
# added to the group. But we do not have to update the cache by calling
|
# added to the group. But we do not have to update the cache by calling
|
||||||
# inform_changed_data() because the cache is updated on server start.
|
# inform_changed_data() because the cache is updated on server start.
|
||||||
|
|
||||||
|
# For postgres, the id sequence (the current auto increment value for the id field)
|
||||||
|
# needs to be refreshed after inserting the groups per id, because postgres does not
|
||||||
|
# increment the sequence then.
|
||||||
|
if connection.vendor == "postgresql":
|
||||||
|
with connection.cursor() as cursor:
|
||||||
|
cursor.execute("SELECT max(id) + 1 as max FROM auth_group;")
|
||||||
|
max_id = cursor.fetchone()[0]
|
||||||
|
cursor.execute(f"ALTER SEQUENCE auth_group_id_seq RESTART WITH {max_id};")
|
||||||
|
Loading…
Reference in New Issue
Block a user