Allow for setting a different DB flavor

master
Tim Möhlmann 6 years ago
parent 1ad853d8d0
commit 8bdc0c71af
No known key found for this signature in database
GPG Key ID: 8677988D8072E8DE

@ -3,8 +3,6 @@ import os
DEFAULT_CONFIG = {
# Specific to the admin UI
'SQLALCHEMY_DATABASE_URI': 'sqlite:////data/main.db',
'SQLALCHEMY_TRACK_MODIFICATIONS': False,
'DOCKER_SOCKET': 'unix:///var/run/docker.sock',
'BABEL_DEFAULT_LOCALE': 'en',
'BABEL_DEFAULT_TIMEZONE': 'UTC',
@ -14,6 +12,14 @@ DEFAULT_CONFIG = {
'DEBUG': False,
'DOMAIN_REGISTRATION': False,
'TEMPLATES_AUTO_RELOAD': True,
# Database settings
'DB_FLAVOR': 'sqlite',
'DB_USER': 'mailu',
'DB_PW': '',
'DB_URL': 'database',
'DB_NAME': 'mailu',
'SQLALCHEMY_DATABASE_URI': 'sqlite:////data/main.db',
'SQLALCHEMY_TRACK_MODIFICATIONS': False,
# Statistics management
'INSTANCE_ID_PATH': '/data/instance',
'STATS_ENDPOINT': '0.{}.stats.mailu.io',
@ -67,8 +73,15 @@ class ConfigManager(dict):
key: os.environ.get(key, value)
for key, value in DEFAULT_CONFIG.items()
})
if self.config['SQL_FLAVOR'] != 'sqlite'
self.setsql()
app.config = self
def setsql(self)
if not self.config['DB_PW']
self.config['DB_PW'] = self.config['SECRET_KEY']
self.config['SQLALCHEMY_DATABASE_URI'] = '{driver}://{user}:{pw}@{url}/{db}'.format(driver=DB_FLAVOR,user=DB_USER,pw=DB_PW,url=DB_URL,db=DB_NAME)
def setdefault(self, key, value):
if key not in self.config:
self.config[key] = value

Loading…
Cancel
Save