mirror of https://github.com/portainer/portainer
fix(migrator): prevent duplicated migration EE-5777 (#10076)
parent
dc76900a28
commit
1c79f10ae8
|
@ -20,6 +20,7 @@ import (
|
||||||
"github.com/portainer/portainer/api/database/models"
|
"github.com/portainer/portainer/api/database/models"
|
||||||
"github.com/portainer/portainer/api/dataservices"
|
"github.com/portainer/portainer/api/dataservices"
|
||||||
"github.com/portainer/portainer/api/datastore"
|
"github.com/portainer/portainer/api/datastore"
|
||||||
|
"github.com/portainer/portainer/api/datastore/migrator"
|
||||||
"github.com/portainer/portainer/api/demo"
|
"github.com/portainer/portainer/api/demo"
|
||||||
"github.com/portainer/portainer/api/docker"
|
"github.com/portainer/portainer/api/docker"
|
||||||
dockerclient "github.com/portainer/portainer/api/docker/client"
|
dockerclient "github.com/portainer/portainer/api/docker/client"
|
||||||
|
@ -119,11 +120,15 @@ func initDataStore(flags *portainer.CLIFlags, secretKey []byte, fileService port
|
||||||
log.Fatal().Err(err).Msg("failed generating instance id")
|
log.Fatal().Err(err).Msg("failed generating instance id")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
migratorInstance := migrator.NewMigrator(&migrator.MigratorParameters{})
|
||||||
|
migratorCount := migratorInstance.GetMigratorCountOfCurrentAPIVersion()
|
||||||
|
|
||||||
// from MigrateData
|
// from MigrateData
|
||||||
v := models.Version{
|
v := models.Version{
|
||||||
SchemaVersion: portainer.APIVersion,
|
SchemaVersion: portainer.APIVersion,
|
||||||
Edition: int(portainer.PortainerCE),
|
Edition: int(portainer.PortainerCE),
|
||||||
InstanceID: instanceId.String(),
|
InstanceID: instanceId.String(),
|
||||||
|
MigratorCount: migratorCount,
|
||||||
}
|
}
|
||||||
store.VersionService.UpdateVersion(&v)
|
store.VersionService.UpdateVersion(&v)
|
||||||
|
|
||||||
|
|
|
@ -148,6 +148,17 @@ func (m *Migrator) LatestMigrations() Migrations {
|
||||||
return m.migrations[len(m.migrations)-1]
|
return m.migrations[len(m.migrations)-1]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *Migrator) GetMigratorCountOfCurrentAPIVersion() int {
|
||||||
|
migratorCount := 0
|
||||||
|
latestMigrations := m.LatestMigrations()
|
||||||
|
|
||||||
|
if latestMigrations.Version.Equal(semver.MustParse(portainer.APIVersion)) {
|
||||||
|
migratorCount = len(latestMigrations.MigrationFuncs)
|
||||||
|
}
|
||||||
|
|
||||||
|
return migratorCount
|
||||||
|
}
|
||||||
|
|
||||||
// !NOTE: Migration funtions should ideally be idempotent.
|
// !NOTE: Migration funtions should ideally be idempotent.
|
||||||
// ! Which simply means the function can run over the same data many times but only transform it once.
|
// ! Which simply means the function can run over the same data many times but only transform it once.
|
||||||
// ! In practice this really just means an extra check or two to ensure we're not destroying valid data.
|
// ! In practice this really just means an extra check or two to ensure we're not destroying valid data.
|
||||||
|
|
Loading…
Reference in New Issue