2020-03-18 11:31:46 +01:00
|
|
|
import os
|
|
|
|
|
2020-03-18 11:14:47 +01:00
|
|
|
from flask_sqlalchemy import SQLAlchemy
|
|
|
|
|
2020-03-18 11:31:46 +01:00
|
|
|
from config import SQLALCHEMY_DATABASE_URI, MAKEDIRS, DATABASE_FILE
|
|
|
|
from oshipka.persistance.populate import populate_db
|
|
|
|
|
2020-03-18 11:14:47 +01:00
|
|
|
db = SQLAlchemy()
|
2020-03-18 11:31:46 +01:00
|
|
|
|
|
|
|
|
|
|
|
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)
|