diff --git a/src/oshipka.py b/src/oshipka.py index 82d2b51..7b92f26 100644 --- a/src/oshipka.py +++ b/src/oshipka.py @@ -1,5 +1,5 @@ -from oshipka import init_db -from oshipka import app +from oshipka.persistance import init_db +from oshipka.webapp import app if __name__ == "__main__": init_db(app) diff --git a/src/oshipka/persistance/__init__.py b/src/oshipka/persistance/__init__.py index f0b13d6..e5d4f91 100644 --- a/src/oshipka/persistance/__init__.py +++ b/src/oshipka/persistance/__init__.py @@ -1,3 +1,21 @@ +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) diff --git a/src/oshipka/persistance/populate.py b/src/oshipka/persistance/populate.py index bd68c79..07b0a8c 100644 --- a/src/oshipka/persistance/populate.py +++ b/src/oshipka/persistance/populate.py @@ -1,7 +1,4 @@ -import os -from config import SQLALCHEMY_DATABASE_URI, MAKEDIRS, DATABASE_FILE -from oshipka.persistance import db def populate_db(app): @@ -9,14 +6,3 @@ def populate_db(app): pass -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)