Enable dynamic database backend configuration
Adjusted the project settings to support MySQL or MariaDB as the database backend based on runtime configuration. This update allows for more flexible deployment options, utilizing either SQLite for development or production-ready databases like MySQL or MariaDB depending on the CONFIG variables. Defaults to SQLite when no external database is specified, maintaining backward compatibility.
This commit is contained in:
parent
27eca84ada
commit
57119dfc4c
1 changed files with 18 additions and 5 deletions
|
@ -71,12 +71,25 @@ WSGI_APPLICATION = 'expalert.wsgi.application'
|
|||
# Database
|
||||
# https://docs.djangoproject.com/en/4.2/ref/settings/#databases
|
||||
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.sqlite3',
|
||||
'NAME': BASE_DIR / 'db.sqlite3',
|
||||
if (dbtype := "MySQL") in CONFIG or (dbtype := "MariaDB") in CONFIG:
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.mysql',
|
||||
'NAME': CONFIG.get(dbtype, "Database"),
|
||||
'USER': CONFIG.get(dbtype, "Username"),
|
||||
'PASSWORD': CONFIG.get(dbtype, "Password"),
|
||||
'HOST': CONFIG.get(dbtype, "Host", fallback="localhost"),
|
||||
'PORT': CONFIG.getint(dbtype, "Port", fallback=3306)
|
||||
}
|
||||
}
|
||||
|
||||
else:
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.sqlite3',
|
||||
'NAME': BASE_DIR / 'db.sqlite3',
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# Password validation
|
||||
|
|
Loading…
Reference in a new issue