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