oshipka/persistance/__init__.py
2020-03-18 11:49:15 +01:00

22 lines
555 B
Python

import os
from flask_sqlalchemy import SQLAlchemy
from config import SQLALCHEMY_DATABASE_URI, MAKEDIRS, DATABASE_FILE
from oshipka.persistance.populate import populate_db
db = SQLAlchemy()
def init_db(app):
app.config["SQLALCHEMY_DATABASE_URI"] = SQLALCHEMY_DATABASE_URI
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
db.init_app(app)
for dir in MAKEDIRS:
os.makedirs(dir, exist_ok=True)
if not os.path.exists(DATABASE_FILE):
with app.app_context():
db.create_all()
populate_db(app)