mirror of
https://github.com/PhoenixTwoFive/karaoqueue.git
synced 2025-05-19 19:11:49 +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
|
@app.before_first_request
|
||||||
def activate_job():
|
def activate_job():
|
||||||
|
helpers.load_dbconfig(app)
|
||||||
helpers.load_version(app)
|
helpers.load_version(app)
|
||||||
helpers.create_data_directory()
|
helpers.create_data_directory()
|
||||||
database.create_entry_table()
|
database.create_entry_table()
|
||||||
|
@ -6,6 +6,7 @@ from sqlalchemy import create_engine, engine
|
|||||||
import mariadb
|
import mariadb
|
||||||
import pandas
|
import pandas
|
||||||
from io import StringIO
|
from io import StringIO
|
||||||
|
from flask import current_app
|
||||||
|
|
||||||
song_table = "songs"
|
song_table = "songs"
|
||||||
entry_table = "entries"
|
entry_table = "entries"
|
||||||
@ -18,8 +19,7 @@ connection = None
|
|||||||
def open_db() -> engine.base.Connection:
|
def open_db() -> engine.base.Connection:
|
||||||
global connection
|
global connection
|
||||||
if (not connection):
|
if (not connection):
|
||||||
engine = create_engine(
|
engine = create_engine(current_app.config.get("DBCONNSTRING"))
|
||||||
"mysql://ek0ur6p6ky9gdmif:jk571ov6g38g5iqv@eporqep6b4b8ql12.chr7pe7iynqr.eu-west-1.rds.amazonaws.com:3306/xdfmpudc3remzgj0")
|
|
||||||
connection = engine.connect()
|
connection = engine.connect()
|
||||||
# cur.execute('PRAGMA encoding = "UTF-8";')
|
# cur.execute('PRAGMA encoding = "UTF-8";')
|
||||||
return connection
|
return connection
|
||||||
|
@ -48,6 +48,19 @@ def load_version(app):
|
|||||||
else:
|
else:
|
||||||
app.config['VERSION'] = ""
|
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):
|
def setup_config(app):
|
||||||
if check_config_exists():
|
if check_config_exists():
|
||||||
config = json.load(open(config_file))
|
config = json.load(open(config_file))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user