- 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
4.2 KiB
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 unifiedDB_*variables - ✅
docker-compose.yml- UsesDB_*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 usingDB_*(no changes needed) - ✅
apps/api/drizzle.config.ts- Already usingDB_*(no changes needed) - ✅
apps/api/src/db/migrate.ts- Already usingDB_*(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
# 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
# Unified DB_* naming
DB_ROOT_PASSWORD=xxx
DB_PASSWORD=xxx
DB_USER=voxblog
DB_NAME=voxblog
DB_HOST=mysql
DB_PORT=3306
Benefits Achieved
- ✅ Consistency - Single naming pattern across entire codebase
- ✅ Simplicity - No more confusion about which variable to use
- ✅ No Duplication - Removed redundant
DATABASE_URLand duplicate password variables - ✅ Better Defaults - All variables have sensible defaults in docker-compose
- ✅ Clear Documentation - All docs updated with correct variable names
- ✅ Easy Migration - Script provided for existing installations
Verification
Run this to verify no legacy variables remain in your project:
# 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:
cp .env.example .env
# Edit .env with your values
docker-compose up -d
Existing Installations
Run the migration script:
./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:
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:
# 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.mdfor detailed migration guide - See
DB_VARS_UNIFIED.mdfor 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.