纳入范围: - backend/ Spring Boot 多模块后端(iot-common/device/rule/data/alarm/auth) - frontend/admin/ Vue3 + Element Plus 管理后台 - Android/ 涂鸦原生 APP (com.xhai.iot) - backend/sql/ Flyway 风格迁移脚本(V2~V21) - docs/ 对接文档与设计文档 排除范围: - 构建产物: node_modules/ target/ build/ dist/ .gradle/ - 签名密钥: *.jks *.keystore (严禁入库) - 本机配置: Android/local.properties - 运行日志: logs/ *.log - AI 协作本地数据 .codebuddy/ 与第三方 demo tuya-demo/ .gitattributes 统一以 LF 存储, Windows 批处理保留 CRLF
47 lines
1.6 KiB
JavaScript
47 lines
1.6 KiB
JavaScript
const mysql = require('mysql2/promise');
|
|
|
|
(async () => {
|
|
const conn = await mysql.createConnection({
|
|
host: 'localhost', port: 33060,
|
|
user: 'root', password: 'root', database: 'iot_platform'
|
|
});
|
|
|
|
// 检查所有表是否缺少 create_by 和 update_by 列
|
|
const [tables] = await conn.query(
|
|
`SELECT TABLE_NAME FROM information_schema.TABLES
|
|
WHERE TABLE_SCHEMA='iot_platform'
|
|
AND TABLE_NAME IN ('alarm','alarm_rule','device','device_data_record',
|
|
'device_credential','device_group','linkage_rule','sys_role')`
|
|
);
|
|
|
|
console.log('=== 检查并修复缺失的列 ===\n');
|
|
|
|
for (const t of tables) {
|
|
const tableName = t.TABLE_NAME;
|
|
const [cols] = await conn.query(
|
|
`SELECT COLUMN_NAME FROM information_schema.COLUMNS
|
|
WHERE TABLE_SCHEMA='iot_platform' AND TABLE_NAME='${tableName}'`
|
|
);
|
|
const colNames = cols.map(c => c.COLUMN_NAME);
|
|
|
|
const fixes = [];
|
|
if (!colNames.includes('create_by')) {
|
|
await conn.query(`ALTER TABLE ${tableName} ADD COLUMN create_by bigint NULL COMMENT '创建人ID' AFTER deleted`);
|
|
fixes.push('create_by');
|
|
}
|
|
if (!colNames.includes('update_by')) {
|
|
await conn.query(`ALTER TABLE ${tableName} ADD COLUMN update_by bigint NULL COMMENT '更新人ID' AFTER create_by`);
|
|
fixes.push('update_by');
|
|
}
|
|
|
|
if (fixes.length > 0) {
|
|
console.log(`✅ ${tableName}: 添加了 ${fixes.join(', ')}`);
|
|
} else {
|
|
console.log(`✅ ${tableName}: 列完整`);
|
|
}
|
|
}
|
|
|
|
console.log('\n修复完成!');
|
|
await conn.end();
|
|
})().catch(e => console.error('错误:', e.message));
|