storagenode/storagenodedb: allow existing dbs on setup

Allow existing storagenode dbs on setup to be able to reinstall
the node with existing data.

Change-Id: Ib42ab585432e61dfecc10640b6cd755ce83f0c46
This commit is contained in:
Yaroslav Vorobiov 2020-09-28 16:30:10 +03:00
parent 4a2c66fa06
commit 8786e55a78

View File

@ -277,7 +277,7 @@ func (db *DB) createDatabases() error {
}
for _, dbName := range dbs {
err := db.createDatabase(dbName)
err := db.openDatabase(dbName)
if err != nil {
return errs.Combine(err, db.closeDatabases())
}
@ -323,19 +323,6 @@ func (db *DB) rawDatabaseFromName(dbName string) tagsql.DB {
return db.SQLDBs[dbName].GetDB()
}
// createDatabase creates new database at the specified path, returns err if db exists.
func (db *DB) createDatabase(dbName string) error {
path := db.filepathFromDBName(dbName)
if _, err := os.Stat(path); err == nil {
return ErrDatabase.New("database %s already exists", dbName)
} else if !os.IsNotExist(err) {
return ErrDatabase.Wrap(err)
}
return db.openDatabase(dbName)
}
// openExistingDatabase opens existing database at the specified path.
func (db *DB) openExistingDatabase(dbName string) error {
path := db.filepathFromDBName(dbName)