From 8bdc0c71afc1944000a8226c6c29a8a16bbcd035 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20M=C3=B6hlmann?= Date: Wed, 14 Nov 2018 14:58:54 +0200 Subject: [PATCH] Allow for setting a different DB flavor --- core/admin/mailu/configuration.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/core/admin/mailu/configuration.py b/core/admin/mailu/configuration.py index 48599d5e..05df8b1f 100644 --- a/core/admin/mailu/configuration.py +++ b/core/admin/mailu/configuration.py @@ -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