-
Notifications
You must be signed in to change notification settings - Fork 0
/
manage.py
58 lines (45 loc) · 1.36 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
import sys
import sqlalchemy
from flask.ext.assets import ManageAssets
from flask.ext.migrate import Migrate, MigrateCommand
from flask.ext.script import Manager
from rhiz import models
from rhiz.factory import create_app
from rhiz.models import db
app = create_app()
migrate = Migrate(app, db)
manager = Manager(app)
manager.add_command('db', MigrateCommand)
manager.add_command('assets', ManageAssets)
@manager.shell
def _make_context():
return dict(app=app, db=db, models=models)
@manager.command
@manager.option('-v', '--verbose', dest='verbose', default=False)
def seed_db(verbose=False):
from rhiz.manage_helpers.seed_db import seed
if not verbose:
db.engine.echo = False
sys.stdout.write(u'Seeding the database.\n')
seed()
return 0
@manager.command
@manager.option('-v', '--verbose', dest='verbose', default=False)
def soft_reset(verbose=False):
if not verbose:
db.engine.echo = False
db.drop_all()
db.create_all()
seed_db()
return 0
@manager.command
@manager.option('-v', '--verbose', dest='verbose', default=False)
def hard_reset(verbose=False):
engine = sqlalchemy.create_engine(app.config['SQLALCHEMY_DATABASE_URI'])
meta = sqlalchemy.MetaData(engine)
meta.reflect()
meta.drop_all()
MigrateCommand._commands['upgrade'].run()
seed_db()
if __name__ == '__main__':
manager.run()