-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanage.py
61 lines (31 loc) · 1.11 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
# -*- coding: utf-8 -*-
"""
zhifang.manage
~~~~~~~~~~~~~~
stamaimer 02/22/17
"""
import MySQLdb
from flask import current_app
from flask_script import Manager, Shell
from flask_migrate import Migrate, MigrateCommand
from app.models import db
from app.models.user import User
from app import create_app
app = create_app("config.Config")
manager = Manager(app)
migrate = Migrate(app, db)
def make_shell_context():
return dict(app=app, db=db, User=User)
manager.add_command("shell", Shell(make_context=make_shell_context))
manager.add_command("db", MigrateCommand)
@manager.command
def db_init():
connection = MySQLdb.connect(host=current_app.config["DB_HOST"],
user=current_app.config["DB_USER"], passwd=current_app.config["DB_PSWD"])
cursor = connection.cursor()
cursor.execute("drop database if exists %s" % current_app.config["DB_NAME"])
cursor.execute(
"create database if not exists %s character set utf8 collate utf8_general_ci" % current_app.config["DB_NAME"])
db.create_all()
if __name__ == "__main__":
manager.run()