Skip to content

Commit

Permalink
Add rebuild-database command
Browse files Browse the repository at this point in the history
  • Loading branch information
Jackson Chadfield committed Jul 31, 2019
1 parent c394fb9 commit 3d7223d
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 1 deletion.
28 changes: 28 additions & 0 deletions OpenLearn/commands.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# -*- coding: utf-8 -*-
import random

import click
import flask
from flask.cli import with_appcontext

from OpenLearn.extensions import db


@click.command()
@with_appcontext
def rebuild_database() -> None:
"""Builds the database."""
if flask.current_app.debug is False:
click.secho("You are in production mode", bold=True, fg="white", bg="red")
click.confirm("Are you sure about this?", abort=True, default=False)
code = "".join([str(random.randint(0, 9)) for _ in range(6)])
click.echo(f"Confirm by using the code: {click.style(code, fg='red', bold=True)}")
u_code = click.prompt("Code", confirmation_prompt=True)
if code != u_code:
raise click.Abort

db.session.commit()
db.drop_all()
click.secho("Dropped All Tables", fg="red", bold=True)
db.create_all()
click.secho("Created All Tables", fg="green", bold=True)
70 changes: 69 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ flask-sqlalchemy = "^2.4"
flask-paranoid = "^0.2.0"
flask-wtf = "^0.14.2"
flask-talisman = "^0.7.0"
flask-bcrypt = "^0.7.1"
psycopg2 = "^2.8"
flask-login = "^0.4.1"

[tool.poetry.dev-dependencies]
flask-debugtoolbar = "^0.10.1"
Expand Down

0 comments on commit 3d7223d

Please sign in to comment.