Using alembic

This commit is contained in:
James Pattinson
2025-11-22 21:18:43 +00:00
parent b8f2d12011
commit 6f1d09cd77
11 changed files with 599 additions and 274 deletions

View File

@@ -25,6 +25,11 @@ A comprehensive membership management system built with FastAPI, MySQL, and Dock
```
membership/
├── backend/
│ ├── alembic/ # Database migration scripts
│ │ ├── versions/ # Migration files
│ │ ├── env.py # Migration environment
│ │ └── script.py.mako # Migration template
│ ├── alembic.ini # Alembic configuration
│ ├── app/
│ │ ├── api/
│ │ │ ├── v1/
@@ -46,7 +51,7 @@ membership/
│ ├── Dockerfile
│ └── requirements.txt
├── database/
│ └── init.sql # Database initialization
│ └── init.sql # Legacy database initialization (deprecated - use Alembic migrations)
├── docker-compose.yml
├── .env.example
└── README.md
@@ -215,6 +220,26 @@ docker exec membership_mysql mysqldump -u membership_user -pSecureMembershipPass
docker exec -i membership_mysql mysql -u membership_user -pSecureMembershipPass2024! membership_db < backup.sql
```
### Database Migrations
The application uses Alembic for database schema migrations. Migrations are automatically run when the backend container starts.
```bash
# Create a new migration (after making model changes)
sudo docker compose exec backend alembic revision --autogenerate -m "Description of changes"
# Apply migrations
sudo docker compose exec backend alembic upgrade head
# View migration status
sudo docker compose exec backend alembic current
# View migration history
sudo docker compose exec backend alembic history
```
**Note**: The `database/init.sql` file is deprecated. All schema changes should now be made through Alembic migrations.
## API Testing
You can use the interactive API documentation at http://localhost:8000/docs to test endpoints: