1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-25 00:09:40 +02:00

fix(migrator): fix setting version struct fields after migration [EE-4613] (#8090)

* fix setting version struct fields

* fix go tests

* remove versionUpdateRequired

* remove old code that was originally for debugging purposes
This commit is contained in:
Matt Hook 2022-11-28 19:28:10 +13:00 committed by GitHub
parent d78b762f7b
commit 95bc508462
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 32 deletions

View file

@ -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,27 +57,27 @@ func (m *Migrator) Migrate() error {
}
}
newMigratorCount = len(migration.migrationFuncs)
if apiVersion.Equal(migration.version) {
newMigratorCount = len(migration.migrationFuncs)
}
}
}
if versionUpdateRequired || newMigratorCount != version.MigratorCount {
err := m.Always()
if err != nil {
return migrationError(err, "Always migrations returned error")
}
version.SchemaVersion = portainer.APIVersion
version.MigratorCount = newMigratorCount
err = m.versionService.UpdateVersion(version)
if err != nil {
return migrationError(err, "StoreDBVersion")
}
log.Info().Msgf("db migrated to %s", portainer.APIVersion)
err = m.Always()
if err != nil {
return migrationError(err, "Always migrations returned error")
}
version.SchemaVersion = portainer.APIVersion
version.MigratorCount = newMigratorCount
err = m.versionService.UpdateVersion(version)
if err != nil {
return migrationError(err, "StoreDBVersion")
}
log.Info().Msgf("db migrated to %s", portainer.APIVersion)
return nil
}