Skip to content

Commit

Permalink
[fa_table] update is_primary to non-null (#496)
Browse files Browse the repository at this point in the history
* add index back

* set fields to nonnull

* change default is_primary value

* adding is_primary migration

---------

Co-authored-by: bowenyang007 <[email protected]>
  • Loading branch information
lightmark and bowenyang007 authored Sep 4, 2024
1 parent 9200855 commit 82ae5ff
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ pub struct CurrentUnifiedFungibleAssetBalance {
// metadata address for (paired) Fungible Asset
pub asset_type_v1: Option<String>,
pub asset_type_v2: Option<String>,
pub is_primary: Option<bool>,
pub is_primary: bool,
pub is_frozen: bool,
pub amount_v1: Option<BigDecimal>,
pub amount_v2: Option<BigDecimal>,
Expand Down Expand Up @@ -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()),
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Original file line number Diff line number Diff line change
@@ -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;
Original file line number Diff line number Diff line change
@@ -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;
4 changes: 2 additions & 2 deletions rust/processor/src/db/postgres/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,11 +431,11 @@ diesel::table! {
asset_type_v2 -> Nullable<Varchar>,
#[max_length = 1000]
asset_type_v1 -> Nullable<Varchar>,
is_primary -> Nullable<Bool>,
is_primary -> Bool,
is_frozen -> Bool,
amount_v1 -> Nullable<Numeric>,
amount_v2 -> Nullable<Numeric>,
amount -> Nullable<Numeric>,
amount -> Numeric,
last_transaction_version_v1 -> Nullable<Int8>,
last_transaction_version_v2 -> Nullable<Int8>,
last_transaction_version -> Nullable<Int8>,
Expand Down
4 changes: 3 additions & 1 deletion rust/processor/src/processors/fungible_asset_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 82ae5ff

Please sign in to comment.