Skip to content

Commit

Permalink
simplifies code
Browse files Browse the repository at this point in the history
  • Loading branch information
Elod23 committed Aug 2, 2023
1 parent 28ca062 commit a550068
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
12 changes: 6 additions & 6 deletions internal/storage/pebble/migrations/0_dag_removeSender.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,19 @@ func (m *RemoveSenderMigration) Apply(s *pebble.Storage) error {
Timestamp: o.Timestamp,
TransactionCount: o.TransactionCount,
}
batch.AddToBatchFullKey(&dag, key)
err = batch.AddToBatchFullKey(&dag, key)

if err != nil {
log.WithFields(log.Fields{"migration": m.id, "error": err}).Fatal("Error adding Dag to batch")
}

last_key = key
count++
if count == DAG_BATCH_THRESHOLD {
return true
}
return false
return count == DAG_BATCH_THRESHOLD
})

if count < DAG_BATCH_THRESHOLD {
batch.CommitBatch()
done = true
break
}
}
Expand Down
11 changes: 7 additions & 4 deletions internal/storage/pebble/migrations/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,21 @@ func (m *Manager) IsApplied(migration Migration) bool {
return err == nil
}

func (m *Manager) ApplyAll() error {
func (m *Manager) ApplyAll() (err error) {
log.Info("Migration Manager: Running migrations")
for _, migration := range m.migrations {
isApplied := m.IsApplied(migration)
if !isApplied {
log.WithFields(log.Fields{"migration": migration.GetId()}).Info("Running migration")
err := migration.Apply(m.s)
err = migration.Apply(m.s)
if err != nil {
return err
return
}
b := m.s.NewBatch()
b.AddToBatchFullKey(migration.GetId(), []byte(migration_prefix+migration.GetId()))
err = b.AddToBatchFullKey(migration.GetId(), []byte(migration_prefix+migration.GetId()))
if err != nil {
return
}
b.CommitBatch()
log.WithFields(log.Fields{"migration": migration.GetId()}).Info("Applied migration")
} else {
Expand Down

0 comments on commit a550068

Please sign in to comment.