-
Notifications
You must be signed in to change notification settings - Fork 0
/
manage.py
43 lines (30 loc) · 845 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
#manage.py
import os
from flask_script import Manager
from flask_migrate import Migrate, MigrateCommand
from datetime import datetime
from project import app, db
from project.models import User, Role
app.config.from_object(os.environ['APP_SETTINGS'])
migrate = Migrate(app, db)
manager = Manager(app)
#migrations
manager.add_command('db', MigrateCommand)
# Creates the db tables.
@manager.command
def create_db():
db.create_all()
# Drops the db tables
@manager.command
def drop_db():
db.drop_all()
# Creates admin user and admin role
@manager.command
def create_admin():
user = User(email="", password="", username="", active=True, confirmed_at=datetime.utcnow())
role = Role(name='admin')
user.roles.append(role)
db.session.add(user)
db.session.commit()
if __name__ == '__main__':
manager.run()