2020-12-16 03:33:04 +00:00
|
|
|
package kv
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
bolt "go.etcd.io/bbolt"
|
|
|
|
)
|
|
|
|
|
|
|
|
type migration func(*bolt.Tx) error
|
|
|
|
|
2021-01-15 21:35:21 +00:00
|
|
|
var (
|
|
|
|
migrationCompleted = []byte("done")
|
2021-02-05 18:39:15 +00:00
|
|
|
upMigrations []migration
|
|
|
|
downMigrations []migration
|
2021-01-15 21:35:21 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// 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
|
|
|
|
}
|
2021-02-17 19:23:59 +00:00
|
|
|
if err := s.migrateSourceTargetEpochsBucketUp(ctx); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2021-01-15 21:35:21 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|
2021-02-17 19:23:59 +00:00
|
|
|
if err := s.migrateSourceTargetEpochsBucketDown(ctx); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-12-16 03:33:04 +00:00
|
|
|
|
2021-01-15 21:35:21 +00:00
|
|
|
for _, m := range downMigrations {
|
2020-12-16 03:33:04 +00:00
|
|
|
if ctx.Err() != nil {
|
|
|
|
return ctx.Err()
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := s.db.Update(m); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|