Fix schema version jump

This commit is contained in:
Michael Sproul
2022-05-24 12:28:42 +10:00
parent b774a1c3f1
commit 30b031da32

View File

@@ -26,6 +26,12 @@ pub fn migrate_schema<T: BeaconChainTypes>(
match (from, to) {
// Migrating from the current schema version to iself is always OK, a no-op.
(_, _) if from == to && to == CURRENT_SCHEMA_VERSION => Ok(()),
// Upgrade for tree-states database changes.
(SchemaVersion(9), SchemaVersion(20)) => migration_schema_v20::upgrade_to_v20::<T>(db, log),
// Downgrade for tree-states database changes.
(SchemaVersion(20), SchemaVersion(9)) => {
migration_schema_v20::downgrade_from_v20::<T>(db, log)
}
// Upgrade across multiple versions by recursively migrating one step at a time.
(_, _) if from.as_u64() + 1 < to.as_u64() => {
let next = SchemaVersion(from.as_u64() + 1);
@@ -128,12 +134,6 @@ pub fn migrate_schema<T: BeaconChainTypes>(
migration_schema_v9::downgrade_from_v9::<T>(db.clone(), log)?;
db.store_schema_version(to)
}
// Upgrade for tree-states database changes.
(SchemaVersion(9), SchemaVersion(20)) => migration_schema_v20::upgrade_to_v20::<T>(db, log),
// Downgrade for tree-states database changes.
(SchemaVersion(20), SchemaVersion(9)) => {
migration_schema_v20::downgrade_from_v20::<T>(db, log)
}
// Anything else is an error.
(_, _) => Err(HotColdDBError::UnsupportedSchemaVersion {
target_version: to,