Files
yunrui_asset/backend/scripts/add-isSystem-sqlite.js
T
zhang1106 bfc5b75b1a fix: 优化生产环境前端端口显示逻辑
- 检测是否为生产环境(通过检查dist目录)
- 生产环境显示Nginx配置提示,不自动重启
- 开发环境保持自动重启功能
- 区分显示生产环境和开发环境状态
2026-02-05 11:00:42 +08:00

50 lines
1.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
const { sequelize } = require('../db');
async function migrate() {
try {
console.log('开始 SQLite 数据库迁移...');
// 检查列是否存在(SQLite 使用 PRAGMA
const tableInfo = await sequelize.query(
"PRAGMA table_info(deviceFields)",
{ type: sequelize.QueryTypes.SELECT }
);
const hasIsSystemColumn = tableInfo.some(col => col.name === 'isSystem');
if (!hasIsSystemColumn) {
// 添加 isSystem 列
await sequelize.query(
"ALTER TABLE deviceFields ADD COLUMN isSystem BOOLEAN DEFAULT 0",
{ type: sequelize.QueryTypes.RAW }
);
console.log('isSystem 列添加成功');
} else {
console.log('isSystem 列已存在');
}
// 更新系统字段标记
const systemFields = [
'deviceId', 'name', 'type', 'model', 'serialNumber',
'rackId', 'position', 'height', 'powerConsumption',
'status', 'purchaseDate', 'warrantyExpiry'
];
for (const fieldName of systemFields) {
await sequelize.query(
`UPDATE deviceFields SET isSystem = 1 WHERE fieldName = '${fieldName}'`,
{ type: sequelize.QueryTypes.RAW }
);
console.log(`标记系统字段: ${fieldName}`);
}
console.log('迁移完成!');
process.exit(0);
} catch (error) {
console.error('迁移失败:', error);
process.exit(1);
}
}
migrate();