migrate
migrate copied to clipboard
Return the number of performed migrations
It would be nice to return the number of performed migrations, as this can be logged when migrations are performed and when someone is looking at the logs, he can observe if the migrations have really been executed or no.
For example, imagine that "clumsy old me" or a colleague decides to change a database column, but without creating a new DB migration file, just edits an existing migration file. Now when the service is deployed and it automatically performs DB migrations upon startup, we can observe in the logs an entry like performed db migrations: 0 and easily guess that the DB changes were not applied, because they are placed in a previously performed DB migration.
I think a good place for this change might be the migrate.Up() function and the API can look something like:
func (m *Migrate) Up() (int, error) {
...
}
if n, err := m.Up(); err != nil {
...
}
log.Println("performed migrations: ", n)
Thanks for the suggestion! This would be nice to halve and really helpful for partial migration runs (e.g. if you have 5 migrations to apply but the 3rd one fails) Unfortunately, this would be a breaking change (or a new API) so would not be easy to do.
In the meanwhile, you can see detailed info by attaching a Logger to your instance of *Migrate or by inspecting the versions before and after running migrations.