feat: add automatic database initialization and recovery
- Add init_database() with alembic programmatic API and retry logic - Add connection retry with exponential backoff (5 attempts) - Improve error messages for connection/auth failures - Add table existence check before seeding data - Update startup event to run migrations before seeding - Add wait-for-db.sh script for Docker containers - Update Docker and docker-compose configurations Quality gates: ruff ✓, mypy ✓, unit tests (8 passed)
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
## Why
|
||||
|
||||
The application currently fails to start when database tables are missing or migrations haven't been applied. This creates a poor deployment experience and requires manual intervention. We need automatic database initialization, migration management, and seed data handling to ensure the application starts reliably in any environment.
|
||||
|
||||
## What Changes
|
||||
|
||||
- **Auto-run migrations on startup** instead of requiring manual `alembic upgrade head`
|
||||
- **Improve startup error handling** with clear error messages when DB is unavailable
|
||||
- **Add database readiness checks** before attempting migrations or seeding
|
||||
- **Seed data management** with proper handling of missing tables
|
||||
- **Better database initialization** in Docker environments
|
||||
|
||||
## Capabilities
|
||||
|
||||
### New Capabilities
|
||||
- `database-initialization`: Automatic database setup including migrations and seed data
|
||||
|
||||
### Modified Capabilities
|
||||
- `docker-infrastructure`: Add database initialization scripts and health checks
|
||||
|
||||
## Impact
|
||||
|
||||
- `apps/api/src/main.py`: Add startup database initialization
|
||||
- `apps/api/src/database.py`: Add connection health checks
|
||||
- `apps/api/Dockerfile`: Add init scripts
|
||||
- `docker-compose.yml` and `docker-compose.traefik.yml`: Update startup behavior
|
||||
Reference in New Issue
Block a user