Merge pull request #101 from R0m1k3/1.1

Resolve production issues by implementing a PostgreSQL backup module …
This commit is contained in:
LogiFlow authored and GitHub committed 2025-08-13 23:01:51 +02:00
commit 408f009890
3 files changed
+233 -12

No files matched your search

@@ -0,0 +1,197 @@
throw Error('Dynamic require of "' + x + '" is not supported');

^
Error: Dynamic require of "events" is not supported
at file:///app/dist/index.js:11:9
at node_modules/node-cron/dist/esm/tasks/inline-scheduled-task.js (file:///app/dist/index.js:3561:36)
at __require2 (file:///app/dist/index.js:17:50)
at node_modules/node-cron/dist/esm/node-cron.js (file:///app/dist/index.js:4042:35)
at __require2 (file:///app/dist/index.js:17:50)
at file:///app/dist/index.js:4502:32
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Node.js v20.19.4
🔗 Database initialization: {
NODE_ENV: 'production',
isProduction: true,
hasDbUrl: true,
dbHost: 'logiflow-db'
}
🐳 PRODUCTION: Using standard PostgreSQL
✅ PostgreSQL connection test successful
🔗 Database initialization: {
NODE_ENV: 'production',
isProduction: true,
hasDbUrl: true,
dbHost: 'logiflow-db:5432'
}
✅ Using DatabaseStorage (production PostgreSQL)
file:///app/dist/index.js:11
throw Error('Dynamic require of "' + x + '" is not supported');

^
Error: Dynamic require of "events" is not supported
at file:///app/dist/index.js:11:9
at node_modules/node-cron/dist/esm/tasks/inline-scheduled-task.js (file:///app/dist/index.js:3561:36)
at __require2 (file:///app/dist/index.js:17:50)
at node_modules/node-cron/dist/esm/node-cron.js (file:///app/dist/index.js:4042:35)
at __require2 (file:///app/dist/index.js:17:50)
at file:///app/dist/index.js:4502:32
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Node.js v20.19.4
🔗 Database initialization: {
NODE_ENV: 'production',
isProduction: true,
hasDbUrl: true,
dbHost: 'logiflow-db'
}
🐳 PRODUCTION: Using standard PostgreSQL
✅ PostgreSQL connection test successful
🔗 Database initialization: {
NODE_ENV: 'production',
isProduction: true,
hasDbUrl: true,
dbHost: 'logiflow-db:5432'
}
✅ Using DatabaseStorage (production PostgreSQL)
file:///app/dist/index.js:11
throw Error('Dynamic require of "' + x + '" is not supported');

^
Error: Dynamic require of "events" is not supported
at file:///app/dist/index.js:11:9
at node_modules/node-cron/dist/esm/tasks/inline-scheduled-task.js (file:///app/dist/index.js:3561:36)
at __require2 (file:///app/dist/index.js:17:50)
at node_modules/node-cron/dist/esm/node-cron.js (file:///app/dist/index.js:4042:35)
at __require2 (file:///app/dist/index.js:17:50)
at file:///app/dist/index.js:4502:32
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Node.js v20.19.4
🔗 Database initialization: {
NODE_ENV: 'production',
isProduction: true,
hasDbUrl: true,
dbHost: 'logiflow-db'
}
🐳 PRODUCTION: Using standard PostgreSQL
✅ PostgreSQL connection test successful
🔗 Database initialization: {
NODE_ENV: 'production',
isProduction: true,
hasDbUrl: true,
dbHost: 'logiflow-db:5432'
}
✅ Using DatabaseStorage (production PostgreSQL)
file:///app/dist/index.js:11
throw Error('Dynamic require of "' + x + '" is not supported');

^
Error: Dynamic require of "events" is not supported
at file:///app/dist/index.js:11:9
at node_modules/node-cron/dist/esm/tasks/inline-scheduled-task.js (file:///app/dist/index.js:3561:36)
at __require2 (file:///app/dist/index.js:17:50)
at node_modules/node-cron/dist/esm/node-cron.js (file:///app/dist/index.js:4042:35)
at __require2 (file:///app/dist/index.js:17:50)
at file:///app/dist/index.js:4502:32
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Node.js v20.19.4
+9
View File
@@ -19,6 +19,15 @@ La plateforme fournit une gestion robuste des flux de travail de livraison avec
## Recent Changes
### 2025-08-13 - Module de sauvegarde PostgreSQL implémenté + correction ESM
✅ **Module de sauvegarde PostgreSQL complet** :
- **Interface BackupManager** : Affichage des sauvegardes avec détails (taille, tables, statut)
- **Fonctions** : Création manuelle, suppression, téléchargement de sauvegardes SQL
- **Automatisation** : Sauvegardes programmées à 2h du matin avec timer natif
- **Base de données** : Table `DATABASE_BACKUPS` avec suivi complet des sauvegardes
- **Navigation** : Ajouté dans la sidebar administration pour les admins
- **Compatibilité ESM** : Remplacement de `node-cron` par `setTimeout` natif pour résoudre l'erreur production
### 2025-08-13 - Optimisation performance production + correction calendrier
✅ **Résolution latence production** :
- **Problème** : Console saturée par centaines de logs "API Response" causant latence
+27 -12
View File
@@ -2,7 +2,6 @@ import { exec } from 'child_process';
import { promisify } from 'util';
import fs from 'fs';
import path from 'path';
import cron from 'node-cron';
import { nanoid } from 'nanoid';
import { eq, desc } from "drizzle-orm";
import { db } from "./db";
@@ -187,19 +186,35 @@ export class BackupService {
}
private scheduleAutomaticBackup(): void {
// Schedule backup every night at 2:00 AM
cron.schedule('0 2 * * *', async () => {
try {
console.log('🌙 Starting scheduled automatic backup...');
await this.createBackup('automatic');
} catch (error) {
console.error('❌ Scheduled backup failed:', error);
// Use native setTimeout instead of node-cron for ESM compatibility
const scheduleNextBackup = () => {
const now = new Date();
const next2AM = new Date(now);
next2AM.setHours(2, 0, 0, 0);
// If it's already past 2 AM today, schedule for tomorrow
if (now.getHours() >= 2) {
next2AM.setDate(next2AM.getDate() + 1);
}
}, {
timezone: 'Europe/Paris'
});
const msUntilBackup = next2AM.getTime() - now.getTime();
setTimeout(async () => {
try {
console.log('🔄 Starting automatic backup...');
await this.createBackup('automatic', 'system');
console.log('✅ Automatic backup completed');
} catch (error) {
console.error('❌ Automatic backup failed:', error);
}
// Schedule the next backup (24 hours later)
scheduleNextBackup();
}, msUntilBackup);
};
console.log('⏰ Automatic backup scheduled for 2:00 AM daily');
scheduleNextBackup();
console.log('⏰ Automatic backup scheduled for 2:00 AM daily (native timer)');
}
}