forked from JiangRenDevOps/EasyCRM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
manage.py
51 lines (38 loc) · 973 Bytes
/
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
from app import create_app
from app.database import db, populate_db
from flask_migrate import Migrate, MigrateCommand
from flask_script import (
Server,
Shell,
Manager,
prompt_bool,
)
def _make_context():
return dict(
app=create_app(),
db=db,
populate_db=populate_db
)
app = create_app()
migrate = Migrate(app, db)
manager = Manager(app)
manager.add_command('runserver', Server())
manager.add_command('shell', Shell(make_context=_make_context))
manager.add_command('db', MigrateCommand)
@manager.command
def create_db(num_users=5):
"""Creates database tables and populates them."""
db.create_all()
populate_db()
@manager.command
def drop_db():
"""Drops database tables."""
if prompt_bool('Are you sure?'):
db.drop_all()
@manager.command
def recreate_db():
"""Same as running drop_db() and create_db()."""
drop_db()
create_db()
if __name__ == '__main__':
manager.run()