add db migration

This commit is contained in:
2025-10-30 22:35:02 +11:00
parent 5dd486844f
commit 9c6ed82a56
56 changed files with 3009 additions and 305 deletions
+54 -3
View File
@@ -316,14 +316,65 @@ uvicorn main:app --port 8001
```
### Database errors
Delete the database file and restart:
If you encounter database errors, try the following:
**With Migrations (Recommended):**
```bash
rm data/youmusic.db
docker-compose restart
# Check current migration status
cd backend
./migrate.sh current
# Apply pending migrations
./migrate.sh upgrade
# If needed, check migration history
./migrate.sh history
```
**Reset Database (Dev only - DATA LOSS!):**
```bash
# Delete database and restart (auto-migrates on startup)
rm data/youmusic.db
docker-compose restart
# Or for local development
./dev-stop.sh
rm backend/data/youmusic.db
./dev.sh
```
See [MIGRATIONS.md](MIGRATIONS.md) for detailed migration documentation.
## Development
### Database Migrations
YouMusic uses Alembic for database migrations. This allows safe schema changes without data loss.
**Common operations:**
```bash
cd backend
# View current database version
./migrate.sh current
# Create a new migration after modifying models
./migrate.sh create "Add new field description"
# Apply migrations
./migrate.sh upgrade
# Rollback last migration
./migrate.sh downgrade
# View migration history
./migrate.sh history
```
**Note:** Migrations run automatically on app startup, so manual migration is only needed when developing new schema changes.
For complete migration documentation, see [MIGRATIONS.md](MIGRATIONS.md).
### Running tests
```bash
# Backend