1
0
mirror of https://github.com/ilri/dspace-statistics-api.git synced 2024-11-25 07:40:17 +01:00

Allow configuration of PostgreSQL port

Defaults to port 5432, but can be overridden with DATABASE_PORT.
This commit is contained in:
Alan Orth 2018-11-03 22:40:45 +02:00
parent e54dd8888f
commit 5f3bd61998
Signed by: alanorth
GPG Key ID: 0FB860CC9C45B1B9
2 changed files with 3 additions and 1 deletions

View File

@ -7,5 +7,6 @@ DATABASE_NAME = os.environ.get('DATABASE_NAME', 'dspacestatistics')
DATABASE_USER = os.environ.get('DATABASE_USER', 'dspacestatistics') DATABASE_USER = os.environ.get('DATABASE_USER', 'dspacestatistics')
DATABASE_PASS = os.environ.get('DATABASE_PASS', 'dspacestatistics') DATABASE_PASS = os.environ.get('DATABASE_PASS', 'dspacestatistics')
DATABASE_HOST = os.environ.get('DATABASE_HOST', 'localhost') DATABASE_HOST = os.environ.get('DATABASE_HOST', 'localhost')
DATABASE_PORT = os.environ.get('DATABASE_PORT', '5432')
# vim: set sw=4 ts=4 expandtab: # vim: set sw=4 ts=4 expandtab:

View File

@ -2,10 +2,11 @@ from .config import DATABASE_NAME
from .config import DATABASE_USER from .config import DATABASE_USER
from .config import DATABASE_PASS from .config import DATABASE_PASS
from .config import DATABASE_HOST from .config import DATABASE_HOST
from .config import DATABASE_PORT
import psycopg2, psycopg2.extras import psycopg2, psycopg2.extras
def database_connection(): 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 return connection