83 lines
1.9 KiB
Markdown
83 lines
1.9 KiB
Markdown
# 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
|
|
|