Merge db-migrations: Add Flask-Migrate support and clean up old migration system

This commit is contained in:
2025-07-13 12:17:20 +02:00
parent 7140aeba41
commit 1500b2cf88
65 changed files with 2153 additions and 7881 deletions

74
MIGRATION_SETUP_FINAL.md Normal file
View File

@@ -0,0 +1,74 @@
# Final Migration Setup for TimeTrack
## What's Working Now
Your migration system is now fully functional with:
1. **Flask-Migrate** - Handles database schema changes
2. **Automatic Enum Sync** - Handles PostgreSQL enum values
3. **Docker Support** - Works without Git in containers
## Essential Files to Keep
### Core Migration Files
- `migrations/` - Flask-Migrate directory (required)
- `sync_postgres_enums.py` - Auto-syncs enum values on startup
- `docker_migrate_init.py` - Initializes migrations in Docker
### Updated Startup Scripts
- `startup_postgres.sh` - Now includes enum sync
- `startup_postgres_safe.sh` - Debug version with error handling
- `startup.sh` - Updated for Flask-Migrate
### Debug Tools (Optional)
- `debug_entrypoint.sh` - For troubleshooting
- `docker-compose.debug.yml` - Debug Docker setup
### Documentation
- `FLASK_MIGRATE_GUIDE.md` - Complete guide
- `DOCKER_MIGRATIONS_GUIDE.md` - Docker-specific guide
- `POSTGRES_ENUM_GUIDE.md` - Enum handling guide
- `FLASK_MIGRATE_TROUBLESHOOTING.md` - Troubleshooting guide
## Workflow Summary
### For New Schema Changes
```bash
# 1. Modify your models
# 2. Generate migration
flask db migrate -m "Add new feature"
# 3. Review the generated file
# 4. Apply migration
flask db upgrade
```
### For New Enum Values
```python
# Just add to Python enum - sync happens automatically
class TaskStatus(enum.Enum):
NEW_STATUS = "New Status"
```
### Docker Deployment
```bash
# Everything is automatic in startup scripts:
# 1. Migrations applied
# 2. Enums synced
# 3. App starts
```
## Cleanup
Run the cleanup script to remove all temporary files:
```bash
./cleanup_migration_cruft.sh
```
This removes ~20+ temporary scripts while keeping the essential ones.
## Notes
- The old migration system (`migrations_old/`) can be removed after confirming everything works
- PostgreSQL enums now support both names (TODO) and values (To Do)
- All future migrations are handled by Flask-Migrate
- Enum sync runs automatically on every startup