Skip to content

Commit

Permalink
Fix pre upgrade schema (#1825)
Browse files Browse the repository at this point in the history
# Goal
The goal of this PR is to fix the pre migration issue that somehow got
slipped into `main` branch.
An example of the error is the following:

```
2023-12-21 20:34:20 Running pre_upgrade...
2023-12-21 20:34:20 (key, value) failed to decode at [238, 198, 243, 193, 61, 38, 174, 37, 7, 201, 155, 103, 81, 225, 158, 118, 13, 72, 203, 53, 182, 108, 220, 238, 63, 151, 213, 0, 114, 204, 79, 216, 6, 164, 163, 214, 215, 161, 241, 20, 108, 0]: Error
2023-12-21 20:34:20 (key, value) failed to decode at [238, 198, 243, 193, 61, 38, 174, 37, 7, 201, 155, 103, 81, 225, 158, 118, 13, 72, 203, 53, 182, 108, 220, 238, 63, 151, 213, 0, 114, 204, 79, 216, 7, 99, 201, 131, 129, 220, 137, 171, 101, 0]: Error
[More with other at values]

```

Related to #1693 

# Discussion
<!-- List discussion items -->

# Checklist
- [X] try-runtime was updated

# verification
 The try-runtime works as expected

![Screenshot 2023-12-21 at 1 53 04
PM](https://github.com/LibertyDSNP/frequency/assets/9152501/48652d58-0a08-4133-bab3-4398fdbf999f)
  • Loading branch information
aramikm authored Dec 22, 2023
1 parent 928f35d commit f45a2b5
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion pallets/schemas/src/migration/v3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ pub fn get_known_schemas() -> BTreeMap<SchemaId, Vec<u8>> {
pub mod old {
use super::*;
use common_primitives::schema::{ModelType, PayloadLocation, SchemaSettings};
use frame_support::storage_alias;

#[derive(Clone, Encode, Decode, PartialEq, Debug, TypeInfo, Eq, MaxEncodedLen)]
/// A structure defining a Schema information (excluding the payload)
Expand All @@ -60,6 +61,11 @@ pub mod old {
/// additional control settings for the schema
pub settings: SchemaSettings,
}

/// Old Storage for schema info struct data
#[storage_alias]
pub(crate) type SchemaInfos<T: Config> =
StorageMap<Pallet<T>, Twox64Concat, SchemaId, OldSchemaInfo, OptionQuery>;
}

/// migration to v3 implementation
Expand All @@ -73,7 +79,7 @@ impl<T: Config> OnRuntimeUpgrade for MigrateToV3<T> {
#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<Vec<u8>, TryRuntimeError> {
log::info!(target: LOG_TARGET, "Running pre_upgrade...");
let count = SchemaInfos::<T>::iter().count() as u32;
let count = old::SchemaInfos::<T>::iter().count() as u32;
log::info!(target: LOG_TARGET, "Finish pre_upgrade for {:?}", count);
Ok(count.encode())
}
Expand Down

0 comments on commit f45a2b5

Please sign in to comment.