2022-02-04 08:15:44 -05:00
|
|
|
#!/usr/bin/env python
|
2022-02-03 17:27:25 -05:00
|
|
|
|
2022-02-04 08:15:44 -05:00
|
|
|
import os
|
2022-02-03 17:27:25 -05:00
|
|
|
|
2022-02-04 08:15:44 -05:00
|
|
|
from flask.cli import FlaskGroup
|
2022-02-04 10:16:42 -05:00
|
|
|
from forest import app, db, User
|
|
|
|
|
2022-02-04 08:27:05 -05:00
|
|
|
from flask_migrate import Migrate
|
2022-02-03 17:27:25 -05:00
|
|
|
|
|
|
|
cli = FlaskGroup(app)
|
|
|
|
|
2022-02-04 10:16:42 -05:00
|
|
|
migrate = Migrate()
|
|
|
|
migrate.init_app(app, db)
|
2022-02-04 08:27:51 -05:00
|
|
|
|
2022-02-03 17:27:25 -05:00
|
|
|
@cli.command("create_db")
|
|
|
|
def create_db():
|
|
|
|
db.drop_all()
|
|
|
|
db.create_all()
|
|
|
|
db.session.commit()
|
|
|
|
|
2022-02-04 08:27:05 -05:00
|
|
|
|
2022-02-03 17:27:25 -05:00
|
|
|
@cli.command("seed_db")
|
|
|
|
def seed_db():
|
|
|
|
db.session.add(User(email="daniel@deflax.net"))
|
|
|
|
db.session.commit()
|
|
|
|
|
2022-02-04 08:27:05 -05:00
|
|
|
|
2022-02-04 08:15:44 -05:00
|
|
|
@cli.command("upgrade_db")
|
|
|
|
def upgrade_db():
|
|
|
|
"""Run deployment tasks."""
|
|
|
|
from flask_migrate import upgrade
|
|
|
|
from app.models import Role, User
|
|
|
|
|
|
|
|
# migrate database to latest revision
|
|
|
|
upgrade()
|
|
|
|
|
|
|
|
# create user roles
|
|
|
|
Role.insert_roles()
|
|
|
|
|
2022-02-04 08:27:05 -05:00
|
|
|
|
2022-02-04 08:15:44 -05:00
|
|
|
@cli.command("restore_db")
|
|
|
|
def restore_db(restore_file):
|
|
|
|
""" recreate db from grid export with python3 manage.py restore /path/grid.tar.bz2 """
|
|
|
|
print(str(restore_file))
|
|
|
|
#TODO
|
|
|
|
from app.models import User
|
|
|
|
db.session.add(User(email=str(user), password=str(password), confirmed=True, confirmed_on=datetime.datetime.now()))
|
|
|
|
db.session.commit()
|
2022-02-03 17:27:25 -05:00
|
|
|
|
2022-02-04 08:27:05 -05:00
|
|
|
|
2022-02-03 17:27:25 -05:00
|
|
|
if __name__ == "__main__":
|
|
|
|
cli()
|
2022-02-04 08:15:44 -05:00
|
|
|
|