Database Migrations¶
MediaFusion uses sqlx for database schema migrations. Migrations apply automatically when the API server or worker starts — no manual step required.
How migrations work¶
On every startup, MediaFusion checks whether the database schema is up to date and applies any pending migrations before accepting requests. This means:
- First-time startup creates all tables automatically
- Upgrades apply new migrations automatically
- Downgrades require a manual rollback step (see below)
Checking migration status¶
Set MEDIAFUSION_MIGRATE=status and run either binary. It prints the migration table and exits without starting the server:
Rolling back migrations¶
Required before downgrading
If you ran a newer version that applied new migrations, you must roll back before switching to an older image. The older binary will refuse to start if it finds schema versions it doesn't recognize.
Set MEDIAFUSION_MIGRATE_ROLLBACK_TO=<version> to roll back to a specific version:
Downgrading from 6.x to 5.x¶
Version 5.x used Alembic for migrations. After rolling back with the 6.x binary, you must restore the Alembic version marker:
- Roll back with the 6.x binary to the correct version (check the 5.x release notes for the target version number).
-
Connect to PostgreSQL and run:
-
Start the 5.x binary — it will see the correct Alembic revision and start normally.