1
1
//! Utilities for managing database schema changes.
2
- mod migration_schema_v20;
3
- mod migration_schema_v21;
4
- mod migration_schema_v22;
5
2
mod migration_schema_v23;
6
3
7
4
use crate :: beacon_chain:: BeaconChainTypes ;
8
5
use std:: sync:: Arc ;
9
6
use store:: hot_cold_store:: { HotColdDB , HotColdDBError } ;
10
7
use store:: metadata:: { SchemaVersion , CURRENT_SCHEMA_VERSION } ;
11
8
use store:: Error as StoreError ;
12
- use types:: Hash256 ;
13
9
14
10
/// Migrate the database from one schema version to another, applying all requisite mutations.
15
11
pub fn migrate_schema < T : BeaconChainTypes > (
16
12
db : Arc < HotColdDB < T :: EthSpec , T :: HotStore , T :: ColdStore > > ,
17
- genesis_state_root : Option < Hash256 > ,
18
13
from : SchemaVersion ,
19
14
to : SchemaVersion ,
20
15
) -> Result < ( ) , StoreError > {
@@ -24,40 +19,19 @@ pub fn migrate_schema<T: BeaconChainTypes>(
24
19
// Upgrade across multiple versions by recursively migrating one step at a time.
25
20
( _, _) if from. as_u64 ( ) + 1 < to. as_u64 ( ) => {
26
21
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)
29
24
}
30
25
// Downgrade across multiple versions by recursively migrating one step at a time.
31
26
( _, _) if to. as_u64 ( ) + 1 < from. as_u64 ( ) => {
32
27
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)
35
30
}
36
31
37
32
//
38
- // Migrations from before SchemaVersion(19 ) are deprecated.
33
+ // Migrations from before SchemaVersion(22 ) are deprecated.
39
34
//
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
- }
61
35
( SchemaVersion ( 22 ) , SchemaVersion ( 23 ) ) => {
62
36
let ops = migration_schema_v23:: upgrade_to_v23 :: < T > ( db. clone ( ) ) ?;
63
37
db. store_schema_version_atomically ( to, ops)
0 commit comments