socket connection for postgresql

This commit is contained in:
Trent Palmer 2021-01-08 22:52:12 -08:00
parent 81d3d5fa8e
commit e20e1529af
6 changed files with 11 additions and 1 deletions

4
.env
View File

@ -10,7 +10,9 @@ LOGGING_XMPP_COMMAND="/usr/bin/sendxmpp"
LOGGING_XMPP_USE_TLS=1
# then create postrgresql role and database
DATABASE_URL="postgresql://<app_user>:<database password for user app_user>@localhost/<app_db>"
# DATABASE_URL="postgresql://<app_user>:<database password for user app_user>@localhost/<app_db>"
# alternatively for unix socket connection
DATABASE_URL="postgresql://<app_user>:<database password for user app_user>@/<app_db>?host=/var/run/postgresql"
DATABASE_NAME="<app_db>"
DATABASE_USER="<app_user>"
DATABASE_PASSWORD="<database password for user app_user>"

View File

@ -8,6 +8,7 @@ def delete_photo(photo, app_config):
conn = psycopg2.connect(
dbname=app_config['DATABASE_NAME'],
user=app_config['DATABASE_USER'],
host="/var/run/postgresql",
password=app_config['DATABASE_PASSWORD']
)
cur = conn.cursor()

View File

@ -9,6 +9,7 @@ def find_next_previous(photo, app_config):
conn = psycopg2.connect(
dbname=app_config['DATABASE_NAME'],
user=app_config['DATABASE_USER'],
host="/var/run/postgresql",
password=app_config['DATABASE_PASSWORD']
)
cur = conn.cursor()
@ -58,6 +59,7 @@ def get_photo_list(contributor_id, app_config):
conn = psycopg2.connect(
dbname=app_config['DATABASE_NAME'],
user=app_config['DATABASE_USER'],
host="/var/run/postgresql",
password=app_config['DATABASE_PASSWORD']
)
cur = conn.cursor(cursor_factory=psycopg2.extras.RealDictCursor)

View File

@ -13,6 +13,7 @@ def process_uploaded_photo(filename, current_user, app_config):
conn = psycopg2.connect(
dbname=app_config['DATABASE_NAME'],
user=app_config['DATABASE_USER'],
host="/var/run/postgresql",
password=app_config['DATABASE_PASSWORD']
)
cur = conn.cursor()

View File

@ -7,6 +7,7 @@ def set_contributor_id_seq(app_config):
conn = psycopg2.connect(
dbname=app_config['DATABASE_NAME'],
user=app_config['DATABASE_USER'],
host="/var/run/postgresql",
password=app_config['DATABASE_PASSWORD']
)

View File

@ -13,6 +13,7 @@ def get_totp_qr(contributor, app_config):
conn = psycopg2.connect(
dbname=app_config['DATABASE_NAME'],
user=app_config['DATABASE_USER'],
host="/var/run/postgresql",
password=app_config['DATABASE_PASSWORD']
)
cur = conn.cursor()
@ -32,6 +33,7 @@ def validate_totp(contributor, totp_code, app_config):
conn = psycopg2.connect(
dbname=app_config['DATABASE_NAME'],
user=app_config['DATABASE_USER'],
host="/var/run/postgresql",
password=app_config['DATABASE_PASSWORD']
)
cur = conn.cursor()
@ -47,6 +49,7 @@ def disable_2fa(contributor, app_config):
conn = psycopg2.connect(
dbname=app_config['DATABASE_NAME'],
user=app_config['DATABASE_USER'],
host="/var/run/postgresql",
password=app_config['DATABASE_PASSWORD']
)
cur = conn.cursor()