From 5f3bd61998f87cf9cf249c48c978ba5e48d46857 Mon Sep 17 00:00:00 2001 From: Alan Orth Date: Sat, 3 Nov 2018 22:40:45 +0200 Subject: [PATCH] Allow configuration of PostgreSQL port Defaults to port 5432, but can be overridden with DATABASE_PORT. --- dspace_statistics_api/config.py | 1 + dspace_statistics_api/database.py | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/dspace_statistics_api/config.py b/dspace_statistics_api/config.py index 289fb06..31b1ea0 100644 --- a/dspace_statistics_api/config.py +++ b/dspace_statistics_api/config.py @@ -7,5 +7,6 @@ DATABASE_NAME = os.environ.get('DATABASE_NAME', 'dspacestatistics') DATABASE_USER = os.environ.get('DATABASE_USER', 'dspacestatistics') DATABASE_PASS = os.environ.get('DATABASE_PASS', 'dspacestatistics') DATABASE_HOST = os.environ.get('DATABASE_HOST', 'localhost') +DATABASE_PORT = os.environ.get('DATABASE_PORT', '5432') # vim: set sw=4 ts=4 expandtab: diff --git a/dspace_statistics_api/database.py b/dspace_statistics_api/database.py index 3dae8ec..73ee022 100644 --- a/dspace_statistics_api/database.py +++ b/dspace_statistics_api/database.py @@ -2,10 +2,11 @@ from .config import DATABASE_NAME from .config import DATABASE_USER from .config import DATABASE_PASS from .config import DATABASE_HOST +from .config import DATABASE_PORT import psycopg2, psycopg2.extras def database_connection(): - connection = psycopg2.connect("dbname={} user={} password={} host='{}'".format(DATABASE_NAME, DATABASE_USER, DATABASE_PASS, DATABASE_HOST), cursor_factory=psycopg2.extras.DictCursor) + connection = psycopg2.connect("dbname={} user={} password={} host='{}' port={}".format(DATABASE_NAME, DATABASE_USER, DATABASE_PASS, DATABASE_HOST, DATABASE_PORT), cursor_factory=psycopg2.extras.DictCursor) return connection