Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various improvements #841

Merged
merged 6 commits into from
Aug 21, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
[cli] Command to check if the db was initialized
frankrousseau committed Aug 20, 2024

Verified

This commit was signed with the committer’s verified signature.
joshcooper Josh Cooper
commit 8f5de366e6c6d1cf4a0ad3fabebe6e56fb0f7967
14 changes: 13 additions & 1 deletion zou/app/utils/dbhelpers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from sqlalchemy import create_engine
from sqlalchemy import create_engine, inspect
from sqlalchemy_utils import database_exists, create_database
from sqlalchemy.engine.url import URL
from sqlalchemy.orm import close_all_sessions
@@ -39,3 +39,15 @@ def drop_all():
db.session.flush()
close_all_sessions()
return db.drop_all()


def is_init():
"""
Check if database is initialized.
"""
from zou.app import db
from zou.app.models.project_status import ProjectStatus
return (
inspect(db.engine).has_table("person")
and db.session.query(ProjectStatus).count() == 2
)
15 changes: 15 additions & 0 deletions zou/cli.py
Original file line number Diff line number Diff line change
@@ -47,6 +47,21 @@ def init_db():
print("Database and tables created.")


@cli.command()
def is_db_ready():
"""
Return a message telling if the database wheter the database is
initiliazed or not."
"""
with app.app_context():
is_init = dbhelpers.is_init()
if is_init:
print("Database is initiliazed.")
else:
print("Database is not initiliazed. "
"Run 'zou init-db' and 'init-data'.")


@cli.command()
@click.option("--message", default="")
def migrate_db(message):