diff --git a/backend/app.py b/backend/app.py index 7511e4e..0a86157 100644 --- a/backend/app.py +++ b/backend/app.py @@ -229,6 +229,7 @@ def admin(): @app.before_first_request def activate_job(): + helpers.load_dbconfig(app) helpers.load_version(app) helpers.create_data_directory() database.create_entry_table() diff --git a/backend/database.py b/backend/database.py index c7bdc48..7ba70c7 100644 --- a/backend/database.py +++ b/backend/database.py @@ -6,6 +6,7 @@ from sqlalchemy import create_engine, engine import mariadb import pandas from io import StringIO +from flask import current_app song_table = "songs" entry_table = "entries" @@ -18,8 +19,7 @@ connection = None def open_db() -> engine.base.Connection: global connection if (not connection): - engine = create_engine( - "mysql://ek0ur6p6ky9gdmif:jk571ov6g38g5iqv@eporqep6b4b8ql12.chr7pe7iynqr.eu-west-1.rds.amazonaws.com:3306/xdfmpudc3remzgj0") + engine = create_engine(current_app.config.get("DBCONNSTRING")) connection = engine.connect() # cur.execute('PRAGMA encoding = "UTF-8";') return connection diff --git a/backend/helpers.py b/backend/helpers.py index 17545a6..c937f04 100644 --- a/backend/helpers.py +++ b/backend/helpers.py @@ -47,6 +47,19 @@ def load_version(app): app.config['VERSION'] = "" else: app.config['VERSION'] = "" + +def load_dbconfig(app): + if os.environ.get("JAWSDB_MARIA_URL"): + app.config['VERSION'] = os.environ.get("JAWSDB_MARIA_URL") + elif os.path.isfile(".dbconn"): + with open('.dbconn', 'r') as file: + data = file.read().replace('\n', '') + if data: + app.config['DBCONNSTRING'] = data + else: + app.config['DBCONNSTRING'] = "" + else: + app.config['DBCONNSTRING'] = "" def setup_config(app): if check_config_exists():