mirror of
https://github.com/empayre/fleet.git
synced 2024-11-06 17:05:18 +00:00
38b8c9cc58
#15555 Probably the best way to review this is commit by commit: - First commit does the actual moving. - Second commit fixes golangci-lint issues (in the least effort way to avoid refactoring or rearrangement of some of the code). - Third commit moves a printf to before the migration step is executed. In the past some customers hitting migration issues (like migration steps hanging or taking long to execute) and wanted to know which one was it. The only way to know was to look at the repository and looking for the next migration after the last one logged. Checks: - [X] Manual QA for all new/changed functionality Manual tests: - `make fleet && make db-reset`. - Adding a new migration via `make migration name=Foobar` and then running `./build/fleet prepare db`. - Enrolling a new device to Fleet (smoke test).
38 lines
624 B
Go
38 lines
624 B
Go
package goose
|
|
|
|
import (
|
|
"database/sql"
|
|
)
|
|
|
|
func (c *Client) Redo(db *sql.DB, dir string) error {
|
|
currentVersion, err := c.GetDBVersion(db)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
migrations, err := c.collectMigrations(dir, minVersion, maxVersion)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
current, err := migrations.Current(currentVersion)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
previous, err := migrations.Next(currentVersion)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if err := c.runMigration(db, previous, migrateUp); err != nil {
|
|
return err
|
|
}
|
|
|
|
if err := c.runMigration(db, current, migrateUp); err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|