diff --git a/swh/web/settings/common.py b/swh/web/settings/common.py --- a/swh/web/settings/common.py +++ b/swh/web/settings/common.py @@ -1,4 +1,4 @@ -# Copyright (C) 2017-2020 The Software Heritage developers +# Copyright (C) 2017-2021 The Software Heritage developers # See the AUTHORS file at the top-level directory of this distribution # License: GNU Affero General Public License version 3, or any later version # See top-level LICENSE file for more information @@ -96,7 +96,7 @@ DATABASES = { "default": { "ENGINE": "django.db.backends.sqlite3", - "NAME": swh_web_config["development_db"], + "NAME": swh_web_config.get("development_db", ""), } } diff --git a/swh/web/settings/production.py b/swh/web/settings/production.py --- a/swh/web/settings/production.py +++ b/swh/web/settings/production.py @@ -31,11 +31,32 @@ # We're going through seven (or, in that case, 2) proxies thanks to Varnish REST_FRAMEWORK["NUM_PROXIES"] = 2 +db_conf = swh_web_config.get("db", {"name": "unset"}) + +db = { + "ENGINE": "django.db.backends.postgresql", + "NAME": db_conf["name"], +} + +db_user = db_conf.get("user") +if db_user: + db["USER"] = db_user + +db_pass = db_conf.get("password") +if db_pass: + db["PASSWORD"] = db_pass + +db_host = db_conf.get("host") +if db_host: + db["HOST"] = db_host + +db_port = db_conf.get("port") +if db_port: + db["PORT"] = db_port + +# https://docs.djangoproject.com/en/1.10/ref/settings/#databases DATABASES = { - "default": { - "ENGINE": "django.db.backends.sqlite3", - "NAME": swh_web_config["production_db"], - } + "default": db, } WEBPACK_LOADER["DEFAULT"]["CACHE"] = True