80 lines
2.1 KiB
Markdown
80 lines
2.1 KiB
Markdown
# Quick Start: Database Migration to Coolify
|
|
|
|
## 🚀 Quick Steps
|
|
|
|
### 1. Backup Current Database
|
|
|
|
```bash
|
|
# Run backup script
|
|
./scripts/backup-database.sh
|
|
```
|
|
|
|
This creates a backup in `backups/YYYYMMDD_HHMMSS/` with all your data.
|
|
|
|
### 2. Set Up PostgreSQL in Coolify
|
|
|
|
1. Create PostgreSQL service in Coolify
|
|
2. Note the container name (e.g., `postgres-abc123`)
|
|
3. Note the database password
|
|
|
|
### 3. Configure Environment Variables
|
|
|
|
In your Next.js app service in Coolify, set:
|
|
|
|
```bash
|
|
DATABASE_URL=postgresql://postgres:YOUR_PASSWORD@postgres-CONTAINER_ID:5432/postgres
|
|
RUNTIME_DATABASE_URL=postgresql://postgres:YOUR_PASSWORD@postgres-CONTAINER_ID:5432/postgres
|
|
```
|
|
|
|
**Replace**:
|
|
- `YOUR_PASSWORD` with actual password
|
|
- `CONTAINER_ID` with actual container ID from Coolify
|
|
|
|
### 4. Restore Database
|
|
|
|
**Option A: Via Coolify Terminal**
|
|
|
|
1. Copy backup to Coolify server
|
|
2. SSH into server or use Coolify terminal
|
|
3. Run restore script:
|
|
```bash
|
|
./scripts/restore-database.sh backups/latest
|
|
```
|
|
|
|
**Option B: Via Prisma Migrations** (Recommended)
|
|
|
|
```bash
|
|
# In Coolify build command or manually:
|
|
npx prisma migrate deploy
|
|
npm run db:seed
|
|
```
|
|
|
|
### 5. Verify
|
|
|
|
Check your app logs in Coolify for database connection errors. Test key features.
|
|
|
|
## 📁 Files Created
|
|
|
|
- `scripts/backup-database.sh` - Backup script
|
|
- `scripts/restore-database.sh` - Restore script
|
|
- `scripts/export-db-config.sh` - Export config (non-sensitive)
|
|
- `docs/COOLIFY_DATABASE_MIGRATION.md` - Detailed guide
|
|
- `docs/DATABASE_CONFIG.md` - Configuration reference
|
|
|
|
## 📚 Full Documentation
|
|
|
|
- **Detailed Migration Guide**: [docs/COOLIFY_DATABASE_MIGRATION.md](docs/COOLIFY_DATABASE_MIGRATION.md)
|
|
- **Database Config Reference**: [docs/DATABASE_CONFIG.md](docs/DATABASE_CONFIG.md)
|
|
- **General Coolify Migration**: [COOLIFY_MIGRATION.md](COOLIFY_MIGRATION.md)
|
|
|
|
## ⚠️ Important Notes
|
|
|
|
1. **Never commit backups** with real data to git
|
|
2. **Use strong passwords** for production
|
|
3. **Test restore** in a staging environment first
|
|
4. **Keep backups** in a secure location
|
|
|
|
## 🆘 Need Help?
|
|
|
|
See troubleshooting section in [docs/COOLIFY_DATABASE_MIGRATION.md](docs/COOLIFY_DATABASE_MIGRATION.md)
|