mirror of https://github.com/portainer/portainer
fix(db/migration): avoid fatal error from being overwritten (#10317)
parent
034157be9a
commit
46949508a4
|
@ -158,13 +158,13 @@ func initDataStore(flags *portainer.CLIFlags, secretKey []byte, fileService port
|
||||||
}
|
}
|
||||||
|
|
||||||
// checkDBSchemaServerVersionMatch checks if the server version matches the db scehma version
|
// checkDBSchemaServerVersionMatch checks if the server version matches the db scehma version
|
||||||
func checkDBSchemaServerVersionMatch(dbStore dataservices.DataStore, serverVersion string) bool {
|
func checkDBSchemaServerVersionMatch(dbStore dataservices.DataStore, serverVersion string, serverEdition int) bool {
|
||||||
v, err := dbStore.Version().Version()
|
v, err := dbStore.Version().Version()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
return v.SchemaVersion == serverVersion && v.Edition == int(portainer.Edition)
|
return v.SchemaVersion == serverVersion && v.Edition == serverEdition
|
||||||
}
|
}
|
||||||
|
|
||||||
func initComposeStackManager(composeDeployer libstack.Deployer, proxyManager *proxy.Manager) portainer.ComposeStackManager {
|
func initComposeStackManager(composeDeployer libstack.Deployer, proxyManager *proxy.Manager) portainer.ComposeStackManager {
|
||||||
|
@ -399,7 +399,7 @@ func buildServer(flags *portainer.CLIFlags) portainer.Server {
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if the db schema version matches with server version
|
// check if the db schema version matches with server version
|
||||||
if !checkDBSchemaServerVersionMatch(dataStore, portainer.APIVersion) {
|
if !checkDBSchemaServerVersionMatch(dataStore, portainer.APIVersion, int(portainer.Edition)) {
|
||||||
log.Fatal().Msg("The database schema version does not align with the server version. Please consider reverting to the previous server version or addressing the database migration issue.")
|
log.Fatal().Msg("The database schema version does not align with the server version. Please consider reverting to the previous server version or addressing the database migration issue.")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,9 +51,9 @@ func (store *Store) MigrateData() error {
|
||||||
err = errors.Wrap(err, "failed to migrate database")
|
err = errors.Wrap(err, "failed to migrate database")
|
||||||
|
|
||||||
log.Warn().Err(err).Msg("migration failed, restoring database to previous version")
|
log.Warn().Err(err).Msg("migration failed, restoring database to previous version")
|
||||||
err = store.restoreWithOptions(&BackupOptions{BackupPath: backupPath})
|
restorErr := store.restoreWithOptions(&BackupOptions{BackupPath: backupPath})
|
||||||
if err != nil {
|
if restorErr != nil {
|
||||||
return errors.Wrap(err, "failed to restore database")
|
return errors.Wrap(restorErr, "failed to restore database")
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Info().Msg("database restored to previous version")
|
log.Info().Msg("database restored to previous version")
|
||||||
|
|
Loading…
Reference in New Issue