Skip to content

Commit

Permalink
Refactor Database code to avoid overload
Browse files Browse the repository at this point in the history
  • Loading branch information
WillNilges committed Sep 3, 2023
1 parent 5f0324f commit 294fa69
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 10 deletions.
5 changes: 3 additions & 2 deletions meshdb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from flask import Flask
from flask_security import Security, SQLAlchemyUserDatastore, hash_password

from .db.database import db
from .data.database import db

from dotenv import load_dotenv

Expand Down Expand Up @@ -33,7 +33,7 @@ def create_app():
app.config["WTF_CSRF_ENABLED"] = False

# Configure Database
from meshdb.db.setup import initialize_db
from meshdb.data.setup import initialize_db

initialize_db()

Expand All @@ -51,6 +51,7 @@ def create_app():
app.security.datastore.create_user(email="[email protected]", password=hash_password("abcd1234"))
db.session.commit()

# Register API routes
from .routes import route_blueprint

app.register_blueprint(route_blueprint)
Expand Down
2 changes: 1 addition & 1 deletion meshdb/auth/authmodels.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from sqlalchemy.ext.mutable import MutableList
from sqlalchemy.orm import backref, relationship

from ..db.database import db
from ..data.database import db


class RolesUsers(db.Model):
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions meshdb/db/setup.py → meshdb/data/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
import meshdb.models.member
import meshdb.models.request

from ..db.database import create_db_engine
from ..data.database import create_db_engine


def initialize_db():
engine = create_db_engine() # TODO: Delete?

print(f"Database Exists: {database_exists(engine.url)}")
if not database_exists(engine.url):
print("Database not found. Bootstrapping....")
create_database(engine.url)
print(database_exists(engine.url))
meshdb.models.baseModel.Base.metadata.create_all(engine)
meshdb.models.baseModel.Base.metadata.create_all(engine)
7 changes: 3 additions & 4 deletions meshdb/routes.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from flask import current_app as app
from flask import request
from flask import request, Blueprint
from flask_security import auth_required
from flask import Blueprint

route_blueprint = Blueprint("route_blueprint", __name__)
from .data import queries

from .db import queries
route_blueprint = Blueprint("route_blueprint", __name__)


@route_blueprint.route("/getMembers", methods=["GET"])
Expand Down

0 comments on commit 294fa69

Please sign in to comment.