Files
nxxmdata/backend/check-farms-sql.js
2025-08-25 15:00:46 +08:00

48 lines
1.6 KiB
JavaScript

const { sequelize } = require('./config/database-simple');
async function checkFarmsSQL() {
try {
console.log('检查farms表状态...');
// 检查表是否存在
const tables = await sequelize.query("SHOW TABLES LIKE 'farms'");
console.log('farms表存在:', tables[0].length > 0);
if (tables[0].length > 0) {
// 检查记录数
const count = await sequelize.query('SELECT COUNT(*) as count FROM farms');
console.log('farms表记录数:', count[0][0].count);
// 如果有记录,显示所有记录
if (count[0][0].count > 0) {
const farms = await sequelize.query('SELECT * FROM farms ORDER BY id ASC');
console.log('farms表数据:');
farms[0].forEach(farm => {
console.log(`ID: ${farm.id}, Name: ${farm.name}`);
});
}
// 检查临时表是否还存在
const tempTables = await sequelize.query("SHOW TABLES LIKE 'farms_temp'");
console.log('farms_temp表存在:', tempTables[0].length > 0);
if (tempTables[0].length > 0) {
const tempCount = await sequelize.query('SELECT COUNT(*) as count FROM farms_temp');
console.log('farms_temp表记录数:', tempCount[0][0].count);
if (tempCount[0][0].count > 0) {
const tempFarms = await sequelize.query('SELECT * FROM farms_temp ORDER BY id ASC');
console.log('farms_temp表数据:');
tempFarms[0].forEach(farm => {
console.log(`ID: ${farm.id}, Name: ${farm.name}`);
});
}
}
}
} catch (error) {
console.error('检查失败:', error.message);
}
}
checkFarmsSQL();