This repository has been archived by the owner on May 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
manage.py
executable file
·69 lines (50 loc) · 2 KB
/
manage.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env python
from flask_script import Manager, Server, Option, prompt_bool
from flask_script.commands import Clean, ShowUrls
from flask_alembic import ManageMigrations, FlaskAlembicConfig
from alembic import command
from peopleflow import app
from peopleflow import models
from peopleflow.models import db
manager = Manager(app)
database = Manager(usage="Perform database operations")
class InitedServer(Server):
def get_options(self):
return super(InitedServer, self).get_options() + (
Option('-e', dest='env', default='dev', help="run server for this environment [default 'dev']"),
)
def handle(self, *args, **kwargs):
super(InitedServer, self).handle(*args, **kwargs)
class InitedMigrations(ManageMigrations):
def run(self, args):
super(InitedMigrations, self).run(args[1:])
@manager.shell
def _make_context():
return dict(app=app, db=db, models=models)
@database.option('-e', '--env', default='dev', help="runtime environment [default 'dev']")
def drop(env):
"Drops database tables"
if prompt_bool("Are you sure you want to lose all your data?"):
db.drop_all()
@database.option('-e', '--env', default='dev', help="runtime environment [default 'dev']")
def create(env):
"Creates database tables from sqlalchemy models"
db.create_all()
config = FlaskAlembicConfig("alembic.ini")
command.stamp(config, "head")
@database.option('-e', '--env', default='dev', help="runtime environment [default 'dev']")
def setversion(env):
'''
Manually set the alembic version of the
database to the provided value.
'''
config = FlaskAlembicConfig("alembic.ini")
version = raw_input("Enter the alembic version to be set:")
command.stamp(config, version)
manager.add_command("db", database)
manager.add_command("runserver", InitedServer())
manager.add_command("clean", Clean())
manager.add_command("showurls", ShowUrls())
manager.add_command("migrate", InitedMigrations())
if __name__ == "__main__":
manager.run()