1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-24 07:49:41 +02:00

fix(migration) datastore always marked new and migrations skipped EE-1775 (#5788)

* fix issue with broken store init

* minor logic improvement

* Remove fileexists logic as its redundant and handled implicitely by bolt.Open

* Added re-open test on IsNew flag.  Essential for migrations to be able to run
This commit is contained in:
Matt Hook 2021-10-01 20:35:43 +13:00 committed by GitHub
parent fc4ff59bfd
commit 6bd72d21a8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 25 deletions

View file

@ -90,20 +90,13 @@ func (store *Store) edition() portainer.SoftwareEdition {
}
// NewStore initializes a new Store and the associated services
func NewStore(storePath string, fileService portainer.FileService) (*Store, error) {
store := &Store{
func NewStore(storePath string, fileService portainer.FileService) *Store {
return &Store{
path: storePath,
fileService: fileService,
isNew: true,
connection: &internal.DbConnection{},
}
databasePath := path.Join(storePath, databaseFileName)
if _, err := fileService.FileExists(databasePath); err != nil {
return nil, err
}
return store, nil
}
// Open opens and initializes the BoltDB database.
@ -120,10 +113,9 @@ func (store *Store) Open() error {
return err
}
//if failed to retrieve DBVersion from database
//treat it as a new store
if _, err := store.VersionService.DBVersion(); err != nil {
store.isNew = true
// if we have DBVersion in the database then ensure we flag this as NOT a new store
if _, err := store.VersionService.DBVersion(); err == nil {
store.isNew = false
}
return nil