refactor(migrate):重构数据迁移脚本

This commit is contained in:
zhengxinonly
2021-07-22 15:55:54 +08:00
parent 3f74011c98
commit 86f07817b1
11 changed files with 521 additions and 247 deletions
@@ -0,0 +1,11 @@
import json
import os
path = os.path.dirname(os.path.abspath(__file__))
cp_dept_data_list = json.loads(open(os.path.join(path, 'cp_dept.json'), encoding='utf-8').read())
cp_user_data_list = json.loads(open(os.path.join(path, 'cp_user.json'), encoding='utf-8').read())
file_photo_data_list = json.loads(open(os.path.join(path, 'file_photo.json'), encoding='utf-8').read())
rt_power_data_list = json.loads(open(os.path.join(path, 'rt_power.json'), encoding='utf-8').read())
rt_role_data_list = json.loads(open(os.path.join(path, 'rt_role.json'), encoding='utf-8').read())
rt_role_power_data_list = json.loads(open(os.path.join(path, 'rt_role_power.json'), encoding='utf-8').read())
rt_user_role_data_list = json.loads(open(os.path.join(path, 'rt_user_role.json'), encoding='utf-8').read())
@@ -0,0 +1,72 @@
[
{
"id": 1,
"parent_id": 0,
"dept_name": "总公司",
"sort": 1,
"leader": "就眠仪式",
"phone": "12312345679",
"email": "123qq.com",
"status": 1,
"remark": null,
"address": "这是总公司",
"create_at": null,
"update_at": "2021-06-01 17:23:20"
},
{
"id": 4,
"parent_id": 1,
"dept_name": "济南分公司",
"sort": 2,
"leader": "就眠仪式",
"phone": "12312345678",
"email": "1234qq.com",
"status": 1,
"remark": null,
"address": "这是济南",
"create_at": "2021-06-01 17:24:33",
"update_at": "2021-06-01 17:25:19"
},
{
"id": 5,
"parent_id": 1,
"dept_name": "唐山分公司",
"sort": 4,
"leader": "mkg",
"phone": "12312345678",
"email": "123@qq.com",
"status": 1,
"remark": null,
"address": "这是唐山",
"create_at": "2021-06-01 17:25:15",
"update_at": "2021-06-01 17:25:20"
},
{
"id": 7,
"parent_id": 4,
"dept_name": "济南分公司开发部",
"sort": 5,
"leader": "就眠仪式",
"phone": "12312345678",
"email": "123@qq.com",
"status": 1,
"remark": null,
"address": "测试",
"create_at": "2021-06-01 17:27:39",
"update_at": "2021-06-01 17:27:39"
},
{
"id": 8,
"parent_id": 5,
"dept_name": "唐山测试部",
"sort": 6,
"leader": "mkg",
"phone": "12312345678",
"email": "123@qq.com",
"status": 1,
"remark": null,
"address": "测试部",
"create_at": "2021-06-01 17:28:27",
"update_at": "2021-06-01 17:28:27"
}
]
@@ -0,0 +1 @@
[{"id": 1, "username": "admin", "password_hash": "pbkdf2:sha256:150000$raM7mDSr$58fe069c3eac01531fc8af85e6fc200655dd2588090530084d182e6ec9d52c85", "create_at": null, "update_at": "2021-06-01 17:28:55", "enable": 1, "realname": "超级管理", "remark": "要是不能把握时机,就要终身蹭蹬,一事无成!", "avatar": "http://127.0.0.1:5000/_uploads/photos/1617291580000.jpg", "dept_id": 1}, {"id": 7, "username": "test", "password_hash": "pbkdf2:sha256:150000$cRS8bYNh$adb57e64d929863cf159f924f74d0634f1fecc46dba749f1bfaca03da6d2e3ac", "create_at": "2021-03-22 20:03:42", "update_at": "2021-06-01 17:29:47", "enable": 1, "realname": "超级管理", "remark": "要是不能把握时机,就要终身蹭蹬,一事无成", "avatar": "/static/admin/admin/images/avatar.jpg", "dept_id": 1}, {"id": 8, "username": "wind", "password_hash": "pbkdf2:sha256:150000$skME1obT$6a2c20cd29f89d7d2f21d9e373a7e3445f70ebce3ef1c3a555e42a7d17170b37", "create_at": "2021-06-01 17:30:39", "update_at": "2021-06-01 17:30:52", "enable": 1, "realname": "风", "remark": null, "avatar": "/static/admin/admin/images/avatar.jpg", "dept_id": 7}]
@@ -0,0 +1,18 @@
[
{
"id": 3,
"name": "6958819_pear-admin_1607443454_1.png",
"href": "http://127.0.0.1:5000/_uploads/photos/6958819_pear-admin_1607443454_1.png",
"mime": "image/png",
"size": "2204",
"create_time": "2021-03-19 18:53:02"
},
{
"id": 17,
"name": "1617291580000.jpg",
"href": "http://127.0.0.1:5000/_uploads/photos/1617291580000.jpg",
"mime": "image/png",
"size": "94211",
"create_time": "2021-04-01 23:39:41"
}
]
@@ -0,0 +1,324 @@
[
{
"id": 1,
"name": "系统管理",
"type": "0",
"code": "",
"url": null,
"open_type": null,
"parent_id": "0",
"icon": "layui-icon layui-icon-set-fill",
"sort": 1,
"create_time": null,
"update_time": null,
"enable": 1
},
{
"id": 3,
"name": "用户管理",
"type": "1",
"code": "admin:user:main",
"url": "/users/",
"open_type": "_iframe",
"parent_id": "1",
"icon": "layui-icon layui-icon layui-icon layui-icon layui-icon-rate",
"sort": 1,
"create_time": null,
"update_time": null,
"enable": 1
},
{
"id": 4,
"name": "权限管理",
"type": "1",
"code": "admin:power:main",
"url": "/rights/",
"open_type": "_iframe",
"parent_id": "1",
"icon": null,
"sort": 2,
"create_time": null,
"update_time": null,
"enable": 1
},
{
"id": 9,
"name": "角色管理",
"type": "1",
"code": "admin:role:main",
"url": "/admin/role",
"open_type": "_iframe",
"parent_id": "1",
"icon": "layui-icon layui-icon-username",
"sort": 2,
"create_time": "2021-03-16 22:24:58",
"update_time": "2021-03-25 19:15:24",
"enable": 1
},
{
"id": 13,
"name": "日志管理",
"type": "1",
"code": "admin:log:main",
"url": "/logs",
"open_type": "_iframe",
"parent_id": "1",
"icon": "layui-icon layui-icon-read",
"sort": 4,
"create_time": "2021-03-18 22:37:10",
"update_time": "2021-06-03 11:06:25",
"enable": 1
},
{
"id": 17,
"name": "文件管理",
"type": "0",
"code": "",
"url": "",
"open_type": "",
"parent_id": "0",
"icon": "layui-icon layui-icon-camera",
"sort": 2,
"create_time": "2021-03-19 18:56:23",
"update_time": "2021-03-25 19:15:08",
"enable": 1
},
{
"id": 18,
"name": "图片上传",
"type": "1",
"code": "admin:file:main",
"url": "/file",
"open_type": "_iframe",
"parent_id": "17",
"icon": "layui-icon layui-icon-camera",
"sort": 5,
"create_time": "2021-03-19 18:57:19",
"update_time": "2021-03-25 19:15:13",
"enable": 1
},
{
"id": 21,
"name": "权限增加",
"type": "2",
"code": "admin:power:add",
"url": "",
"open_type": "",
"parent_id": "4",
"icon": "layui-icon layui-icon-add-circle",
"sort": 1,
"create_time": "2021-03-22 19:43:52",
"update_time": "2021-03-25 19:15:22",
"enable": 1
},
{
"id": 22,
"name": "用户增加",
"type": "2",
"code": "admin:user:add",
"url": "",
"open_type": "",
"parent_id": "3",
"icon": "layui-icon layui-icon-add-circle",
"sort": 1,
"create_time": "2021-03-22 19:45:40",
"update_time": "2021-03-25 19:15:17",
"enable": 1
},
{
"id": 23,
"name": "用户编辑",
"type": "2",
"code": "admin:user:edit",
"url": "",
"open_type": "",
"parent_id": "3",
"icon": "layui-icon layui-icon-rate",
"sort": 2,
"create_time": "2021-03-22 19:46:15",
"update_time": "2021-03-25 19:15:18",
"enable": 1
},
{
"id": 24,
"name": "用户删除",
"type": "2",
"code": "admin:user:remove",
"url": "",
"open_type": "",
"parent_id": "3",
"icon": "layui-icon None",
"sort": 3,
"create_time": "2021-03-22 19:46:51",
"update_time": "2021-03-25 19:15:18",
"enable": 1
},
{
"id": 25,
"name": "权限编辑",
"type": "2",
"code": "admin:power:edit",
"url": "",
"open_type": "",
"parent_id": "4",
"icon": "layui-icon layui-icon-edit",
"sort": 2,
"create_time": "2021-03-22 19:47:36",
"update_time": "2021-03-25 19:15:22",
"enable": 1
},
{
"id": 26,
"name": "用户删除",
"type": "2",
"code": "admin:power:remove",
"url": "",
"open_type": "",
"parent_id": "4",
"icon": "layui-icon layui-icon-delete",
"sort": 3,
"create_time": "2021-03-22 19:48:17",
"update_time": "2021-03-25 19:15:23",
"enable": 1
},
{
"id": 27,
"name": "用户增加",
"type": "2",
"code": "admin:role:add",
"url": "",
"open_type": "",
"parent_id": "9",
"icon": "layui-icon layui-icon-add-circle",
"sort": 1,
"create_time": "2021-03-22 19:49:09",
"update_time": "2021-03-25 19:15:24",
"enable": 1
},
{
"id": 28,
"name": "角色编辑",
"type": "2",
"code": "admin:role:edit",
"url": "",
"open_type": "",
"parent_id": "9",
"icon": "layui-icon layui-icon-edit",
"sort": 2,
"create_time": "2021-03-22 19:49:41",
"update_time": "2021-03-25 19:15:25",
"enable": 1
},
{
"id": 29,
"name": "角色删除",
"type": "2",
"code": "admin:role:remove",
"url": "",
"open_type": "",
"parent_id": "9",
"icon": "layui-icon layui-icon-delete",
"sort": 3,
"create_time": "2021-03-22 19:50:15",
"update_time": "2021-03-25 19:15:26",
"enable": 1
},
{
"id": 30,
"name": "角色授权",
"type": "2",
"code": "admin:role:power",
"url": "",
"open_type": "",
"parent_id": "9",
"icon": "layui-icon layui-icon-component",
"sort": 4,
"create_time": "2021-03-22 19:50:54",
"update_time": "2021-03-25 19:15:26",
"enable": 1
},
{
"id": 31,
"name": "图片增加",
"type": "2",
"code": "admin:file:add",
"url": "",
"open_type": "",
"parent_id": "18",
"icon": "layui-icon layui-icon-add-circle",
"sort": 1,
"create_time": "2021-03-22 19:58:05",
"update_time": "2021-03-25 19:15:28",
"enable": 1
},
{
"id": 32,
"name": "图片删除",
"type": "2",
"code": "admin:file:delete",
"url": "",
"open_type": "",
"parent_id": "18",
"icon": "layui-icon layui-icon-delete",
"sort": 2,
"create_time": "2021-03-22 19:58:45",
"update_time": "2021-03-25 19:15:29",
"enable": 1
},
{
"id": 48,
"name": "部门管理",
"type": "1",
"code": "admin:dept:main",
"url": "/dept",
"open_type": "_iframe",
"parent_id": "1",
"icon": "layui-icon layui-icon-group",
"sort": 3,
"create_time": "2021-06-01 16:22:11",
"update_time": "2021-06-01 16:22:11",
"enable": 1
},
{
"id": 49,
"name": "部门增加",
"type": "2",
"code": "admin:dept:add",
"url": "",
"open_type": "",
"parent_id": "48",
"icon": "layui-icon None",
"sort": 1,
"create_time": "2021-06-01 17:35:52",
"update_time": "2021-06-01 17:36:15",
"enable": 1
},
{
"id": 50,
"name": "部门编辑",
"type": "2",
"code": "admin:dept:edit",
"url": "",
"open_type": "",
"parent_id": "48",
"icon": "layui-icon ",
"sort": 2,
"create_time": "2021-06-01 17:36:41",
"update_time": "2021-06-01 17:36:41",
"enable": 1
},
{
"id": 51,
"name": "部门删除",
"type": "2",
"code": "admin:dept:remove",
"url": "",
"open_type": "",
"parent_id": "48",
"icon": "layui-icon None",
"sort": 3,
"create_time": "2021-06-01 17:37:15",
"update_time": "2021-06-01 17:37:26",
"enable": 1
}
]
@@ -0,0 +1 @@
[{"id": 1, "name": "管理员", "code": "admin", "remark": null, "details": "管理员", "sort": 1, "create_time": null, "update_time": null, "enable": 1}, {"id": 2, "name": "普通用户", "code": "common", "remark": null, "details": "只有查看,没有增删改权限", "sort": 2, "create_time": "2021-03-22 20:02:38", "update_time": "2021-04-01 22:29:56", "enable": 1}]
@@ -0,0 +1,40 @@
[
[237, 1, 1],
[238, 3, 1],
[239, 4, 1],
[240, 9, 1],
[241, 12, 1],
[242, 13, 1],
[243, 17, 1],
[244, 18, 1],
[245, 21, 1],
[246, 22, 1],
[247, 23, 1],
[248, 24, 1],
[249, 25, 1],
[250, 26, 1],
[251, 27, 1],
[252, 28, 1],
[253, 29, 1],
[254, 30, 1],
[255, 31, 1],
[256, 32, 1],
[257, 44, 1],
[258, 45, 1],
[259, 46, 1],
[260, 47, 1],
[261, 48, 1],
[262, 49, 1],
[263, 50, 1],
[264, 51, 1],
[265, 1, 2],
[266, 3, 2],
[267, 4, 2],
[268, 9, 2],
[269, 12, 2],
[270, 13, 2],
[271, 17, 2],
[272, 18, 2],
[273, 44, 2],
[274, 48, 2]
]
@@ -0,0 +1,5 @@
[
[21, 1, 1],
[22, 7, 2],
[24, 8, 2]
]
+3 -1
View File
@@ -11,5 +11,7 @@ def init_plugs(app: Flask) -> None:
init_login_manager(app)
init_databases(app)
init_template_directives(app)
# init_error_views(app)
init_error_views(app)
# 生成测试数据的命令,生成环境可以注释
register_script(app)
@@ -5,12 +5,12 @@ from datetime import datetime
date_str = re.compile('\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d$')
def add_data(fields, data_list, obj):
def add_data(data_list, obj):
from applications.extensions import db
for _data in data_list:
dept = obj()
for key, value in dict(zip(fields, _data)).items():
for key, value in _data.items():
if isinstance(value, str) and date_str.match(value):
value = datetime.strptime(value, "%Y-%m-%d %H:%M:%S")
@@ -20,253 +20,53 @@ def add_data(fields, data_list, obj):
db.session.commit()
def create_dept_data():
"""创建化部门数据"""
from applications.models import Dept
_data_list = [
(1, 0, '总公司', 1, '就眠仪式', '12312345679', '123qq.com', 1, None, '这是总公司', None, '2021-06-01 17:23:20'),
(4, 1, '济南分公司', 2, '就眠仪式', '12312345678', '1234qq.com', 1, None, '这是济南', '2021-06-01 17:24:33',
'2021-06-01 17:25:19'),
(5, 1, '唐山分公司', 4, 'mkg', '12312345678', '123@qq.com', 1, None, '这是唐山', '2021-06-01 17:25:15',
'2021-06-01 17:25:20'),
(7, 4, '济南分公司开发部', 5, '就眠仪式', '12312345678', '123@qq.com', 1, None, '测试', '2021-06-01 17:27:39',
'2021-06-01 17:27:39'),
(8, 5, '唐山测试部', 6, 'mkg', '12312345678', '123@qq.com', 1, None, '测试部', '2021-06-01 17:28:27',
'2021-06-01 17:28:27'),
]
_fields = ['id', 'parent_id', 'dept_name', 'sort', 'leader', 'phone', 'email', 'status', 'remark', 'address',
'create_at', 'update_at']
_data_list = [item for item in _data_list]
add_data(_fields, _data_list, Dept)
def create_admin_photo():
from applications.models import Photo
_fields = [
'id',
'name',
'href',
'mime',
'size',
'create_time',
]
_data_list = [
(3, '6958819_pear-admin_1607443454_1.png',
'http://127.0.0.1:5000/_uploads/photos/6958819_pear-admin_1607443454_1.png', 'image/png', '2204',
'2021-03-19 18:53:02'),
(17, '1617291580000.jpg', 'http://127.0.0.1:5000/_uploads/photos/1617291580000.jpg', 'image/png', '94211',
'2021-04-01 23:39:41'),
]
add_data(_fields, _data_list, Photo)
def create_admin_power():
from applications.models import Power
_data_list = \
[
(1, '系统管理', '0', '', None, None, '0', 'layui-icon layui-icon-set-fill', 1, None, None, 1),
(3, '用户管理', '1', 'admin:user:main', '/users/', '_iframe', '1',
'layui-icon layui-icon layui-icon layui-icon layui-icon-rate', 1, None, None, 1),
(4, '权限管理', '1', 'admin:power:main', '/rights/', '_iframe', '1', None, 2, None, None, 1),
(9, '角色管理', '1', 'admin:role:main', '/admin/role', '_iframe', '1', 'layui-icon layui-icon-username', 2,
'2021-03-16 22:24:58', '2021-03-25 19:15:24', 1),
(13, '日志管理', '1', 'admin:log:main', '/logs', '_iframe', '1', 'layui-icon layui-icon-read', 4,
'2021-03-18 22:37:10', '2021-06-03 11:06:25', 1),
(17, '文件管理', '0', '', '', '', '0', 'layui-icon layui-icon-camera', 2, '2021-03-19 18:56:23',
'2021-03-25 19:15:08', 1),
(18, '图片上传', '1', 'admin:file:main', '/file', '_iframe', '17', 'layui-icon layui-icon-camera', 5,
'2021-03-19 18:57:19', '2021-03-25 19:15:13', 1),
(21, '权限增加', '2', 'admin:power:add', '', '', '4', 'layui-icon layui-icon-add-circle', 1,
'2021-03-22 19:43:52',
'2021-03-25 19:15:22', 1),
(22, '用户增加', '2', 'admin:user:add', '', '', '3', 'layui-icon layui-icon-add-circle', 1,
'2021-03-22 19:45:40',
'2021-03-25 19:15:17', 1),
(23, '用户编辑', '2', 'admin:user:edit', '', '', '3', 'layui-icon layui-icon-rate', 2, '2021-03-22 19:46:15',
'2021-03-25 19:15:18', 1),
(24, '用户删除', '2', 'admin:user:remove', '', '', '3', 'layui-icon None', 3, '2021-03-22 19:46:51',
'2021-03-25 19:15:18', 1),
(25, '权限编辑', '2', 'admin:power:edit', '', '', '4', 'layui-icon layui-icon-edit', 2, '2021-03-22 19:47:36',
'2021-03-25 19:15:22', 1),
(26, '用户删除', '2', 'admin:power:remove', '', '', '4', 'layui-icon layui-icon-delete', 3,
'2021-03-22 19:48:17',
'2021-03-25 19:15:23', 1),
(27, '用户增加', '2', 'admin:role:add', '', '', '9', 'layui-icon layui-icon-add-circle', 1,
'2021-03-22 19:49:09',
'2021-03-25 19:15:24', 1),
(28, '角色编辑', '2', 'admin:role:edit', '', '', '9', 'layui-icon layui-icon-edit', 2, '2021-03-22 19:49:41',
'2021-03-25 19:15:25', 1),
(
29, '角色删除', '2', 'admin:role:remove', '', '', '9', 'layui-icon layui-icon-delete', 3,
'2021-03-22 19:50:15',
'2021-03-25 19:15:26', 1),
(30, '角色授权', '2', 'admin:role:power', '', '', '9', 'layui-icon layui-icon-component', 4,
'2021-03-22 19:50:54',
'2021-03-25 19:15:26', 1),
(31, '图片增加', '2', 'admin:file:add', '', '', '18', 'layui-icon layui-icon-add-circle', 1,
'2021-03-22 19:58:05',
'2021-03-25 19:15:28', 1),
(32, '图片删除', '2', 'admin:file:delete', '', '', '18', 'layui-icon layui-icon-delete', 2,
'2021-03-22 19:58:45',
'2021-03-25 19:15:29', 1),
(48, '部门管理', '1', 'admin:dept:main', '/dept', '_iframe', '1', 'layui-icon layui-icon-group', 3,
'2021-06-01 16:22:11', '2021-06-01 16:22:11', 1),
(49, '部门增加', '2', 'admin:dept:add', '', '', '48', 'layui-icon None', 1, '2021-06-01 17:35:52',
'2021-06-01 17:36:15', 1),
(50, '部门编辑', '2', 'admin:dept:edit', '', '', '48', 'layui-icon ', 2, '2021-06-01 17:36:41',
'2021-06-01 17:36:41', 1),
(51, '部门删除', '2', 'admin:dept:remove', '', '', '48', 'layui-icon None', 3, '2021-06-01 17:37:15',
'2021-06-01 17:37:26', 1),
]
_fields = [
'id',
'name',
'type',
'code',
'url',
'open_type',
'parent_id',
'icon',
'sort',
'create_time',
'update_time',
'enable',
]
add_data(_fields, _data_list, Power)
def create_admin_role():
from applications.models import Role
_fields = [
'id',
'name',
'code',
'remark',
'details',
'sort',
'create_time',
'update_time',
'enable',
]
_data_list = [
(1, '管理员', 'admin', None, '管理员', 1, None, None, 1),
(2, '普通用户', 'common', None, '只有查看,没有增删改权限', 2, '2021-03-22 20:02:38', '2021-04-01 22:29:56', 1),
]
add_data(_fields, _data_list, Role)
def create_admin_role_power():
from applications.extensions import db
_data_list = [
(237, 1, 1),
(238, 3, 1),
(239, 4, 1),
(240, 9, 1),
(241, 12, 1),
(242, 13, 1),
(243, 17, 1),
(244, 18, 1),
(245, 21, 1),
(246, 22, 1),
(247, 23, 1),
(248, 24, 1),
(249, 25, 1),
(250, 26, 1),
(251, 27, 1),
(252, 28, 1),
(253, 29, 1),
(254, 30, 1),
(255, 31, 1),
(256, 32, 1),
(257, 44, 1),
(258, 45, 1),
(259, 46, 1),
(260, 47, 1),
(261, 48, 1),
(262, 49, 1),
(263, 50, 1),
(264, 51, 1),
(265, 1, 2),
(266, 3, 2),
(267, 4, 2),
(268, 9, 2),
(269, 12, 2),
(270, 13, 2),
(271, 17, 2),
(272, 18, 2),
(273, 44, 2),
(274, 48, 2),
]
# add_data(_fields, _data_list, UserRole)
for data in _data_list:
db.session.execute('insert into rt_role_power VALUES (%s, %s, %s);' % data)
db.session.commit()
def create_admin_user():
from applications.models import User
_fields = [
'id',
'username',
'password_hash',
'create_at',
'update_at',
'enable',
'realname',
'remark',
'avatar',
'dept_id',
]
_data_list = [
(1, 'admin', 'pbkdf2:sha256:150000$raM7mDSr$58fe069c3eac01531fc8af85e6fc200655dd2588090530084d182e6ec9d52c85',
None, '2021-06-01 17:28:55', 1, '超级管理', '要是不能把握时机,就要终身蹭蹬,一事无成!',
'http://127.0.0.1:5000/_uploads/photos/1617291580000.jpg', 1),
(7, 'test', 'pbkdf2:sha256:150000$cRS8bYNh$adb57e64d929863cf159f924f74d0634f1fecc46dba749f1bfaca03da6d2e3ac',
'2021-03-22 20:03:42', '2021-06-01 17:29:47', 1, '超级管理', '要是不能把握时机,就要终身蹭蹬,一事无成',
'/static/admin/admin/images/avatar.jpg', 1),
(8, 'wind', 'pbkdf2:sha256:150000$skME1obT$6a2c20cd29f89d7d2f21d9e373a7e3445f70ebce3ef1c3a555e42a7d17170b37',
'2021-06-01 17:30:39', '2021-06-01 17:30:52', 1, '', None, '/static/admin/admin/images/avatar.jpg', 7),
]
add_data(_fields, _data_list, User)
def create_admin_user_role() -> object:
from applications.extensions import db
_data_list = [
(21, 1, 1),
(22, 7, 2),
(24, 8, 2),
]
# add_data(_fields, _data_list, UserRole)
for data in _data_list:
db.session.execute('insert into rt_user_role VALUES (%s, %s, %s);' % data)
db.session.commit()
def register_script(app: Flask):
@app.cli.command()
def init_db():
"""数据库初始化"""
create_dept_data()
create_admin_photo()
create_admin_power()
create_admin_role()
create_admin_role_power()
create_admin_user()
create_admin_user_role()
# 创建化部门数据
from applications.models import Dept
from applications.configs.init_data import cp_dept_data_list
add_data(cp_dept_data_list, Dept)
# 图片数据
from applications.models import Photo
from applications.configs.init_data import file_photo_data_list
add_data(file_photo_data_list, Photo)
# 初始化权限表数据
from applications.models import Power
from applications.configs.init_data import rt_power_data_list
add_data(rt_power_data_list, Power)
# 初始化角色表
from applications.models import Role
from applications.configs.init_data import rt_role_data_list
# 角色权限关系表
from applications.extensions import db
from applications.configs.init_data import rt_role_power_data_list
for data in rt_role_power_data_list:
db.session.execute('insert into rt_role_power VALUES (%s, %s, %s);' % tuple(data))
db.session.commit()
add_data(rt_role_data_list, Role)
# 管理员用户
from applications.models import User
from applications.configs.init_data import cp_user_data_list
add_data(cp_user_data_list, User)
# 用户角色表
from applications.extensions import db
from applications.configs.init_data import rt_user_role_data_list
for data in rt_user_role_data_list:
db.session.execute('insert into rt_user_role VALUES (%s, %s, %s);' % tuple(data))
db.session.commit()
@app.cli.command()
def turn():
+1 -1
View File
@@ -38,7 +38,7 @@ class Login(Resource):
if user is None:
return fail_api(msg="不存在的用户")
if user.enable is 0:
if user.enable == 0:
return fail_api(msg="用户被暂停使用")
if user.validate_password(req.password):