1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-11-11 12:46:49 +00:00

refactor(settings): SQLite's WAL mode is an init_command

The operations app set PRAGMA journal_mode=WAL from a connection_created
receiver because Django's SQLite OPTIONS had no init command; Django 5.1
added init_command, so the template sets it there and the receiver goes.
The mode is stored in the database file, so existing databases keep it.
This commit is contained in:
catborise 2026-11-06 11:01:51 +03:00
parent 2e287f3a7f
commit 2440c9eaf7
2 changed files with 3 additions and 14 deletions

View file

@ -1,21 +1,10 @@
from django.apps import AppConfig
from django.db.backends.signals import connection_created
def _sqlite_wal(sender, connection, **kwargs):
"""The worker and gunicorn write the same SQLite file: WAL lets readers
go on during a write. Django's SQLite OPTIONS have no init command."""
if connection.vendor == "sqlite":
with connection.cursor() as cursor:
cursor.execute("PRAGMA journal_mode=WAL")
class OperationsConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "operations"
def ready(self):
connection_created.connect(_sqlite_wal)
# every installed app's jobs.py registers its kinds
from django.utils.module_loading import autodiscover_modules