Skip to content

Commit d54af98

Browse files
twslmakseq
authored andcommitted
fix: Enable SQLite on Azure App Services (#1720)
Add connectection_created hook for WAL
1 parent 705d95b commit d54af98

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

label_studio/server.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
windows_dll_fix()
1919

2020
from django.core.management import call_command
21-
from django.db import IntegrityError
2221
from django.core.wsgi import get_wsgi_application
22+
from django.db import connections, DEFAULT_DB_ALIAS, IntegrityError
23+
from django.db.backends.signals import connection_created
2324
from django.db.migrations.executor import MigrationExecutor
24-
from django.db import connections, DEFAULT_DB_ALIAS
2525

2626
from label_studio.core.argparser import parse_input_args
2727
from label_studio.core.utils.params import get_env
@@ -45,6 +45,13 @@ def _app_run(host, port):
4545
call_command('runserver', '--noreload', http_socket)
4646

4747

48+
def _set_sqlite_fix_pragma(sender, connection, **kwargs):
49+
"""Enable integrity constraint with sqlite."""
50+
if connection.vendor == 'sqlite' and get_env('AZURE_MOUNT_FIX'):
51+
cursor = connection.cursor()
52+
cursor.execute('PRAGMA journal_mode=wal;')
53+
54+
4855
def is_database_synchronized(database):
4956
connection = connections[database]
5057
connection.prepare_database()
@@ -54,6 +61,7 @@ def is_database_synchronized(database):
5461

5562

5663
def _apply_database_migrations():
64+
connection_created.connect(_set_sqlite_fix_pragma)
5765
if not is_database_synchronized(DEFAULT_DB_ALIAS):
5866
print('Initializing database..')
5967
call_command('migrate', '--no-color', verbosity=0)

0 commit comments

Comments
 (0)