diff --git a/api/bolt/migrator/migrate_dbversion30.go b/api/bolt/migrator/migrate_dbversion30.go index 47543fe13..77b9023c1 100644 --- a/api/bolt/migrator/migrate_dbversion30.go +++ b/api/bolt/migrator/migrate_dbversion30.go @@ -1,6 +1,13 @@ package migrator -func (m *Migrator) updateSettingsToDB31() error { +func (m *Migrator) migrateDBVersionTo30() error { + if err := m.migrateSettings(); err != nil { + return err + } + return nil +} + +func (m *Migrator) migrateSettings() error { legacySettings, err := m.settingsService.Settings() if err != nil { return err diff --git a/api/bolt/migrator/migrate_dbversion30_test.go b/api/bolt/migrator/migrate_dbversion30_test.go index d4597fffa..42f09b4ab 100644 --- a/api/bolt/migrator/migrate_dbversion30_test.go +++ b/api/bolt/migrator/migrate_dbversion30_test.go @@ -2,9 +2,12 @@ package migrator import ( "os" + "path" "testing" + "time" "github.com/boltdb/bolt" + "github.com/portainer/portainer/api/bolt/internal" "github.com/portainer/portainer/api/bolt/settings" ) @@ -16,6 +19,34 @@ var ( settingsService *settings.Service ) +// initTestingDBConn creates a raw bolt DB connection +// for unit testing usage only since using NewStore will cause cycle import inside migrator pkg +func initTestingDBConn(storePath, fileName string) (*bolt.DB, error) { + databasePath := path.Join(storePath, fileName) + dbConn, err := bolt.Open(databasePath, 0600, &bolt.Options{Timeout: 1 * time.Second}) + if err != nil { + return nil, err + } + return dbConn, nil +} + +// initTestingDBConn creates a settings service with raw bolt DB connection +// for unit testing usage only since using NewStore will cause cycle import inside migrator pkg +func initTestingSettingsService(dbConn *bolt.DB, preSetObj map[string]interface{}) (*settings.Service, error) { + internalDBConn := &internal.DbConnection{ + DB: dbConn, + } + settingsService, err := settings.NewService(internalDBConn) + if err != nil { + return nil, err + } + //insert a obj + if err := internal.UpdateObject(internalDBConn, "settings", []byte("SETTINGS"), preSetObj); err != nil { + return nil, err + } + return settingsService, nil +} + func setup() error { testingDBStorePath, _ = os.Getwd() testingDBFileName = "portainer-ee-mig-30.db" @@ -35,7 +66,7 @@ func setup() error { return nil } -func TestUpdateSettingsToDB31(t *testing.T) { +func TestMigrateSettings(t *testing.T) { if err := setup(); err != nil { t.Errorf("failed to complete testing setups, err: %v", err) } @@ -45,7 +76,7 @@ func TestUpdateSettingsToDB31(t *testing.T) { db: dbConn, settingsService: settingsService, } - if err := m.updateSettingsToDB31(); err != nil { + if err := m.migrateSettings(); err != nil { t.Errorf("failed to update settings: %v", err) } updatedSettings, err := m.settingsService.Settings() diff --git a/api/bolt/migrator/migrate_test_helper.go b/api/bolt/migrator/migrate_test_helper.go deleted file mode 100644 index 5b02c9d6a..000000000 --- a/api/bolt/migrator/migrate_test_helper.go +++ /dev/null @@ -1,38 +0,0 @@ -package migrator - -import ( - "path" - "time" - - "github.com/boltdb/bolt" - "github.com/portainer/portainer/api/bolt/internal" - "github.com/portainer/portainer/api/bolt/settings" -) - -// initTestingDBConn creates a raw bolt DB connection -// for unit testing usage only since using NewStore will cause cycle import inside migrator pkg -func initTestingDBConn(storePath, fileName string) (*bolt.DB, error) { - databasePath := path.Join(storePath, fileName) - dbConn, err := bolt.Open(databasePath, 0600, &bolt.Options{Timeout: 1 * time.Second}) - if err != nil { - return nil, err - } - return dbConn, nil -} - -// initTestingDBConn creates a settings service with raw bolt DB connection -// for unit testing usage only since using NewStore will cause cycle import inside migrator pkg -func initTestingSettingsService(dbConn *bolt.DB, preSetObj map[string]interface{}) (*settings.Service, error) { - internalDBConn := &internal.DbConnection{ - DB: dbConn, - } - settingsService, err := settings.NewService(internalDBConn) - if err != nil { - return nil, err - } - //insert a obj - if err := internal.UpdateObject(internalDBConn, "settings", []byte("SETTINGS"), preSetObj); err != nil { - return nil, err - } - return settingsService, nil -} diff --git a/api/bolt/migrator/migrator.go b/api/bolt/migrator/migrator.go index 9e8499379..8d99b5bfa 100644 --- a/api/bolt/migrator/migrator.go +++ b/api/bolt/migrator/migrator.go @@ -358,9 +358,9 @@ func (m *Migrator) Migrate() error { } } - // Portainer 2.5.0 - if m.currentDBVersion < 31 { - err := m.updateSettingsToDB31() + // Portainer 2.6.0 + if m.currentDBVersion < 30 { + err := m.migrateDBVersionTo30() if err != nil { return err } diff --git a/api/portainer.go b/api/portainer.go index 512cb8ae0..5ead33d64 100644 --- a/api/portainer.go +++ b/api/portainer.go @@ -1336,7 +1336,7 @@ const ( // APIVersion is the version number of the Portainer API APIVersion = "2.5.1" // DBVersion is the version number of the Portainer database - DBVersion = 31 + DBVersion = 30 // ComposeSyntaxMaxVersion is a maximum supported version of the docker compose syntax ComposeSyntaxMaxVersion = "3.9" // AssetsServerURL represents the URL of the Portainer asset server