Add sync-tables script to package.json for table synchronization
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
"dev": "NODE_ENV=development node server.js",
|
||||
"start-daemon": "node daemonServer.js",
|
||||
"sync-db": "node sync-database.js",
|
||||
"sync-tables": "node sync-tables-only.js",
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"keywords": [],
|
||||
|
||||
43
backend/sync-tables-only.js
Normal file
43
backend/sync-tables-only.js
Normal file
@@ -0,0 +1,43 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
/**
|
||||
* Einfaches Script zum Erstellen/Aktualisieren von Tabellen
|
||||
* Ohne Cleanup und Initialisierung
|
||||
*/
|
||||
|
||||
import './config/loadEnv.js';
|
||||
import { initializeDatabase, syncModelsAlways, sequelize } from './utils/sequelize.js';
|
||||
import setupAssociations from './models/associations.js';
|
||||
import models from './models/index.js';
|
||||
|
||||
console.log('🗄️ Starte Tabellen-Synchronisation (nur Schema-Updates)...');
|
||||
|
||||
async function main() {
|
||||
try {
|
||||
// 1. Datenbank-Schemas initialisieren
|
||||
console.log('📊 Initialisiere Datenbank-Schemas...');
|
||||
await initializeDatabase();
|
||||
console.log('✅ Datenbank-Schemas initialisiert');
|
||||
|
||||
// 2. Associations setzen
|
||||
console.log('🔗 Setze Associations...');
|
||||
setupAssociations();
|
||||
console.log('✅ Associations gesetzt');
|
||||
|
||||
// 3. Nur Tabellen synchronisieren (ohne Cleanup, ohne Initialisierung)
|
||||
console.log('🔄 Synchronisiere Tabellen...');
|
||||
await syncModelsAlways(models);
|
||||
console.log('✅ Tabellen-Synchronisation erfolgreich abgeschlossen');
|
||||
|
||||
console.log('🎉 Tabellen-Synchronisation abgeschlossen!');
|
||||
process.exit(0);
|
||||
|
||||
} catch (error) {
|
||||
console.error('❌ Fehler bei der Tabellen-Synchronisation:', error);
|
||||
console.error('Stack Trace:', error.stack);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
// Script ausführen
|
||||
main();
|
||||
Reference in New Issue
Block a user