Add cleanup for orphaned notification entries in syncDatabase functions to remove invalid user_id references, improving data integrity and logging consistency.
This commit is contained in:
@@ -96,7 +96,19 @@ const syncDatabase = async () => {
|
||||
console.log(`✅ ${deletedCount3} verwaiste knowledge Einträge entfernt`);
|
||||
}
|
||||
|
||||
if (deletedCount1 === 0 && deletedCount2 === 0 && deletedCount3 === 0) {
|
||||
// Cleanup notification mit ungültigen user_id
|
||||
const result4 = await sequelize.query(`
|
||||
DELETE FROM falukant_log.notification
|
||||
WHERE user_id NOT IN (
|
||||
SELECT id FROM falukant_data.falukant_user
|
||||
);
|
||||
`);
|
||||
const deletedCount4 = result4[1] || 0;
|
||||
if (deletedCount4 > 0) {
|
||||
console.log(`✅ ${deletedCount4} verwaiste notification Einträge entfernt`);
|
||||
}
|
||||
|
||||
if (deletedCount1 === 0 && deletedCount2 === 0 && deletedCount3 === 0 && deletedCount4 === 0) {
|
||||
console.log("✅ Keine verwaisten Einträge gefunden");
|
||||
}
|
||||
} catch (e) {
|
||||
@@ -263,7 +275,19 @@ const syncDatabaseForDeployment = async () => {
|
||||
console.log(`✅ ${deletedCount3} verwaiste knowledge Einträge entfernt`);
|
||||
}
|
||||
|
||||
if (deletedCount1 === 0 && deletedCount2 === 0 && deletedCount3 === 0) {
|
||||
// Cleanup notification mit ungültigen user_id
|
||||
const result4 = await sequelize.query(`
|
||||
DELETE FROM falukant_log.notification
|
||||
WHERE user_id NOT IN (
|
||||
SELECT id FROM falukant_data.falukant_user
|
||||
);
|
||||
`);
|
||||
const deletedCount4 = result4[1] || 0;
|
||||
if (deletedCount4 > 0) {
|
||||
console.log(`✅ ${deletedCount4} verwaiste notification Einträge entfernt`);
|
||||
}
|
||||
|
||||
if (deletedCount1 === 0 && deletedCount2 === 0 && deletedCount3 === 0 && deletedCount4 === 0) {
|
||||
console.log("✅ Keine verwaisten Einträge gefunden");
|
||||
}
|
||||
} catch (e) {
|
||||
|
||||
Reference in New Issue
Block a user