完善保险前后端、养殖端小程序
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = {
|
||||
up: async (queryInterface, Sequelize) => {
|
||||
await queryInterface.addColumn('users', 'fixed_token', {
|
||||
type: Sequelize.STRING(255),
|
||||
allowNull: true,
|
||||
unique: true,
|
||||
comment: '用户固定token,用于API访问验证'
|
||||
});
|
||||
},
|
||||
|
||||
down: async (queryInterface, Sequelize) => {
|
||||
await queryInterface.removeColumn('users', 'fixed_token');
|
||||
}
|
||||
};
|
||||
@@ -1,75 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = {
|
||||
up: async (queryInterface, Sequelize) => {
|
||||
// 添加参保类型字段
|
||||
await queryInterface.addColumn('insurance_applications', 'insurance_category', {
|
||||
type: Sequelize.STRING(50),
|
||||
allowNull: true,
|
||||
comment: '参保类型(如:牛、羊、猪等)',
|
||||
after: 'insurance_type_id'
|
||||
});
|
||||
|
||||
// 添加申请数量字段
|
||||
await queryInterface.addColumn('insurance_applications', 'application_quantity', {
|
||||
type: Sequelize.INTEGER,
|
||||
allowNull: true,
|
||||
defaultValue: 1,
|
||||
comment: '申请数量',
|
||||
validate: {
|
||||
min: 1
|
||||
},
|
||||
after: 'insurance_category'
|
||||
});
|
||||
|
||||
// 添加备注字段
|
||||
await queryInterface.addColumn('insurance_applications', 'remarks', {
|
||||
type: Sequelize.TEXT,
|
||||
allowNull: true,
|
||||
comment: '备注信息',
|
||||
after: 'review_notes'
|
||||
});
|
||||
|
||||
// 更新状态枚举值以匹配UI显示
|
||||
await queryInterface.changeColumn('insurance_applications', 'status', {
|
||||
type: Sequelize.ENUM(
|
||||
'pending', // 待初审
|
||||
'initial_approved', // 初审通过待复核
|
||||
'under_review', // 已支付待复核
|
||||
'approved', // 已支付
|
||||
'rejected', // 已拒绝
|
||||
'paid' // 已支付
|
||||
),
|
||||
allowNull: false,
|
||||
defaultValue: 'pending',
|
||||
comment: '申请状态'
|
||||
});
|
||||
|
||||
// 添加索引
|
||||
await queryInterface.addIndex('insurance_applications', ['insurance_category'], {
|
||||
name: 'idx_insurance_applications_category'
|
||||
});
|
||||
|
||||
await queryInterface.addIndex('insurance_applications', ['application_quantity'], {
|
||||
name: 'idx_insurance_applications_quantity'
|
||||
});
|
||||
},
|
||||
|
||||
down: async (queryInterface, Sequelize) => {
|
||||
// 移除索引
|
||||
await queryInterface.removeIndex('insurance_applications', 'idx_insurance_applications_category');
|
||||
await queryInterface.removeIndex('insurance_applications', 'idx_insurance_applications_quantity');
|
||||
|
||||
// 移除添加的字段
|
||||
await queryInterface.removeColumn('insurance_applications', 'insurance_category');
|
||||
await queryInterface.removeColumn('insurance_applications', 'application_quantity');
|
||||
await queryInterface.removeColumn('insurance_applications', 'remarks');
|
||||
|
||||
// 恢复原始状态枚举
|
||||
await queryInterface.changeColumn('insurance_applications', 'status', {
|
||||
type: Sequelize.ENUM('pending', 'approved', 'rejected', 'under_review'),
|
||||
allowNull: false,
|
||||
defaultValue: 'pending'
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,109 @@
|
||||
'use strict';
|
||||
|
||||
/** @type {import('sequelize-cli').Migration} */
|
||||
module.exports = {
|
||||
async up(queryInterface, Sequelize) {
|
||||
// 创建权限表
|
||||
await queryInterface.createTable('permissions', {
|
||||
id: {
|
||||
type: Sequelize.INTEGER,
|
||||
autoIncrement: true,
|
||||
primaryKey: true,
|
||||
comment: '权限ID'
|
||||
},
|
||||
name: {
|
||||
type: Sequelize.STRING(100),
|
||||
allowNull: false,
|
||||
comment: '权限名称'
|
||||
},
|
||||
code: {
|
||||
type: Sequelize.STRING(100),
|
||||
allowNull: false,
|
||||
unique: true,
|
||||
comment: '权限代码'
|
||||
},
|
||||
description: {
|
||||
type: Sequelize.TEXT,
|
||||
allowNull: true,
|
||||
comment: '权限描述'
|
||||
},
|
||||
module: {
|
||||
type: Sequelize.STRING(50),
|
||||
allowNull: false,
|
||||
comment: '所属模块'
|
||||
},
|
||||
type: {
|
||||
type: Sequelize.ENUM('menu', 'operation'),
|
||||
allowNull: false,
|
||||
defaultValue: 'operation',
|
||||
comment: '权限类型:menu-菜单权限,operation-操作权限'
|
||||
},
|
||||
parent_id: {
|
||||
type: Sequelize.INTEGER,
|
||||
allowNull: true,
|
||||
comment: '父权限ID',
|
||||
references: {
|
||||
model: 'permissions',
|
||||
key: 'id'
|
||||
},
|
||||
onUpdate: 'CASCADE',
|
||||
onDelete: 'SET NULL'
|
||||
},
|
||||
status: {
|
||||
type: Sequelize.ENUM('active', 'inactive'),
|
||||
allowNull: false,
|
||||
defaultValue: 'active',
|
||||
comment: '状态'
|
||||
},
|
||||
sort_order: {
|
||||
type: Sequelize.INTEGER,
|
||||
allowNull: false,
|
||||
defaultValue: 0,
|
||||
comment: '排序'
|
||||
},
|
||||
created_at: {
|
||||
type: Sequelize.DATE,
|
||||
allowNull: false,
|
||||
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'),
|
||||
comment: '创建时间'
|
||||
},
|
||||
updated_at: {
|
||||
type: Sequelize.DATE,
|
||||
allowNull: false,
|
||||
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'),
|
||||
comment: '更新时间'
|
||||
}
|
||||
}, {
|
||||
comment: '权限表'
|
||||
});
|
||||
|
||||
// 创建索引
|
||||
await queryInterface.addIndex('permissions', ['code'], {
|
||||
name: 'idx_permissions_code'
|
||||
});
|
||||
await queryInterface.addIndex('permissions', ['module'], {
|
||||
name: 'idx_permissions_module'
|
||||
});
|
||||
await queryInterface.addIndex('permissions', ['type'], {
|
||||
name: 'idx_permissions_type'
|
||||
});
|
||||
await queryInterface.addIndex('permissions', ['parent_id'], {
|
||||
name: 'idx_permissions_parent_id'
|
||||
});
|
||||
await queryInterface.addIndex('permissions', ['status'], {
|
||||
name: 'idx_permissions_status'
|
||||
});
|
||||
},
|
||||
|
||||
async down(queryInterface, Sequelize) {
|
||||
// 删除索引
|
||||
await queryInterface.removeIndex('permissions', 'idx_permissions_code');
|
||||
await queryInterface.removeIndex('permissions', 'idx_permissions_module');
|
||||
await queryInterface.removeIndex('permissions', 'idx_permissions_type');
|
||||
await queryInterface.removeIndex('permissions', 'idx_permissions_parent_id');
|
||||
await queryInterface.removeIndex('permissions', 'idx_permissions_status');
|
||||
|
||||
// 删除表
|
||||
await queryInterface.dropTable('permissions');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,82 @@
|
||||
'use strict';
|
||||
|
||||
/** @type {import('sequelize-cli').Migration} */
|
||||
module.exports = {
|
||||
async up(queryInterface, Sequelize) {
|
||||
// 创建角色权限关联表
|
||||
await queryInterface.createTable('role_permissions', {
|
||||
id: {
|
||||
type: Sequelize.INTEGER,
|
||||
autoIncrement: true,
|
||||
primaryKey: true,
|
||||
comment: '关联ID'
|
||||
},
|
||||
role_id: {
|
||||
type: Sequelize.INTEGER,
|
||||
allowNull: false,
|
||||
comment: '角色ID',
|
||||
references: {
|
||||
model: 'roles',
|
||||
key: 'id'
|
||||
},
|
||||
onUpdate: 'CASCADE',
|
||||
onDelete: 'CASCADE'
|
||||
},
|
||||
permission_id: {
|
||||
type: Sequelize.INTEGER,
|
||||
allowNull: false,
|
||||
comment: '权限ID',
|
||||
references: {
|
||||
model: 'permissions',
|
||||
key: 'id'
|
||||
},
|
||||
onUpdate: 'CASCADE',
|
||||
onDelete: 'CASCADE'
|
||||
},
|
||||
granted: {
|
||||
type: Sequelize.BOOLEAN,
|
||||
allowNull: false,
|
||||
defaultValue: true,
|
||||
comment: '是否授权'
|
||||
},
|
||||
created_at: {
|
||||
type: Sequelize.DATE,
|
||||
allowNull: false,
|
||||
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'),
|
||||
comment: '创建时间'
|
||||
},
|
||||
updated_at: {
|
||||
type: Sequelize.DATE,
|
||||
allowNull: false,
|
||||
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'),
|
||||
comment: '更新时间'
|
||||
}
|
||||
}, {
|
||||
comment: '角色权限关联表'
|
||||
});
|
||||
|
||||
// 创建唯一索引
|
||||
await queryInterface.addIndex('role_permissions', ['role_id', 'permission_id'], {
|
||||
name: 'uk_role_permission',
|
||||
unique: true
|
||||
});
|
||||
|
||||
// 创建普通索引
|
||||
await queryInterface.addIndex('role_permissions', ['role_id'], {
|
||||
name: 'idx_role_permissions_role_id'
|
||||
});
|
||||
await queryInterface.addIndex('role_permissions', ['permission_id'], {
|
||||
name: 'idx_role_permissions_permission_id'
|
||||
});
|
||||
},
|
||||
|
||||
async down(queryInterface, Sequelize) {
|
||||
// 删除索引
|
||||
await queryInterface.removeIndex('role_permissions', 'uk_role_permission');
|
||||
await queryInterface.removeIndex('role_permissions', 'idx_role_permissions_role_id');
|
||||
await queryInterface.removeIndex('role_permissions', 'idx_role_permissions_permission_id');
|
||||
|
||||
// 删除表
|
||||
await queryInterface.dropTable('role_permissions');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,82 @@
|
||||
'use strict';
|
||||
|
||||
/** @type {import('sequelize-cli').Migration} */
|
||||
module.exports = {
|
||||
async up(queryInterface, Sequelize) {
|
||||
// 创建菜单权限关联表
|
||||
await queryInterface.createTable('menu_permissions', {
|
||||
id: {
|
||||
type: Sequelize.INTEGER,
|
||||
autoIncrement: true,
|
||||
primaryKey: true,
|
||||
comment: '关联ID'
|
||||
},
|
||||
menu_id: {
|
||||
type: Sequelize.INTEGER,
|
||||
allowNull: false,
|
||||
comment: '菜单ID',
|
||||
references: {
|
||||
model: 'menus',
|
||||
key: 'id'
|
||||
},
|
||||
onUpdate: 'CASCADE',
|
||||
onDelete: 'CASCADE'
|
||||
},
|
||||
permission_id: {
|
||||
type: Sequelize.INTEGER,
|
||||
allowNull: false,
|
||||
comment: '权限ID',
|
||||
references: {
|
||||
model: 'permissions',
|
||||
key: 'id'
|
||||
},
|
||||
onUpdate: 'CASCADE',
|
||||
onDelete: 'CASCADE'
|
||||
},
|
||||
required: {
|
||||
type: Sequelize.BOOLEAN,
|
||||
allowNull: false,
|
||||
defaultValue: true,
|
||||
comment: '是否必需权限'
|
||||
},
|
||||
created_at: {
|
||||
type: Sequelize.DATE,
|
||||
allowNull: false,
|
||||
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'),
|
||||
comment: '创建时间'
|
||||
},
|
||||
updated_at: {
|
||||
type: Sequelize.DATE,
|
||||
allowNull: false,
|
||||
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'),
|
||||
comment: '更新时间'
|
||||
}
|
||||
}, {
|
||||
comment: '菜单权限关联表'
|
||||
});
|
||||
|
||||
// 创建唯一索引
|
||||
await queryInterface.addIndex('menu_permissions', ['menu_id', 'permission_id'], {
|
||||
name: 'uk_menu_permission',
|
||||
unique: true
|
||||
});
|
||||
|
||||
// 创建普通索引
|
||||
await queryInterface.addIndex('menu_permissions', ['menu_id'], {
|
||||
name: 'idx_menu_permissions_menu_id'
|
||||
});
|
||||
await queryInterface.addIndex('menu_permissions', ['permission_id'], {
|
||||
name: 'idx_menu_permissions_permission_id'
|
||||
});
|
||||
},
|
||||
|
||||
async down(queryInterface, Sequelize) {
|
||||
// 删除索引
|
||||
await queryInterface.removeIndex('menu_permissions', 'uk_menu_permission');
|
||||
await queryInterface.removeIndex('menu_permissions', 'idx_menu_permissions_menu_id');
|
||||
await queryInterface.removeIndex('menu_permissions', 'idx_menu_permissions_permission_id');
|
||||
|
||||
// 删除表
|
||||
await queryInterface.dropTable('menu_permissions');
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user