# Database Migrations ## Overview This project uses sequential SQL migration files located in `veza-backend-api/migrations/`. Migrations are numbered sequentially (001, 002, ..., 108). ## Current State (v0.501) | Range | Description | |-------|-------------| | 001-050 | Core schema (users, tracks, playlists, roles) | | 051-080 | Features (likes, shares, versions, sessions, OAuth) | | 081-098 | Advanced (HLS streams, marketplace, notifications) | | 099-100 | Promo codes and order discounts (v0.402) | | 101-102 | Previous stabilization migrations | | 103-108 | v0.501 (waveform, cloud storage, gear images) | ## Running Migrations Migrations are applied automatically by the backend on startup via GORM AutoMigrate and manual SQL execution. ## Squash Script To generate a single baseline SQL file from all migrations: ```bash ./scripts/squash_migrations.sh > veza-backend-api/migrations/baseline_v0501.sql ``` This is useful for: - Setting up new development environments - Creating test databases - Documenting the complete schema **Important**: Do NOT delete individual migration files. The baseline is supplementary. ## Adding New Migrations 1. Create a new file: `{next_number}_{description}.sql` 2. Use `IF NOT EXISTS` / `IF EXISTS` for idempotency 3. Include a comment header with version reference 4. Test on a clean database before committing