|
@@ -1,4 +1,5 @@
|
|
|
import json
|
|
|
+import logging
|
|
|
import sys
|
|
|
|
|
|
from pathlib import Path
|
|
@@ -6,7 +7,8 @@ from pathlib import Path
|
|
|
from flask import Flask
|
|
|
from flask_migrate import Migrate
|
|
|
from flask_sqlalchemy import SQLAlchemy
|
|
|
-
|
|
|
+from sqlalchemy.engine import Engine
|
|
|
+from sqlalchemy import event
|
|
|
|
|
|
print('- Loading settings')
|
|
|
with open('settings.json') as file:
|
|
@@ -18,13 +20,18 @@ app = Flask(__name__)
|
|
|
if "unittest" in sys.modules:
|
|
|
# creates an in-memory DB
|
|
|
db_file = ""
|
|
|
- app.logger.setLevel("CRITICAL")
|
|
|
+ app.logger.setLevel(logging.CRITICAL)
|
|
|
else:
|
|
|
db_file = Path.cwd() / settings['database']
|
|
|
|
|
|
app.config["SQLALCHEMY_DATABASE_URI"] = f"sqlite:///{db_file}"
|
|
|
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
|
|
|
|
|
|
+@event.listens_for(Engine, "connect")
|
|
|
+def set_sqlite_pragma(dbapi_connection, connection_record):
|
|
|
+ cursor = dbapi_connection.cursor()
|
|
|
+ cursor.execute("PRAGMA foreign_keys=ON")
|
|
|
+ cursor.close()
|
|
|
+
|
|
|
db = SQLAlchemy(app)
|
|
|
-db.session().execute("PRAGMA foreign_keys=ON")
|
|
|
migrate = Migrate(app, db)
|