Add socket notification for status bar updates in FalukantService and enhance model sync by handling VIRTUAL fields in sequelize.js

This commit is contained in:
Torsten Schulz (local)
2025-12-18 15:25:24 +01:00
parent 31c23a0c40
commit a0a7e81927
2 changed files with 27 additions and 2 deletions

View File

@@ -4397,6 +4397,12 @@ class FalukantService extends BaseService {
} }
); );
await transaction.commit(); await transaction.commit();
// Send socket notification to update statusbar
if (count > 0) {
notifyUser(hashedUserId, 'falukantUpdateStatus', {});
}
return { updated: count }; return { updated: count };
} catch (error) { } catch (error) {
await transaction.rollback(); await transaction.rollback();

View File

@@ -417,7 +417,26 @@ const syncModelsAlways = async (models) => {
try { try {
for (const model of Object.values(models)) { for (const model of Object.values(models)) {
await model.sync({ alter: true, force: false }); // Temporarily remove VIRTUAL fields before sync to prevent sync errors
const originalAttributes = model.rawAttributes;
const virtualFields = {};
// Find and temporarily remove VIRTUAL fields
for (const [key, attr] of Object.entries(originalAttributes)) {
if (attr.type && attr.type.constructor && attr.type.constructor.name === 'VIRTUAL') {
virtualFields[key] = attr;
delete model.rawAttributes[key];
}
}
try {
await model.sync({ alter: true, force: false });
} finally {
// Restore VIRTUAL fields after sync
for (const [key, attr] of Object.entries(virtualFields)) {
model.rawAttributes[key] = attr;
}
}
} }
console.log('✅ Schema-Updates für alle Models abgeschlossen'); console.log('✅ Schema-Updates für alle Models abgeschlossen');
} catch (error) { } catch (error) {