github.com/prysmaticlabs/prysm@v1.4.4/validator/db/kv/migration.go (about)

     1  package kv
     2  
     3  import (
     4  	"context"
     5  
     6  	bolt "go.etcd.io/bbolt"
     7  )
     8  
     9  type migration func(*bolt.Tx) error
    10  
    11  var (
    12  	migrationCompleted = []byte("done")
    13  	upMigrations       []migration
    14  	downMigrations     []migration
    15  )
    16  
    17  // RunUpMigrations defined in the upMigrations list.
    18  func (s *Store) RunUpMigrations(ctx context.Context) error {
    19  	// Run any special migrations that require special conditions.
    20  	if err := s.migrateOptimalAttesterProtectionUp(ctx); err != nil {
    21  		return err
    22  	}
    23  	if err := s.migrateSourceTargetEpochsBucketUp(ctx); err != nil {
    24  		return err
    25  	}
    26  
    27  	for _, m := range upMigrations {
    28  		if ctx.Err() != nil {
    29  			return ctx.Err()
    30  		}
    31  
    32  		if err := s.db.Update(m); err != nil {
    33  			return err
    34  		}
    35  	}
    36  	return nil
    37  }
    38  
    39  // RunDownMigrations defined in the downMigrations list.
    40  func (s *Store) RunDownMigrations(ctx context.Context) error {
    41  	// Run any special migrations that require special conditions.
    42  	if err := s.migrateOptimalAttesterProtectionDown(ctx); err != nil {
    43  		return err
    44  	}
    45  	if err := s.migrateSourceTargetEpochsBucketDown(ctx); err != nil {
    46  		return err
    47  	}
    48  
    49  	for _, m := range downMigrations {
    50  		if ctx.Err() != nil {
    51  			return ctx.Err()
    52  		}
    53  
    54  		if err := s.db.Update(m); err != nil {
    55  			return err
    56  		}
    57  	}
    58  	return nil
    59  }