Implement PostgreSQL support and update database configuration: Migrate from SQLite to PostgreSQL by updating the Prisma schema, Docker configuration, and environment variables. Add PostgreSQL dependencies and adjust the database connection logic in the application. Enhance .gitignore to exclude PostgreSQL-related files and directories.
Some checks failed
Deploy with Docker Compose / deploy (push) Has been cancelled
Some checks failed
Deploy with Docker Compose / deploy (push) Has been cancelled
This commit is contained in:
82
MIGRATION_POSTGRES.md
Normal file
82
MIGRATION_POSTGRES.md
Normal file
@@ -0,0 +1,82 @@
|
||||
# Migration vers PostgreSQL
|
||||
|
||||
## Changements effectués
|
||||
|
||||
✅ Schema Prisma modifié pour PostgreSQL
|
||||
✅ Code retiré Better SQLite adapter
|
||||
✅ Docker Compose configuré avec service PostgreSQL
|
||||
✅ Dockerfile mis à jour
|
||||
✅ Dépendances retirées (better-sqlite3)
|
||||
|
||||
## Prochaines étapes
|
||||
|
||||
### 1. Démarrer PostgreSQL en local (pour dev)
|
||||
|
||||
```bash
|
||||
# Option 1: Docker Compose
|
||||
docker-compose up postgres -d
|
||||
|
||||
# Option 2: PostgreSQL local
|
||||
# Installer PostgreSQL puis créer la DB
|
||||
createdb gotgaming
|
||||
```
|
||||
|
||||
### 2. Configurer DATABASE_URL
|
||||
|
||||
Créer un fichier `.env.local` avec :
|
||||
```
|
||||
DATABASE_URL="postgresql://gotgaming:password@localhost:5432/gotgaming?schema=public"
|
||||
```
|
||||
|
||||
### 3. Créer la migration initiale
|
||||
|
||||
```bash
|
||||
pnpm prisma migrate dev --name init_postgres
|
||||
```
|
||||
|
||||
### 4. Migrer les données SQLite → PostgreSQL (si nécessaire)
|
||||
|
||||
Si tu as des données existantes dans SQLite :
|
||||
|
||||
```bash
|
||||
# Exporter SQLite
|
||||
sqlite3 data/dev.db .dump > sqlite_dump.sql
|
||||
|
||||
# Adapter le dump pour PostgreSQL (changer les types, syntaxe)
|
||||
# Puis importer dans PostgreSQL
|
||||
psql gotgaming < adapted_dump.sql
|
||||
```
|
||||
|
||||
Ou utiliser un outil comme `pgloader` :
|
||||
```bash
|
||||
pgloader sqlite://data/dev.db postgresql://gotgaming:password@localhost:5432/gotgaming
|
||||
```
|
||||
|
||||
### 5. En production (Docker Compose)
|
||||
|
||||
```bash
|
||||
# Démarrer tous les services
|
||||
docker-compose up -d
|
||||
|
||||
# Les migrations seront appliquées automatiquement au démarrage via entrypoint.sh
|
||||
```
|
||||
|
||||
## Variables d'environnement Docker
|
||||
|
||||
Ajouter dans ton `.env` ou docker-compose.yml :
|
||||
|
||||
```env
|
||||
POSTGRES_USER=gotgaming
|
||||
POSTGRES_PASSWORD=change-this-in-production
|
||||
POSTGRES_DB=gotgaming
|
||||
POSTGRES_DATA_PATH=./data/postgres
|
||||
```
|
||||
|
||||
## Avantages de PostgreSQL
|
||||
|
||||
- ✅ Pool de connexions natif (plus de timeout après inactivité)
|
||||
- ✅ Concurrence réelle (pas de verrous de fichier)
|
||||
- ✅ Meilleures performances en production
|
||||
- ✅ Backups plus simples (`pg_dump`)
|
||||
- ✅ Scaling horizontal possible
|
||||
|
||||
Reference in New Issue
Block a user