mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-10-26 15:54:20 -04:00
feat: Add option to switch sqlite to WAL (#6050)
Co-authored-by: Michael Genson <71845777+michael-genson@users.noreply.github.com>
This commit is contained in:
@@ -88,6 +88,8 @@ tasks:
|
|||||||
- rm -r ./dev/data/recipes/
|
- rm -r ./dev/data/recipes/
|
||||||
- rm -r ./dev/data/users/
|
- rm -r ./dev/data/users/
|
||||||
- rm -f ./dev/data/mealie*.db
|
- rm -f ./dev/data/mealie*.db
|
||||||
|
- rm -f ./dev/data/mealie*.db-shm
|
||||||
|
- rm -f ./dev/data/mealie*.db-wal
|
||||||
- rm -f ./dev/data/mealie.log
|
- rm -f ./dev/data/mealie.log
|
||||||
- rm -f ./dev/data/.secret
|
- rm -f ./dev/data/.secret
|
||||||
|
|
||||||
|
|||||||
@@ -32,15 +32,16 @@
|
|||||||
|
|
||||||
### Database
|
### Database
|
||||||
|
|
||||||
| Variables | Default | Description |
|
| Variables | Default | Description |
|
||||||
| ------------------------------------------------------- | :------: | ----------------------------------------------------------------------- |
|
|---------------------------------------------------------|:--------:|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||||
| DB_ENGINE | sqlite | Optional: 'sqlite', 'postgres' |
|
| DB_ENGINE | sqlite | Optional: 'sqlite', 'postgres' |
|
||||||
| POSTGRES_USER<super>[†][secrets]</super> | mealie | Postgres database user |
|
| SQLITE_MIGRATE_JOURNAL_WAL | False | If set to true, switches SQLite's journal mode to WAL, which allows for multiple concurrent accesses. This can be useful when you have a decent amount of concurrency or when using certain remote storage systems such as Ceph. |
|
||||||
| POSTGRES_PASSWORD<super>[†][secrets]</super> | mealie | Postgres database password |
|
| POSTGRES_USER<super>[†][secrets]</super> | mealie | Postgres database user |
|
||||||
| POSTGRES_SERVER<super>[†][secrets]</super> | postgres | Postgres database server address |
|
| POSTGRES_PASSWORD<super>[†][secrets]</super> | mealie | Postgres database password |
|
||||||
| POSTGRES_PORT<super>[†][secrets]</super> | 5432 | Postgres database port |
|
| POSTGRES_SERVER<super>[†][secrets]</super> | postgres | Postgres database server address |
|
||||||
| POSTGRES_DB<super>[†][secrets]</super> | mealie | Postgres database name |
|
| POSTGRES_PORT<super>[†][secrets]</super> | 5432 | Postgres database port |
|
||||||
| POSTGRES_URL_OVERRIDE<super>[†][secrets]</super> | None | Optional Postgres URL override to use instead of POSTGRES\_\* variables |
|
| POSTGRES_DB<super>[†][secrets]</super> | mealie | Postgres database name |
|
||||||
|
| POSTGRES_URL_OVERRIDE<super>[†][secrets]</super> | None | Optional Postgres URL override to use instead of POSTGRES\_\* variables |
|
||||||
|
|
||||||
### Email
|
### Email
|
||||||
|
|
||||||
|
|||||||
@@ -196,6 +196,8 @@ class AppSettings(AppLoggingSettings):
|
|||||||
DB_ENGINE: str = "sqlite" # Options: 'sqlite', 'postgres'
|
DB_ENGINE: str = "sqlite" # Options: 'sqlite', 'postgres'
|
||||||
DB_PROVIDER: AbstractDBProvider | None = None
|
DB_PROVIDER: AbstractDBProvider | None = None
|
||||||
|
|
||||||
|
SQLITE_MIGRATE_JOURNAL_WAL: bool = False
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def DB_URL(self) -> str | None:
|
def DB_URL(self) -> str | None:
|
||||||
return self.DB_PROVIDER.db_url if self.DB_PROVIDER else None
|
return self.DB_PROVIDER.db_url if self.DB_PROVIDER else None
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ from collections.abc import Generator
|
|||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
|
|
||||||
import sqlalchemy as sa
|
import sqlalchemy as sa
|
||||||
|
from sqlalchemy.engine import Engine
|
||||||
|
from sqlalchemy.event import listens_for
|
||||||
from sqlalchemy.orm import sessionmaker
|
from sqlalchemy.orm import sessionmaker
|
||||||
from sqlalchemy.orm.session import Session
|
from sqlalchemy.orm.session import Session
|
||||||
|
|
||||||
@@ -10,6 +12,24 @@ from mealie.core.config import get_app_settings
|
|||||||
settings = get_app_settings()
|
settings = get_app_settings()
|
||||||
|
|
||||||
|
|
||||||
|
@listens_for(Engine, "connect")
|
||||||
|
def set_sqlite_pragma_journal_wal(dbapi_connection, connection_record):
|
||||||
|
"""
|
||||||
|
Automatically enables SQLite's WAL journal mode if the setting is activated.
|
||||||
|
|
||||||
|
This is a persistent setting, so turning it off down the line doesn't revert back to the original journal mode.
|
||||||
|
|
||||||
|
Write-Ahead-Log enables sqlite to be used concurrently by multiple readers and writers (writes still happen
|
||||||
|
sequentially).
|
||||||
|
"""
|
||||||
|
global settings
|
||||||
|
if settings.DB_ENGINE != "sqlite" or not settings.SQLITE_MIGRATE_JOURNAL_WAL:
|
||||||
|
return
|
||||||
|
cursor = dbapi_connection.cursor()
|
||||||
|
cursor.execute("PRAGMA journal_mode=WAL")
|
||||||
|
cursor.close()
|
||||||
|
|
||||||
|
|
||||||
def sql_global_init(db_url: str):
|
def sql_global_init(db_url: str):
|
||||||
connect_args = {}
|
connect_args = {}
|
||||||
if "sqlite" in db_url:
|
if "sqlite" in db_url:
|
||||||
|
|||||||
Reference in New Issue
Block a user