feat(backend): Hinzufügen der Datenbank-Synchronisation zum Deployment-Skript
- Implementierung eines neuen Skripts zur Datenbank-Synchronisation im deploy-backend.sh. - Hinzufügen eines npm-Skripts "sync-db" in package.json zur Ausführung der Synchronisation. - Verbesserung des Deployment-Prozesses durch automatisierte Datenbankaktualisierungen.
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
"scripts": {
|
||||
"start": "node server.js",
|
||||
"dev": "NODE_ENV=development node server.js",
|
||||
"sync-db": "node sync-database.js",
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"keywords": [],
|
||||
|
||||
37
backend/sync-database.js
Normal file
37
backend/sync-database.js
Normal file
@@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
/**
|
||||
* Datenbank-Synchronisations-Script
|
||||
* Führt Schema-Updates und Constraint-Bereinigung durch
|
||||
*/
|
||||
|
||||
import './config/loadEnv.js';
|
||||
import { syncDatabase } from './utils/syncDatabase.js';
|
||||
import { cleanupDatabaseConstraints } from './utils/cleanupDatabaseConstraints.js';
|
||||
|
||||
console.log('🗄️ Starte Datenbank-Synchronisation...');
|
||||
|
||||
async function main() {
|
||||
try {
|
||||
// 1. Datenbank-Synchronisation
|
||||
console.log('📊 Führe Datenbank-Synchronisation durch...');
|
||||
await syncDatabase();
|
||||
console.log('✅ Datenbank-Synchronisation erfolgreich abgeschlossen');
|
||||
|
||||
// 2. Constraint-Bereinigung
|
||||
console.log('🧹 Räume Datenbank-Constraints auf...');
|
||||
await cleanupDatabaseConstraints();
|
||||
console.log('✅ Constraint-Bereinigung erfolgreich abgeschlossen');
|
||||
|
||||
console.log('🎉 Alle Datenbank-Operationen erfolgreich abgeschlossen!');
|
||||
process.exit(0);
|
||||
|
||||
} catch (error) {
|
||||
console.error('❌ Fehler bei der Datenbank-Synchronisation:', error);
|
||||
console.error('Stack Trace:', error.stack);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
// Script ausführen
|
||||
main();
|
||||
@@ -27,4 +27,9 @@ if [ -f .env ]; then
|
||||
sudo chmod 600 /opt/yourpart/backend/.env
|
||||
fi
|
||||
|
||||
# Datenbank-Synchronisation durchführen
|
||||
echo "Running database synchronization..."
|
||||
cd /opt/yourpart/backend
|
||||
sudo -u www-data npm run sync-db
|
||||
|
||||
echo "Backend deployment completed!"
|
||||
|
||||
Reference in New Issue
Block a user