diff --git a/configs/docker_config.py b/configs/docker_config.py index 030e8d2..347bc26 100644 --- a/configs/docker_config.py +++ b/configs/docker_config.py @@ -27,6 +27,7 @@ legal_envvars = ( 'SALT', 'SQLALCHEMY_TRACK_MODIFICATIONS', 'SQLALCHEMY_DATABASE_URI', + 'SQLALCHEMY_ENGINE_OPTIONS', 'MAIL_SERVER', 'MAIL_PORT', 'MAIL_DEBUG', @@ -98,14 +99,25 @@ legal_envvars_bool = ( 'CAPTCHA_ENABLE', ) +legal_envvars_dict = ( + 'SQLALCHEMY_ENGINE_OPTIONS', +) + # import everything from environment variables import os import sys - +import json def str2bool(v): return v.lower() in ("true", "yes", "1") +def dictfromstr(v,ret): + try: + return json.loads(ret) + except Exception as e: + print('Cannot parse json {} for variable {}'.format(ret, v)) + print(e) + raise ValueError for v in legal_envvars: @@ -129,4 +141,6 @@ for v in legal_envvars: ret = str2bool(ret) if v in legal_envvars_int: ret = int(ret) + if v in legal_envvars_dict: + ret = dictfromstr(v, ret) sys.modules[__name__].__dict__[v] = ret diff --git a/docs/wiki/configuration/Environment-variables.md b/docs/wiki/configuration/Environment-variables.md index fbbedac..d49f60f 100644 --- a/docs/wiki/configuration/Environment-variables.md +++ b/docs/wiki/configuration/Environment-variables.md @@ -57,6 +57,8 @@ | SESSION_COOKIE_SECURE | | SIGNUP_ENABLED | | SQLALCHEMY_DATABASE_URI | SQL Alchemy URI to connect to database | N | no default | -| SQLALCHEMY_TRACK_MODIFICATIONS | +| SQLALCHEMY_TRACK_MODIFICATIONS | +| SQLALCHEMY_ENGINE_OPTIONS | json string. e.g. '{"pool_recycle":600,"echo":1}' [^2] | [^1]: Flask secret key (see https://flask.palletsprojects.com/en/1.1.x/config/#SECRET_KEY for how to generate) +[^2]: See Flask-SQLAlchemy Documentation for all engine options.