44 lines
1.1 KiB
JavaScript
44 lines
1.1 KiB
JavaScript
|
|
/**
|
||
|
|
* 更新动物健康状态枚举值
|
||
|
|
* 添加 'treatment' 状态到现有的 ENUM 类型
|
||
|
|
*/
|
||
|
|
|
||
|
|
const { sequelize } = require('./config/database-simple');
|
||
|
|
|
||
|
|
async function updateHealthStatusEnum() {
|
||
|
|
try {
|
||
|
|
console.log('开始更新 health_status 枚举值...');
|
||
|
|
|
||
|
|
// 更新 ENUM 类型,添加 'treatment' 选项
|
||
|
|
await sequelize.query(`
|
||
|
|
ALTER TABLE animals
|
||
|
|
MODIFY COLUMN health_status
|
||
|
|
ENUM('healthy', 'sick', 'quarantine', 'treatment')
|
||
|
|
DEFAULT 'healthy'
|
||
|
|
`);
|
||
|
|
|
||
|
|
console.log('health_status 枚举值更新成功!');
|
||
|
|
console.log('现在支持的状态: healthy, sick, quarantine, treatment');
|
||
|
|
|
||
|
|
} catch (error) {
|
||
|
|
console.error('更新 health_status 枚举值失败:', error);
|
||
|
|
throw error;
|
||
|
|
} finally {
|
||
|
|
await sequelize.close();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// 如果直接运行此脚本
|
||
|
|
if (require.main === module) {
|
||
|
|
updateHealthStatusEnum()
|
||
|
|
.then(() => {
|
||
|
|
console.log('数据库更新完成');
|
||
|
|
process.exit(0);
|
||
|
|
})
|
||
|
|
.catch((error) => {
|
||
|
|
console.error('数据库更新失败:', error);
|
||
|
|
process.exit(1);
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
module.exports = updateHealthStatusEnum;
|