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
37 changes: 21 additions & 16 deletions cmd/integration/commands/stages.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,37 +414,42 @@ var cmdRunMigrations = &cobra.Command{
Short: "",
Run: func(cmd *cobra.Command, args []string) {
logger := debug.SetupCobra(cmd, "integration")
dbPaths := map[kv.Label]string{kv.ChainDB: chaindata}
migrateDB := func(label kv.Label, path string) {
logger.Info("Opening DB", "label", label, "path", path)
// Non-accede and exclusive mode - to apply creation of new tables if needed.
cfg := dbCfg(label, path).RemoveFlags(mdbx.Accede).Exclusive(true)
db, err := openDB(cfg, true, logger)
if err != nil {
logger.Error("Opening DB", "error", err)
return
}
defer db.Close()
// Nothing to do, migrations will be applied automatically
}

// Chaindata DB *must* be the first one because guaranteed to contain data in Config table
// (see openSnapshotOnce in allSnapshots below).
migrateDB(kv.ChainDB, chaindata)

// Migrations must be applied also to the consensus DB because ConsensusTables contain also ChaindataTables
// (see kv/tables.go).
consensus := strings.Replace(chaindata, "chaindata", "aura", 1)
if exists, err := dir.Exist(consensus); err == nil && exists {
dbPaths[kv.ConsensusDB] = consensus
migrateDB(kv.ConsensusDB, consensus)
} else {
consensus = strings.Replace(chaindata, "chaindata", "clique", 1)
if exists, err := dir.Exist(consensus); err == nil && exists {
dbPaths[kv.ConsensusDB] = consensus
migrateDB(kv.ConsensusDB, consensus)
}
}
// Migrations must be applied also to the Bor heimdall and polygon-bridge DBs.
heimdall := strings.Replace(chaindata, "chaindata", "heimdall", 1)
if exists, err := dir.Exist(heimdall); err == nil && exists {
dbPaths[kv.HeimdallDB] = heimdall
migrateDB(kv.HeimdallDB, heimdall)
}
polygonBridge := strings.Replace(chaindata, "chaindata", "polygon-bridge", 1)
if exists, err := dir.Exist(polygonBridge); err == nil && exists {
dbPaths[kv.PolygonBridgeDB] = polygonBridge
}
for dbLabel, dbPath := range dbPaths {
//non-accede and exclusive mode - to apply create new tables if need.
cfg := dbCfg(dbLabel, dbPath).RemoveFlags(mdbx.Accede).Exclusive(true)
db, err := openDB(cfg, true, logger)
if err != nil {
logger.Error("Opening DB", "error", err)
return
}
defer db.Close()
// Nothing to do, migrations will be applied automatically
migrateDB(kv.PolygonBridgeDB, polygonBridge)
}
},
}
Expand Down
Loading