mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-14 05:58:19 +00:00
4c19e622cd
* 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
54 lines
1.0 KiB
Go
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
|
|
}
|