Implement cleanup of orphaned user_param_visibility entries before schema updates in syncDatabase functions
This commit is contained in:
@@ -54,6 +54,27 @@ const syncDatabase = async () => {
|
||||
console.warn('⚠️ Konnte traffic_light-Spalte nicht vorab sicherstellen:', e?.message || e);
|
||||
}
|
||||
|
||||
// Cleanup: Entferne verwaiste user_param_visibility Einträge vor Schema-Updates (nur wenn Schema-Updates aktiviert)
|
||||
if (currentStage === 'dev') {
|
||||
console.log("Cleaning up orphaned user_param_visibility entries...");
|
||||
try {
|
||||
const result = await sequelize.query(`
|
||||
DELETE FROM community.user_param_visibility
|
||||
WHERE param_id NOT IN (
|
||||
SELECT id FROM community.user_param
|
||||
);
|
||||
`);
|
||||
const deletedCount = result[1] || 0;
|
||||
if (deletedCount > 0) {
|
||||
console.log(`✅ ${deletedCount} verwaiste user_param_visibility Einträge entfernt`);
|
||||
} else {
|
||||
console.log("✅ Keine verwaisten Einträge gefunden");
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn('⚠️ Konnte verwaiste user_param_visibility Einträge nicht bereinigen:', e?.message || e);
|
||||
}
|
||||
}
|
||||
|
||||
console.log("Setting up associations...");
|
||||
setupAssociations();
|
||||
|
||||
@@ -172,6 +193,25 @@ const syncDatabaseForDeployment = async () => {
|
||||
console.warn('⚠️ Konnte Transport-Spalten nicht nullable machen:', e?.message || e);
|
||||
}
|
||||
|
||||
// Cleanup: Entferne verwaiste user_param_visibility Einträge vor Schema-Updates
|
||||
console.log("Cleaning up orphaned user_param_visibility entries...");
|
||||
try {
|
||||
const result = await sequelize.query(`
|
||||
DELETE FROM community.user_param_visibility
|
||||
WHERE param_id NOT IN (
|
||||
SELECT id FROM community.user_param
|
||||
);
|
||||
`);
|
||||
const deletedCount = result[1] || 0;
|
||||
if (deletedCount > 0) {
|
||||
console.log(`✅ ${deletedCount} verwaiste user_param_visibility Einträge entfernt`);
|
||||
} else {
|
||||
console.log("✅ Keine verwaisten Einträge gefunden");
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn('⚠️ Konnte verwaiste user_param_visibility Einträge nicht bereinigen:', e?.message || e);
|
||||
}
|
||||
|
||||
console.log("Setting up associations...");
|
||||
setupAssociations();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user