mirror of
https://github.com/PhoenixTwoFive/karaoqueue.git
synced 2025-05-19 02:51:48 +02:00
Load DB Connection from ENV
This commit is contained in:
parent
fc78bdc4fe
commit
57ced69ddd
@ -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()
|
||||
|
@ -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
|
||||
|
@ -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():
|
||||
|
Loading…
x
Reference in New Issue
Block a user