prysm-pulse/validator/db/kv/migration.go
Raul Jordan 4c19e622cd
Implement Migration Up/Down Logic for Validator DB (#8271)
* rollback logic

* implement up down logic

* begin down migration tests

* rollback works

* unset test

* remove iface

* gaz

* add comment

* fix ineff assign

* preston comment

* add progress
2021-01-15 15:35:21 -06:00

54 lines
1.0 KiB
Go

package kv
import (
"context"
bolt "go.etcd.io/bbolt"
)
type migration func(*bolt.Tx) error
var (
migrationCompleted = []byte("done")
upMigrations = []migration{}
downMigrations = []migration{}
)
// RunUpMigrations defined in the upMigrations list.
func (s *Store) RunUpMigrations(ctx context.Context) error {
// Run any special migrations that require special conditions.
if err := s.migrateOptimalAttesterProtectionUp(ctx); err != nil {
return err
}
for _, m := range upMigrations {
if ctx.Err() != nil {
return ctx.Err()
}
if err := s.db.Update(m); err != nil {
return err
}
}
return nil
}
// RunDownMigrations defined in the downMigrations list.
func (s *Store) RunDownMigrations(ctx context.Context) error {
// Run any special migrations that require special conditions.
if err := s.migrateOptimalAttesterProtectionDown(ctx); err != nil {
return err
}
for _, m := range downMigrations {
if ctx.Err() != nil {
return ctx.Err()
}
if err := s.db.Update(m); err != nil {
return err
}
}
return nil
}