misc: use BEGIN IMMEDIATE to start transactions (#89314)
gitea/ants-hub/pipeline/head This commit looks good Details

This commit is contained in:
Benjamin Dauvergne 2024-04-09 15:41:42 +02:00
parent a8553f0c72
commit be65c4b929
4 changed files with 17 additions and 3 deletions

View File

@ -13,7 +13,7 @@ MEDIA_ROOT = os.path.join(VAR_DIR, 'media')
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'ENGINE': 'ants_hub.sqlite3_backend',
'NAME': os.path.join(VAR_DIR, 'db.sqlite3'),
}
}

2
debian/settings.py vendored
View File

@ -15,7 +15,7 @@
# Databases
# DATABASES = {
# 'default': {
# 'ENGINE': 'django.db.backends.sqlite3',
# 'ENGINE': 'ants_hub.sqlite3_backend',
# 'NAME': os.path.join(VAR_DIR, 'db.sqlite3'),
# }
# }

View File

@ -63,7 +63,7 @@ WSGI_APPLICATION = 'ants_hub.wsgi.application'
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'ENGINE': 'ants_hub.sqlite3_backend',
'NAME': 'db.sqlite3',
# Keep database open
'CONN_MAX_AGE': None,

View File

@ -0,0 +1,14 @@
# ANTS-Hub - Copyright (C) Entr'ouvert
from django.db.backends.sqlite3 import base
class DatabaseWrapper(base.DatabaseWrapper):
def _start_transaction_under_autocommit(self):
"""
Start a transaction explicitly in autocommit mode.
Staying in autocommit mode works around a bug of sqlite3 that breaks
savepoints when autocommit is disabled.
"""
self.cursor().execute('BEGIN IMMEDIATE')