-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathapp.py
More file actions
41 lines (30 loc) · 1015 Bytes
/
app.py
File metadata and controls
41 lines (30 loc) · 1015 Bytes
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
# coding: utf-8
from os import getenv
from click import argument
from sqlalchemy import text
from src import create_app, db
env = getenv("APP_ENV", "dev").lower()
name = getenv("APP_NAME", __name__).lower()
flask_app = create_app(env, name)
@flask_app.cli.command("init_db")
def init_db():
"""初始化数据库基本表结构"""
print(f"【{env}】环境下库表结构初始化...", end="")
db.create_all()
print("完成")
@flask_app.cli.command("drop_db")
def drop_db():
"""删除所有库表结构"""
rv = input(f"确定要删除【{env}】环境下所有数据吗?[Y/N]\n")
if rv and rv.lower() in ('y', 'yes'):
print("删除所有数据...", end="")
db.drop_all()
print("完成")
@flask_app.cli.command("rebuild_table")
@argument("table_name")
def rebuild_table(table_name):
print(f"drop table {table_name}")
db.session.execute(text(f"drop table IF EXISTS {table_name}"))
print("create all")
db.create_all()
print("完成")