mirror of
https://github.com/R0m1k3/noteflow.git
synced 2026-10-11 17:29:37 +02:00
🎯 Objectif: Résoudre définitivement le problème d'affichage RSS Problème analysé: - Articles récupérés (logs: "18 nouveaux") mais jamais affichés - SQLite avec multiples DBs impossibles à déboguer - Concurrence limitée, pas de logs SQL natifs - Impossible de savoir quelle DB est vraiment utilisée Solution: Migration complète vers PostgreSQL + Docker 📦 Fichiers ajoutés/modifiés: **Docker & Configuration** - docker-compose.yml: Ajout service PostgreSQL (port 5499) - Dockerfile: Remplacement sqlite par postgresql-client - init-db.sql: Script d'initialisation PostgreSQL - .env.example: Variables d'environnement PostgreSQL **Code Base de Données** - config/database-postgres.js: Nouvelle couche PostgreSQL - Utilise pg (node-postgres) avec pool de connexions - Conversion SERIAL pour auto-increment - Conversion TIMESTAMP pour dates - Gestion transactions avec BEGIN/COMMIT - Support DATABASE_URL **Migration** - scripts/migrate-sqlite-to-postgres.js: - Migration automatique SQLite → PostgreSQL - Respect ordre des foreign keys - Conversion types SQLite → PostgreSQL - Reset des séquences SERIAL - Gestion des erreurs et rollback **Documentation** - MIGRATION-POSTGRESQL.md: Guide complet - Pourquoi PostgreSQL vs SQLite - Étapes de migration détaillées - Configuration Docker - Backup/Restore PostgreSQL - Monitoring et performance - Dépannage complet **Dépendances** - package.json: Ajout pg@^8.11.3 📊 Architecture PostgreSQL: ```yaml postgres: port: 5499:5499 (personnalisé) user: noteflow database: noteflow volume: postgres_data (persistant) healthcheck: pg_isready app: depends_on: postgres (avec healthcheck) DATABASE_URL: auto-configurée Connexion: via nom de service 'postgres' ``` 🔧 Utilisation: 1. **Installer dépendances:** ```bash npm install ``` 2. **Activer PostgreSQL:** ```bash cp config/database-postgres.js config/database.js ``` 3. **Démarrer PostgreSQL:** ```bash docker-compose up -d postgres ``` 4. **Migrer données:** ```bash SQLITE_PATH=/path/to/notes.db node scripts/migrate-sqlite-to-postgres.js ``` 5. **Démarrer app:** ```bash docker-compose up -d ``` ✨ Avantages PostgreSQL: ✅ Concurrence MVCC (pas de verrous globaux) ✅ Une seule DB (pas de confusion) ✅ Logs SQL natifs (debuggable) ✅ Transactions robustes ✅ Production-ready ✅ Monitoring intégré ✅ Performance supérieure 🎯 Résultat attendu: Le problème RSS sera DÉFINITIVEMENT résolu car: - Une seule source de vérité (PostgreSQL) - Logs clairs pour voir les INSERT - Pas de problème de concurrence - Frontend et backend sur la même DB - Debuggable en temps réel Les articles du 14 novembre (et suivants) seront visibles! 📚 Documentation complète dans MIGRATION-POSTGRESQL.md
65 lines
1.7 KiB
YAML
65 lines
1.7 KiB
YAML
version: '3.8'
|
|
|
|
services:
|
|
# PostgreSQL Database
|
|
postgres:
|
|
image: postgres:16-alpine
|
|
container_name: noteflow-postgres
|
|
restart: unless-stopped
|
|
command: -p 5499
|
|
environment:
|
|
POSTGRES_DB: noteflow
|
|
POSTGRES_USER: noteflow
|
|
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-noteflow_secure_password_change_me}
|
|
POSTGRES_INITDB_ARGS: "--encoding=UTF8"
|
|
volumes:
|
|
- postgres_data:/var/lib/postgresql/data
|
|
ports:
|
|
- "5499:5499"
|
|
networks:
|
|
- nginx_default
|
|
healthcheck:
|
|
test: ["CMD-SHELL", "pg_isready -U noteflow -d noteflow -p 5499"]
|
|
interval: 10s
|
|
timeout: 5s
|
|
retries: 5
|
|
|
|
# NoteFlow Application
|
|
notes-app:
|
|
build: .
|
|
container_name: notes-todo-app
|
|
restart: unless-stopped
|
|
depends_on:
|
|
postgres:
|
|
condition: service_healthy
|
|
ports:
|
|
- "2222:2222"
|
|
volumes:
|
|
- notes_uploads:/app/public/uploads
|
|
- notes_logs:/app/data/logs
|
|
environment:
|
|
- NODE_ENV=production
|
|
- JWT_SECRET=${JWT_SECRET:-change_me_in_production_please_use_strong_secret}
|
|
- PORT=2222
|
|
- UPLOADS_PATH=/app/public/uploads
|
|
# PostgreSQL connection
|
|
- DATABASE_URL=postgresql://noteflow:${POSTGRES_PASSWORD:-noteflow_secure_password_change_me}@postgres:5499/noteflow
|
|
- DB_TYPE=postgres
|
|
networks:
|
|
- nginx_default
|
|
healthcheck:
|
|
test: ["CMD", "node", "-e", "require('http').get('http://localhost:2222/health', (r) => process.exit(r.statusCode === 200 ? 0 : 1))"]
|
|
interval: 30s
|
|
timeout: 10s
|
|
retries: 3
|
|
start_period: 40s
|
|
|
|
volumes:
|
|
postgres_data:
|
|
notes_uploads:
|
|
notes_logs:
|
|
|
|
networks:
|
|
nginx_default:
|
|
external: true
|