62 lines
1.8 KiB
JavaScript
62 lines
1.8 KiB
JavaScript
const sequelize = require('./config/db');
|
||
const { Region, Apartment, Room, Tenant, Contract, Rental } = require('./models');
|
||
|
||
// 检查数据库数据的函数
|
||
async function checkData() {
|
||
try {
|
||
console.log('开始检查数据库数据...');
|
||
|
||
// 检查区域数据
|
||
const regions = await Region.findAll();
|
||
console.log(`区域数据数量: ${regions.length}`);
|
||
regions.forEach(region => {
|
||
console.log(`区域: ${region.name}`);
|
||
});
|
||
|
||
// 检查公寓数据
|
||
const apartments = await Apartment.findAll();
|
||
console.log(`\n公寓数据数量: ${apartments.length}`);
|
||
apartments.forEach(apartment => {
|
||
console.log(`公寓: ${apartment.name}`);
|
||
});
|
||
|
||
// 检查房间数据
|
||
const rooms = await Room.findAll();
|
||
console.log(`\n房间数据数量: ${rooms.length}`);
|
||
rooms.forEach(room => {
|
||
console.log(`房间: ${room.roomNumber}`);
|
||
});
|
||
|
||
// 检查租客数据
|
||
const tenants = await Tenant.findAll();
|
||
console.log(`\n租客数据数量: ${tenants.length}`);
|
||
tenants.forEach(tenant => {
|
||
console.log(`租客: ${tenant.name}`);
|
||
});
|
||
|
||
// 检查合同数据
|
||
const contracts = await Contract.findAll();
|
||
console.log(`\n合同数据数量: ${contracts.length}`);
|
||
contracts.forEach(contract => {
|
||
console.log(`合同 ID: ${contract.id}`);
|
||
});
|
||
|
||
// 检查租房数据
|
||
const rentals = await Rental.findAll();
|
||
console.log(`\n租房数据数量: ${rentals.length}`);
|
||
rentals.forEach(rental => {
|
||
console.log(`租房 ID: ${rental.id}`);
|
||
});
|
||
|
||
console.log('\n数据检查完成!');
|
||
} catch (error) {
|
||
console.error('检查数据时出错:', error);
|
||
} finally {
|
||
// 关闭数据库连接
|
||
await sequelize.close();
|
||
}
|
||
}
|
||
|
||
// 执行检查操作
|
||
checkData();
|