builder
builder copied to clipboard
Add standalone CLI tool for database migration
Description
With the database migration system implemented in #2001, we now have automated migrations that run when the spx-backend starts. However, there are operational scenarios where a standalone migration tool would be valuable.
Currently, migration operations are tightly coupled with application startup:
- Migrations only run when
config.DatabaseConfig.AutoMigrateis enabled - No way to handle dirty state without direct database manipulation
- Cannot execute migrations independently of application deployment
Possible solution
Create a standalone CLI tool spx-backend-migrate that provides:
status: Show current migration version and pending migrationsup [N]: ApplyNpending migrations (default:all)down [N]: RollbackNmigrations (emergency use only)goto <version>: Migrate to specific version (up or down as needed)force <version>: Force set version to resolve dirty statevalidate: Verify migration file integrity, up/down symmetry, and schema consistency with GORM models
[!NOTE] Following golang-migrate conventions,
[N]represents the count of migrations to apply/rollback, not version numbers. Usegoto <version>to migrate to a specific version.