refactor: 统一代码风格并迁移至 ESLint 新配置
style(backend): 格式化模型文件代码 style(frontend): 调整组件代码格式 chore: 删除旧 ESLint 配置并添加新配置 refactor(backend): 重构模型定义语法 style: 统一箭头函数和对象属性简写
This commit is contained in:
@@ -3,34 +3,42 @@ const { sequelize } = require('../db');
|
||||
async function addIsSystemColumn() {
|
||||
try {
|
||||
console.log('开始添加 isSystem 列到 deviceFields 表...');
|
||||
|
||||
|
||||
// 检查列是否已存在
|
||||
const tableInfo = await sequelize.query(
|
||||
"PRAGMA table_info(deviceFields)",
|
||||
{ type: sequelize.QueryTypes.SELECT }
|
||||
);
|
||||
|
||||
const tableInfo = await sequelize.query('PRAGMA table_info(deviceFields)', {
|
||||
type: sequelize.QueryTypes.SELECT,
|
||||
});
|
||||
|
||||
const hasIsSystemColumn = tableInfo.some(col => col.name === 'isSystem');
|
||||
|
||||
|
||||
if (hasIsSystemColumn) {
|
||||
console.log('isSystem 列已存在,跳过添加');
|
||||
} else {
|
||||
// 添加 isSystem 列
|
||||
await sequelize.query(
|
||||
"ALTER TABLE deviceFields ADD COLUMN isSystem BOOLEAN DEFAULT 0",
|
||||
{ type: sequelize.QueryTypes.RAW }
|
||||
);
|
||||
await sequelize.query('ALTER TABLE deviceFields ADD COLUMN isSystem BOOLEAN DEFAULT 0', {
|
||||
type: sequelize.QueryTypes.RAW,
|
||||
});
|
||||
console.log('isSystem 列添加成功');
|
||||
}
|
||||
|
||||
|
||||
// 更新现有数据:将核心字段标记为系统字段
|
||||
const systemFields = [
|
||||
'deviceId', 'name', 'type', 'model', 'serialNumber',
|
||||
'rackId', 'position', 'height', 'powerConsumption',
|
||||
'status', 'purchaseDate', 'warrantyExpiry',
|
||||
'ipAddress', 'description'
|
||||
'deviceId',
|
||||
'name',
|
||||
'type',
|
||||
'model',
|
||||
'serialNumber',
|
||||
'rackId',
|
||||
'position',
|
||||
'height',
|
||||
'powerConsumption',
|
||||
'status',
|
||||
'purchaseDate',
|
||||
'warrantyExpiry',
|
||||
'ipAddress',
|
||||
'description',
|
||||
];
|
||||
|
||||
|
||||
for (const fieldName of systemFields) {
|
||||
await sequelize.query(
|
||||
`UPDATE deviceFields SET isSystem = 1 WHERE fieldName = '${fieldName}'`,
|
||||
@@ -38,7 +46,7 @@ async function addIsSystemColumn() {
|
||||
);
|
||||
}
|
||||
console.log('系统字段标记完成');
|
||||
|
||||
|
||||
console.log('数据库迁移完成');
|
||||
process.exit(0);
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user