update
All checks were successful
Deploy to Production / deploy (push) Successful in 20s

This commit is contained in:
vuongps38770
2026-02-28 20:00:38 +07:00
parent f96833a7e4
commit 72283443ab
15 changed files with 972 additions and 318 deletions

View File

@@ -0,0 +1,53 @@
const { Context } = require('../models');
const { Op } = require('sequelize');
const { sequelize } = require('../config/database');
async function checkNullRefId() {
try {
await sequelize.authenticate();
console.log('✅ Kết nối database thành công.');
// Kiểm tra tất cả các bản ghi có reference_id là null hoặc chuỗi rỗng
const nullRefCount = await Context.count({
where: {
[Op.or]: [
{ reference_id: null },
{ reference_id: '' }
]
}
});
const totalCount = await Context.count();
// Thêm thống kê theo status để dễ hình dung
const statsByStatus = await Context.findAll({
attributes: ['status', [sequelize.fn('COUNT', sequelize.col('uuid')), 'count']],
where: {
[Op.or]: [
{ reference_id: null },
{ reference_id: '' }
]
},
group: ['status']
});
console.log('\n--- KẾT QUẢ KIỂM TRA REFERENCE_ID ---');
console.log(`📊 Tổng số bản ghi trong bảng: ${totalCount}`);
console.log(`❌ Số bản ghi có reference_id bị NULL/Trống: ${nullRefCount}`);
console.log(`📈 Tỷ lệ lỗi: ${((nullRefCount / totalCount) * 100).toFixed(2)}%`);
if (statsByStatus.length > 0) {
console.log('\nPhân loại theo Status:');
statsByStatus.forEach(stat => {
console.log(` - Status ${stat.get('status')}: ${stat.get('count')} bản ghi`);
});
}
process.exit(0);
} catch (error) {
console.error('❌ Lỗi khi kiểm tra:', error);
process.exit(1);
}
}
checkNullRefId();