11//! Utilities for managing database schema changes.
2- mod migration_schema_v20;
3- mod migration_schema_v21;
4- mod migration_schema_v22;
52mod migration_schema_v23;
63
74use crate :: beacon_chain:: BeaconChainTypes ;
85use std:: sync:: Arc ;
96use store:: hot_cold_store:: { HotColdDB , HotColdDBError } ;
107use store:: metadata:: { SchemaVersion , CURRENT_SCHEMA_VERSION } ;
118use store:: Error as StoreError ;
12- use types:: Hash256 ;
139
1410/// Migrate the database from one schema version to another, applying all requisite mutations.
1511pub fn migrate_schema < T : BeaconChainTypes > (
1612 db : Arc < HotColdDB < T :: EthSpec , T :: HotStore , T :: ColdStore > > ,
17- genesis_state_root : Option < Hash256 > ,
1813 from : SchemaVersion ,
1914 to : SchemaVersion ,
2015) -> Result < ( ) , StoreError > {
@@ -24,40 +19,19 @@ pub fn migrate_schema<T: BeaconChainTypes>(
2419 // Upgrade across multiple versions by recursively migrating one step at a time.
2520 ( _, _) if from. as_u64 ( ) + 1 < to. as_u64 ( ) => {
2621 let next = SchemaVersion ( from. as_u64 ( ) + 1 ) ;
27- migrate_schema :: < T > ( db. clone ( ) , genesis_state_root , from, next) ?;
28- migrate_schema :: < T > ( db, genesis_state_root , next, to)
22+ migrate_schema :: < T > ( db. clone ( ) , from, next) ?;
23+ migrate_schema :: < T > ( db, next, to)
2924 }
3025 // Downgrade across multiple versions by recursively migrating one step at a time.
3126 ( _, _) if to. as_u64 ( ) + 1 < from. as_u64 ( ) => {
3227 let next = SchemaVersion ( from. as_u64 ( ) - 1 ) ;
33- migrate_schema :: < T > ( db. clone ( ) , genesis_state_root , from, next) ?;
34- migrate_schema :: < T > ( db, genesis_state_root , next, to)
28+ migrate_schema :: < T > ( db. clone ( ) , from, next) ?;
29+ migrate_schema :: < T > ( db, next, to)
3530 }
3631
3732 //
38- // Migrations from before SchemaVersion(19 ) are deprecated.
33+ // Migrations from before SchemaVersion(22 ) are deprecated.
3934 //
40- ( SchemaVersion ( 19 ) , SchemaVersion ( 20 ) ) => {
41- let ops = migration_schema_v20:: upgrade_to_v20 :: < T > ( db. clone ( ) ) ?;
42- db. store_schema_version_atomically ( to, ops)
43- }
44- ( SchemaVersion ( 20 ) , SchemaVersion ( 19 ) ) => {
45- let ops = migration_schema_v20:: downgrade_from_v20 :: < T > ( db. clone ( ) ) ?;
46- db. store_schema_version_atomically ( to, ops)
47- }
48- ( SchemaVersion ( 20 ) , SchemaVersion ( 21 ) ) => {
49- let ops = migration_schema_v21:: upgrade_to_v21 :: < T > ( db. clone ( ) ) ?;
50- db. store_schema_version_atomically ( to, ops)
51- }
52- ( SchemaVersion ( 21 ) , SchemaVersion ( 20 ) ) => {
53- let ops = migration_schema_v21:: downgrade_from_v21 :: < T > ( db. clone ( ) ) ?;
54- db. store_schema_version_atomically ( to, ops)
55- }
56- ( SchemaVersion ( 21 ) , SchemaVersion ( 22 ) ) => {
57- // This migration needs to sync data between hot and cold DBs. The schema version is
58- // bumped inside the upgrade_to_v22 fn
59- migration_schema_v22:: upgrade_to_v22 :: < T > ( db. clone ( ) , genesis_state_root)
60- }
6135 ( SchemaVersion ( 22 ) , SchemaVersion ( 23 ) ) => {
6236 let ops = migration_schema_v23:: upgrade_to_v23 :: < T > ( db. clone ( ) ) ?;
6337 db. store_schema_version_atomically ( to, ops)
0 commit comments