Skip to content

Commit

Permalink
🐛 fix: minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
greenstick committed Feb 13, 2024
1 parent 76dc410 commit 478cb12
Showing 1 changed file with 27 additions and 10 deletions.
37 changes: 27 additions & 10 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,27 +105,33 @@ def create_app(config_module=None, loglevel="INFO"):

# CORS(app, resources={r"/*": {"origins": "*", "send_wildcard": True}})

@app.cli.command("create-schema")
def create_schema():
"""Create the database schema."""
engine = model.db.session.get_bind()
metadata = MetaData()
metadata.reflect(bind=engine)
table_names = [table.name for table in metadata.tables.values()]
if len(table_names) == 0:
with engine.begin():
model.db.create_all()
# @app.cli.command("create-schema")
# def create_schema():
# """Create the database schema."""
# engine = model.db.session.get_bind()
# metadata = MetaData()
# metadata.reflect(bind=engine)
# table_names = [table.name for table in metadata.tables.values()]
# if len(table_names) == 0:
# with engine.begin():
# model.db.create_all()

@app.cli.command("destroy-schema")
def destroy_schema():
"""Create the database schema."""
# If DB is Azure, Skip
if config.FAIRHUB_DATABASE_URL.find("azure") > -1:
return
engine = model.db.session.get_bind()
with engine.begin():
model.db.drop_all()

@app.cli.command("cycle-schema")
def cycle_schema():
"""Destroy then re-create the database schema."""
# If DB is Azure, Skip
if config.FAIRHUB_DATABASE_URL.find("azure") > -1:
return
engine = model.db.session.get_bind()
with engine.begin():
model.db.drop_all()
Expand Down Expand Up @@ -240,6 +246,17 @@ def on_after_request(resp):
def validation_exception_handler(error):
return error.args[0], 422

with app.app_context():
engine = model.db.session.get_bind()
metadata = MetaData()
metadata.reflect(bind=engine)
table_names = [table.name for table in metadata.tables.values()]

# The alembic table is created by default, so we need to check for more than 1 table
if len(table_names) <= 1:
with engine.begin():
model.db.create_all()

return app


Expand Down

0 comments on commit 478cb12

Please sign in to comment.