Initial commit: 宁夏智慧养殖监管平台
This commit is contained in:
53
backend/check-table-structure.js
Normal file
53
backend/check-table-structure.js
Normal file
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
* 检查并同步数据库表结构脚本
|
||||
*/
|
||||
const { sequelize } = require('./models/index');
|
||||
|
||||
async function checkAndSyncDatabase() {
|
||||
try {
|
||||
console.log('连接数据库...');
|
||||
await sequelize.authenticate();
|
||||
console.log('数据库连接成功');
|
||||
|
||||
// 强制同步数据库(这会删除现有表并重新创建)
|
||||
console.log('\n开始同步数据库模型...');
|
||||
await sequelize.sync({ force: true });
|
||||
console.log('数据库模型同步完成');
|
||||
|
||||
// 检查创建的表
|
||||
console.log('\n=== 检查创建的表 ===');
|
||||
const [tables] = await sequelize.query("SHOW TABLES");
|
||||
console.log('已创建的表:', tables.map(row => Object.values(row)[0]));
|
||||
|
||||
// 检查devices表结构
|
||||
console.log('\n=== devices表结构 ===');
|
||||
const [devicesFields] = await sequelize.query("DESCRIBE devices");
|
||||
console.log('devices表字段:');
|
||||
devicesFields.forEach(field => {
|
||||
console.log(`- ${field.Field}: ${field.Type} (${field.Null === 'YES' ? 'NULL' : 'NOT NULL'})`);
|
||||
});
|
||||
|
||||
// 检查animals表结构
|
||||
console.log('\n=== animals表结构 ===');
|
||||
const [animalsFields] = await sequelize.query("DESCRIBE animals");
|
||||
console.log('animals表字段:');
|
||||
animalsFields.forEach(field => {
|
||||
console.log(`- ${field.Field}: ${field.Type} (${field.Null === 'YES' ? 'NULL' : 'NOT NULL'})`);
|
||||
});
|
||||
|
||||
// 检查alerts表结构
|
||||
console.log('\n=== alerts表结构 ===');
|
||||
const [alertsFields] = await sequelize.query("DESCRIBE alerts");
|
||||
console.log('alerts表字段:');
|
||||
alertsFields.forEach(field => {
|
||||
console.log(`- ${field.Field}: ${field.Type} (${field.Null === 'YES' ? 'NULL' : 'NOT NULL'})`);
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
console.error('操作失败:', error);
|
||||
} finally {
|
||||
await sequelize.close();
|
||||
}
|
||||
}
|
||||
|
||||
checkAndSyncDatabase();
|
||||
Reference in New Issue
Block a user