Initial commit : API Node.js + PostgreSQL + sync service Docker
- API Express/pg connectée à PostgreSQL (converti depuis mssql) - 8 routes : articles, fournisseurs, commandes, stock, mouvements, performance, schema, sync - Service sync nightly (mssql → pg, cron 3h00) - Docker Compose : postgres + api + sync + frpc (tunnel sortant) - Schéma PostgreSQL 17 tables dans postgres/init.sql Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
commit
d565ed9f10
28 files changed
+2423
No files matched your search
@@ -0,0 +1,46 @@
|
||||
require('dotenv').config();
|
||||
const cron = require('node-cron');
|
||||
|
||||
const { syncArticles } = require('./tables/articles');
|
||||
const { syncFournisseurs } = require('./tables/fournisseurs');
|
||||
const { syncStock } = require('./tables/stock');
|
||||
const { syncMouvements } = require('./tables/mouvements');
|
||||
const { syncCommandes } = require('./tables/commandes');
|
||||
const { syncReferentiel } = require('./tables/referentiel');
|
||||
const { closeAll } = require('./db');
|
||||
|
||||
const forceMode = process.argv.includes('--force');
|
||||
|
||||
async function syncAll(force = false) {
|
||||
const start = Date.now();
|
||||
console.log(`\n=== SYNC START ${new Date().toISOString()} (force=${force}) ===`);
|
||||
|
||||
// Ordre important : référentiel avant articles, articles avant stock/mouvements
|
||||
await syncReferentiel(force);
|
||||
await syncArticles(force);
|
||||
await syncFournisseurs(force);
|
||||
await syncStock(force);
|
||||
await syncMouvements(force);
|
||||
await syncCommandes(force);
|
||||
|
||||
const elapsed = ((Date.now() - start) / 1000).toFixed(1);
|
||||
console.log(`=== SYNC DONE en ${elapsed}s ===\n`);
|
||||
}
|
||||
|
||||
if (forceMode) {
|
||||
// Lancement manuel : node index.js --force
|
||||
console.log('Mode force : sync complète en cours...');
|
||||
syncAll(true)
|
||||
.then(() => closeAll())
|
||||
.then(() => process.exit(0))
|
||||
.catch(err => {
|
||||
console.error('Erreur fatale sync:', err.message);
|
||||
process.exit(1);
|
||||
});
|
||||
} else {
|
||||
// Mode daemon : sync nightly à 3h00
|
||||
console.log('Service sync démarré — cron: 0 3 * * * (3h00 chaque nuit)');
|
||||
cron.schedule('0 3 * * *', () => {
|
||||
syncAll(false).catch(err => console.error('Erreur cron sync:', err.message));
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user