golang-migrate / migrate

Database migrations. CLI and Golang library.
Other
15.14k stars 1.39k forks source link

Do not return an error when no change. Communicate error conditions using errors. #1063

Open atljoseph opened 6 months ago

atljoseph commented 6 months ago

It is good to know when a migration is not needed, but that is a valid state in a system. So, why is there an error when all migrations already been ran? Why are you communicating informational conditions using errors? Errors should be reserved for errors. Please return a struct from Up and Down which lists information conditions (stats, if you will). Please remove the return of error when all migrations have been performed, and no changes would result. Can't imagine when that would ever be a valid condition for an error. No changes? Great! Sail the seas of cheese!

if migrateErr := m.Up(); migrateErr != nil {
        // No change is not an error condition. It is the DESIRED condition.. .To be up to date.
    if !errors.Is(migrateErr, migrate.ErrNoChange) {
        return fmt.Errorf("cannot perform database migration: %w", migrateErr)
    }
}