__init__.py 650 B

123456789101112131415161718192021222324252627282930
  1. import json
  2. import sys
  3. from pathlib import Path
  4. from flask import Flask
  5. from flask_migrate import Migrate
  6. from flask_sqlalchemy import SQLAlchemy
  7. print('- Loading settings')
  8. with open('settings.json') as file:
  9. settings = json.load(file)
  10. app = Flask(__name__)
  11. if "unittest" in sys.modules:
  12. # creates an in-memory DB
  13. db_file = ""
  14. app.logger.setLevel("CRITICAL")
  15. else:
  16. db_file = Path.cwd() / settings['database']
  17. app.config["SQLALCHEMY_DATABASE_URI"] = f"sqlite:///{db_file}"
  18. app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
  19. db = SQLAlchemy(app)
  20. db.session().execute("PRAGMA foreign_keys=ON")
  21. migrate = Migrate(app, db)