Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions migrator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"net/http"
"os"
"strings"

"github.com/jackc/pgx/v4/pgxpool"
"github.com/pkg/errors"
Expand All @@ -25,6 +26,7 @@ import (
pkgSchema "github.com/stackrox/rox/pkg/postgres/schema"
"github.com/stackrox/rox/pkg/rocksdb"
"github.com/stackrox/rox/pkg/sac"
"github.com/stackrox/rox/pkg/version"
"github.com/tecbot/gorocksdb"
"go.etcd.io/bbolt"
"gorm.io/gorm"
Expand Down Expand Up @@ -52,7 +54,7 @@ func startProfilingServer() {
}

func run() error {
log.WriteToStderr("In migrator.run()")
log.WriteToStderrf("Run migrator.run() with version: %s, DB sequence: %d", version.GetMainVersion(), migrations.CurrentDBVersionSeqNum())
conf := config.GetConfig()
if conf == nil {
log.WriteToStderrf("cannot get central configuration. Skipping migrator")
Expand All @@ -64,16 +66,21 @@ func run() error {
return nil
}

rollbackVersion := strings.TrimSpace(conf.Maintenance.ForceRollbackVersion)
if rollbackVersion != "" {
log.WriteToStderrf("conf.Maintenance.ForceRollbackVersion: %s", rollbackVersion)
}

var dbm cloneMgr.DBCloneManager
// Create the clone manager
if env.PostgresDatastoreEnabled.BooleanSetting() {
sourceMap, adminConfig, err := pgconfig.GetPostgresConfig()
if err != nil {
return errors.Wrap(err, "unable to get Postgres DB config")
}
dbm = cloneMgr.NewPostgres(migrations.DBMountPath(), conf.Maintenance.ForceRollbackVersion, adminConfig, sourceMap)
dbm = cloneMgr.NewPostgres(migrations.DBMountPath(), rollbackVersion, adminConfig, sourceMap)
} else {
dbm = cloneMgr.New(migrations.DBMountPath(), conf.Maintenance.ForceRollbackVersion)
dbm = cloneMgr.New(migrations.DBMountPath(), rollbackVersion)
}

err := dbm.Scan()
Expand Down