Some checks failed
Deploy to Production / deploy (push) Failing after 8s
- Renamed MYSQL_ROOT_PASSWORD to DB_ROOT_PASSWORD and MYSQL_PASSWORD to DB_PASSWORD for consistent naming - Updated docker-compose.yml to map DB_* variables to MySQL container's expected MYSQL_* format - Removed redundant DATABASE_URL variable since individual DB_* variables are now used - Added default values for DB_USER, DB_NAME, DB_HOST, and DB_PORT in docker-compose.yml - Updated all documentation files to reference new standar
146 lines
4.2 KiB
Markdown
146 lines
4.2 KiB
Markdown
# Database Variable Migration Complete ✅
|
|
|
|
## Summary
|
|
|
|
All database configuration variables across the entire project have been successfully unified to use the `DB_*` prefix.
|
|
|
|
## Files Updated
|
|
|
|
### Configuration Files
|
|
- ✅ `.env.example` - Updated with unified `DB_*` variables
|
|
- ✅ `docker-compose.yml` - Uses `DB_*` variables with proper MySQL container mapping
|
|
|
|
### Documentation Files
|
|
- ✅ `QUICK_START.md` - All references updated
|
|
- ✅ `DATABASE_SETUP.md` - All references updated
|
|
- ✅ `DEPLOYMENT_SUMMARY.md` - All references updated
|
|
- ✅ `DEPLOYMENT_GUIDE.md` - Docker compose example and GitHub Actions updated
|
|
- ✅ `LOCAL_TESTING.md` - All references updated
|
|
|
|
### Migration Tools
|
|
- ✅ `scripts/migrate-db-vars.sh` - Helper script for existing installations
|
|
- ✅ `docs/DB_VARIABLE_MIGRATION.md` - Comprehensive migration guide
|
|
- ✅ `DB_VARS_UNIFIED.md` - Quick reference guide
|
|
|
|
### Application Code
|
|
- ✅ `apps/api/src/db.ts` - Already using `DB_*` (no changes needed)
|
|
- ✅ `apps/api/drizzle.config.ts` - Already using `DB_*` (no changes needed)
|
|
- ✅ `apps/api/src/db/migrate.ts` - Already using `DB_*` (no changes needed)
|
|
|
|
## Unified Variable Names
|
|
|
|
| Variable | Purpose | Default |
|
|
|----------|---------|---------|
|
|
| `DB_ROOT_PASSWORD` | MySQL root password | - |
|
|
| `DB_PASSWORD` | Application database password | - |
|
|
| `DB_USER` | Database username | `voxblog` |
|
|
| `DB_NAME` | Database name | `voxblog` |
|
|
| `DB_HOST` | Database host | `mysql` (docker) / `localhost` |
|
|
| `DB_PORT` | Database port | `3306` |
|
|
|
|
## What Was Changed
|
|
|
|
### Before
|
|
```bash
|
|
# Mixed naming conventions
|
|
MYSQL_ROOT_PASSWORD=xxx
|
|
MYSQL_PASSWORD=xxx
|
|
DATABASE_URL=mysql://...
|
|
DB_HOST=mysql
|
|
DB_PORT=3306
|
|
DB_USER=voxblog
|
|
DB_PASSWORD=xxx # Duplicate!
|
|
DB_NAME=voxblog
|
|
```
|
|
|
|
### After
|
|
```bash
|
|
# Unified DB_* naming
|
|
DB_ROOT_PASSWORD=xxx
|
|
DB_PASSWORD=xxx
|
|
DB_USER=voxblog
|
|
DB_NAME=voxblog
|
|
DB_HOST=mysql
|
|
DB_PORT=3306
|
|
```
|
|
|
|
## Benefits Achieved
|
|
|
|
1. ✅ **Consistency** - Single naming pattern across entire codebase
|
|
2. ✅ **Simplicity** - No more confusion about which variable to use
|
|
3. ✅ **No Duplication** - Removed redundant `DATABASE_URL` and duplicate password variables
|
|
4. ✅ **Better Defaults** - All variables have sensible defaults in docker-compose
|
|
5. ✅ **Clear Documentation** - All docs updated with correct variable names
|
|
6. ✅ **Easy Migration** - Script provided for existing installations
|
|
|
|
## Verification
|
|
|
|
Run this to verify no legacy variables remain in your project:
|
|
```bash
|
|
# Should only show references in migration docs (as "before" examples)
|
|
grep -r "MYSQL_ROOT_PASSWORD\|MYSQL_PASSWORD" --include="*.md" --include="*.yml" --include="*.env*" .
|
|
```
|
|
|
|
## Next Steps for Users
|
|
|
|
### New Installations
|
|
Just use the updated `.env.example`:
|
|
```bash
|
|
cp .env.example .env
|
|
# Edit .env with your values
|
|
docker-compose up -d
|
|
```
|
|
|
|
### Existing Installations
|
|
Run the migration script:
|
|
```bash
|
|
./scripts/migrate-db-vars.sh
|
|
docker-compose down
|
|
docker-compose up -d
|
|
```
|
|
|
|
## Technical Notes
|
|
|
|
### MySQL Container Mapping
|
|
The MySQL Docker container still requires `MYSQL_*` environment variables internally. Our `docker-compose.yml` handles this mapping:
|
|
|
|
```yaml
|
|
mysql:
|
|
environment:
|
|
MYSQL_ROOT_PASSWORD: ${DB_ROOT_PASSWORD} # Maps DB_* to MYSQL_*
|
|
MYSQL_PASSWORD: ${DB_PASSWORD}
|
|
MYSQL_USER: ${DB_USER:-voxblog}
|
|
MYSQL_DATABASE: ${DB_NAME:-voxblog}
|
|
```
|
|
|
|
This is transparent to users - they only need to set `DB_*` variables.
|
|
|
|
### Application Code
|
|
The application code in `apps/api/src/db.ts` and related files already used `DB_*` variables, so no code changes were needed. This migration was purely about configuration consistency.
|
|
|
|
## Rollback (If Needed)
|
|
|
|
If you need to rollback for any reason:
|
|
```bash
|
|
# Restore your .env backup
|
|
cp .env.backup.YYYYMMDD_HHMMSS .env
|
|
|
|
# Or manually change:
|
|
DB_ROOT_PASSWORD → MYSQL_ROOT_PASSWORD
|
|
DB_PASSWORD → MYSQL_PASSWORD
|
|
```
|
|
|
|
However, we recommend moving forward with the unified naming as it's cleaner and more maintainable.
|
|
|
|
## Support
|
|
|
|
- See `docs/DB_VARIABLE_MIGRATION.md` for detailed migration guide
|
|
- See `DB_VARS_UNIFIED.md` for quick reference
|
|
- Check docker-compose logs if services don't start: `docker-compose logs`
|
|
|
|
---
|
|
|
|
**Migration completed successfully!** 🎉
|
|
|
|
All database variables are now unified under the `DB_*` prefix for consistency and simplicity.
|