diff --git a/rust/processor/src/db/common/models/fungible_asset_models/v2_fungible_asset_balances.rs b/rust/processor/src/db/common/models/fungible_asset_models/v2_fungible_asset_balances.rs index 57b44f9b0..3bf244824 100644 --- a/rust/processor/src/db/common/models/fungible_asset_models/v2_fungible_asset_balances.rs +++ b/rust/processor/src/db/common/models/fungible_asset_models/v2_fungible_asset_balances.rs @@ -78,7 +78,7 @@ pub struct CurrentUnifiedFungibleAssetBalance { // metadata address for (paired) Fungible Asset pub asset_type_v1: Option, pub asset_type_v2: Option, - pub is_primary: Option, + pub is_primary: bool, pub is_frozen: bool, pub amount_v1: Option, pub amount_v2: Option, @@ -117,7 +117,7 @@ impl From<&CurrentFungibleAssetBalance> for CurrentUnifiedFungibleAssetBalance { owner_address: cfab.owner_address.clone(), asset_type_v2: Some(cfab.asset_type.clone()), asset_type_v1: None, - is_primary: Some(cfab.is_primary), + is_primary: cfab.is_primary, is_frozen: cfab.is_frozen, amount_v1: None, amount_v2: Some(cfab.amount.clone()), @@ -135,7 +135,7 @@ impl From<&CurrentFungibleAssetBalance> for CurrentUnifiedFungibleAssetBalance { owner_address: cfab.owner_address.clone(), asset_type_v2: None, asset_type_v1: Some(cfab.asset_type.clone()), - is_primary: None, + is_primary: true, is_frozen: cfab.is_frozen, amount_v1: Some(cfab.amount.clone()), amount_v2: None, diff --git a/rust/processor/src/db/postgres/migrations/2024-08-20-224736_fa_migration_fix_part1/up.sql b/rust/processor/src/db/postgres/migrations/2024-08-20-224736_fa_migration_fix_part1/up.sql index bf6528785..cfdd4071a 100644 --- a/rust/processor/src/db/postgres/migrations/2024-08-20-224736_fa_migration_fix_part1/up.sql +++ b/rust/processor/src/db/postgres/migrations/2024-08-20-224736_fa_migration_fix_part1/up.sql @@ -1,4 +1,6 @@ -- Your SQL goes here +--truncate table because there are a bunch of changes that might pose a problem with existing data +TRUNCATE TABLE current_unified_fungible_asset_balances_to_be_renamed; -- removing generated fields because we're redoing them ALTER TABLE current_unified_fungible_asset_balances_to_be_renamed DROP COLUMN IF EXISTS asset_type; ALTER TABLE current_unified_fungible_asset_balances_to_be_renamed DROP COLUMN IF EXISTS token_standard; \ No newline at end of file diff --git a/rust/processor/src/db/postgres/migrations/2024-08-30-170635_is_primary_nullable_fix/down.sql b/rust/processor/src/db/postgres/migrations/2024-08-30-170635_is_primary_nullable_fix/down.sql new file mode 100644 index 000000000..fda9e35c6 --- /dev/null +++ b/rust/processor/src/db/postgres/migrations/2024-08-30-170635_is_primary_nullable_fix/down.sql @@ -0,0 +1,5 @@ +-- This file should undo anything in `up.sql` +ALTER TABLE IF EXISTS current_fungible_asset_balances +ALTER COLUMN is_primary DROP NOT NULL; +ALTER TABLE IF EXISTS current_fungible_asset_balances +ALTER COLUMN amount DROP NOT NULL; \ No newline at end of file diff --git a/rust/processor/src/db/postgres/migrations/2024-08-30-170635_is_primary_nullable_fix/up.sql b/rust/processor/src/db/postgres/migrations/2024-08-30-170635_is_primary_nullable_fix/up.sql new file mode 100644 index 000000000..de5864438 --- /dev/null +++ b/rust/processor/src/db/postgres/migrations/2024-08-30-170635_is_primary_nullable_fix/up.sql @@ -0,0 +1,7 @@ +-- Your SQL goes here +ALTER TABLE IF EXISTS current_fungible_asset_balances +ALTER COLUMN is_primary +SET NOT NULL; +ALTER TABLE IF EXISTS current_fungible_asset_balances +ALTER COLUMN amount +SET NOT NULL; \ No newline at end of file diff --git a/rust/processor/src/db/postgres/schema.rs b/rust/processor/src/db/postgres/schema.rs index a35e5f447..43f091757 100644 --- a/rust/processor/src/db/postgres/schema.rs +++ b/rust/processor/src/db/postgres/schema.rs @@ -431,11 +431,11 @@ diesel::table! { asset_type_v2 -> Nullable, #[max_length = 1000] asset_type_v1 -> Nullable, - is_primary -> Nullable, + is_primary -> Bool, is_frozen -> Bool, amount_v1 -> Nullable, amount_v2 -> Nullable, - amount -> Nullable, + amount -> Numeric, last_transaction_version_v1 -> Nullable, last_transaction_version_v2 -> Nullable, last_transaction_version -> Nullable, diff --git a/rust/processor/src/processors/fungible_asset_processor.rs b/rust/processor/src/processors/fungible_asset_processor.rs index da9a48c17..704ed4bfe 100644 --- a/rust/processor/src/processors/fungible_asset_processor.rs +++ b/rust/processor/src/processors/fungible_asset_processor.rs @@ -379,9 +379,11 @@ impl ProcessorTrait for FungibleAssetProcessor { { (vec![], vec![]) } else { + // Basically we need to split the current unified balances into v1 and v2 + // by looking at whether asset_type_v1 is null (must be v1 if not null) current_unified_fungible_asset_balances .into_iter() - .partition(|x| x.is_primary.is_none()) + .partition(|x| x.asset_type_v1.is_some()) }; if self