diff --git a/requirements-test.txt b/requirements-test.txt --- a/requirements-test.txt +++ b/requirements-test.txt @@ -12,5 +12,6 @@ swh-scheduler[testing] >= 0.5.0 swh.storage >= 0.1.1 types-docutils +types-psycopg2 types-pyyaml types-requests 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 @@ -32,6 +32,19 @@ REST_FRAMEWORK["NUM_PROXIES"] = 2 db_conf = swh_web_config["production_db"] +if db_conf.get("name", "").startswith("postgresql://"): + # poor man's support for dsn connection string... + import psycopg2 + + with psycopg2.connect(db_conf.get("name")) as cnx: + dsn_dict = cnx.get_dsn_parameters() + + db_conf["name"] = dsn_dict.get("dbname") + db_conf["host"] = dsn_dict.get("host") + db_conf["port"] = dsn_dict.get("port") + db_conf["user"] = dsn_dict.get("user") + db_conf["password"] = dsn_dict.get("password") + # https://docs.djangoproject.com/en/1.10/ref/settings/#databases DATABASES = {