OpenSlides/server/openslides/utils/postgres.py
FinnStutzenstein 2bcab5d098
Repository restructure
- moved all server related things into the folder `server`, so this
configuration is parallel to the client.
- All main "services" are now folders in the root directory
- Added Dockerfiles to each service (currently server and client)
- Added a docker compose configuration to start everything together.
Currently there are heavy dependencies into https://github.com/OpenSlides/openslides-docker-compose
- Resturctured the .gitignore. If someone needs something excluded,
please add it to the right section.
- Added initial build setup with Docker and docker-compose.
- removed setup.py. We won't deliver OpenSlides via pip anymore.
2020-08-21 08:11:13 +02:00

18 lines
726 B
Python

from django.db import connection
def restart_id_sequence(table_name: str) -> None:
"""
This function resets the id sequence from the given table (the current auto
increment value for the id field) to the max_id+1. This is needed, when manually
inserting object id, because Postgresql does not update the id sequence in this case.
"""
if connection.vendor == "postgresql":
with connection.cursor() as cursor:
cursor.execute(f"SELECT max(id) + 1 as max FROM {table_name};")
max_id = cursor.fetchone()[0]
if max_id is not None:
cursor.execute(
f"ALTER SEQUENCE {table_name}_id_seq RESTART WITH {max_id};"
)