mirror of
https://github.com/wahyd4/you-music.git
synced 2026-08-09 05:06:44 +10:00
add db migration
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user