forked from OpenSlides/openslides-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_schema.py
More file actions
38 lines (33 loc) · 1.09 KB
/
create_schema.py
File metadata and controls
38 lines (33 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from psycopg import Connection, rows, sql
from openslides_backend.services.postgresql.create_schema import (
create_db,
create_schema,
)
from openslides_backend.services.postgresql.db_connection_handling import (
env,
get_unpooled_db_connection,
)
from openslides_backend.shared.exceptions import DatabaseException
def main() -> None:
connection: Connection[rows.DictRow]
try:
connection = get_unpooled_db_connection(env.DATABASE_NAME, False)
except DatabaseException:
create_db()
connection = get_unpooled_db_connection(env.DATABASE_NAME, False)
with connection:
with connection.cursor() as cursor:
lock_int = 13371234564223
cursor.execute(
sql.SQL("SELECT pg_advisory_lock({lock_int});").format(
lock_int=lock_int
)
)
create_schema()
cursor.execute(
sql.SQL("SELECT pg_advisory_unlock({lock_int});").format(
lock_int=lock_int
)
)
if __name__ == "__main__":
main()