|
|
|
@ -32,15 +32,13 @@ func (m *Migrator) Migrate() error {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
newMigratorCount := 0
|
|
|
|
|
versionUpdateRequired := false
|
|
|
|
|
if schemaVersion.Equal(semver.MustParse(portainer.APIVersion)) {
|
|
|
|
|
apiVersion := semver.MustParse(portainer.APIVersion)
|
|
|
|
|
if schemaVersion.Equal(apiVersion) {
|
|
|
|
|
// detect and run migrations when the versions are the same.
|
|
|
|
|
// e.g. development builds
|
|
|
|
|
latestMigrations := m.latestMigrations()
|
|
|
|
|
if latestMigrations.version.Equal(schemaVersion) &&
|
|
|
|
|
version.MigratorCount != len(latestMigrations.migrationFuncs) {
|
|
|
|
|
|
|
|
|
|
versionUpdateRequired = true
|
|
|
|
|
err := runMigrations(latestMigrations.migrationFuncs)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
@ -51,7 +49,7 @@ func (m *Migrator) Migrate() error {
|
|
|
|
|
// regular path when major/minor/patch versions differ
|
|
|
|
|
for _, migration := range m.migrations {
|
|
|
|
|
if schemaVersion.LessThan(migration.version) {
|
|
|
|
|
versionUpdateRequired = true
|
|
|
|
|
|
|
|
|
|
log.Info().Msgf("migrating data to %s", migration.version.String())
|
|
|
|
|
err := runMigrations(migration.migrationFuncs)
|
|
|
|
|
if err != nil {
|
|
|
|
@ -59,12 +57,13 @@ func (m *Migrator) Migrate() error {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if apiVersion.Equal(migration.version) {
|
|
|
|
|
newMigratorCount = len(migration.migrationFuncs)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if versionUpdateRequired || newMigratorCount != version.MigratorCount {
|
|
|
|
|
err := m.Always()
|
|
|
|
|
err = m.Always()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return migrationError(err, "Always migrations returned error")
|
|
|
|
|
}
|
|
|
|
@ -78,7 +77,6 @@ func (m *Migrator) Migrate() error {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
log.Info().Msgf("db migrated to %s", portainer.APIVersion)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|