Skip to content

Commit 82ae5ff

Browse files
[fa_table] update is_primary to non-null (#496)
* add index back * set fields to nonnull * change default is_primary value * adding is_primary migration --------- Co-authored-by: bowenyang007 <[email protected]>
1 parent 9200855 commit 82ae5ff

File tree

6 files changed

+22
-6
lines changed

6 files changed

+22
-6
lines changed

rust/processor/src/db/common/models/fungible_asset_models/v2_fungible_asset_balances.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ pub struct CurrentUnifiedFungibleAssetBalance {
7878
// metadata address for (paired) Fungible Asset
7979
pub asset_type_v1: Option<String>,
8080
pub asset_type_v2: Option<String>,
81-
pub is_primary: Option<bool>,
81+
pub is_primary: bool,
8282
pub is_frozen: bool,
8383
pub amount_v1: Option<BigDecimal>,
8484
pub amount_v2: Option<BigDecimal>,
@@ -117,7 +117,7 @@ impl From<&CurrentFungibleAssetBalance> for CurrentUnifiedFungibleAssetBalance {
117117
owner_address: cfab.owner_address.clone(),
118118
asset_type_v2: Some(cfab.asset_type.clone()),
119119
asset_type_v1: None,
120-
is_primary: Some(cfab.is_primary),
120+
is_primary: cfab.is_primary,
121121
is_frozen: cfab.is_frozen,
122122
amount_v1: None,
123123
amount_v2: Some(cfab.amount.clone()),
@@ -135,7 +135,7 @@ impl From<&CurrentFungibleAssetBalance> for CurrentUnifiedFungibleAssetBalance {
135135
owner_address: cfab.owner_address.clone(),
136136
asset_type_v2: None,
137137
asset_type_v1: Some(cfab.asset_type.clone()),
138-
is_primary: None,
138+
is_primary: true,
139139
is_frozen: cfab.is_frozen,
140140
amount_v1: Some(cfab.amount.clone()),
141141
amount_v2: None,
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
-- Your SQL goes here
2+
--truncate table because there are a bunch of changes that might pose a problem with existing data
3+
TRUNCATE TABLE current_unified_fungible_asset_balances_to_be_renamed;
24
-- removing generated fields because we're redoing them
35
ALTER TABLE current_unified_fungible_asset_balances_to_be_renamed DROP COLUMN IF EXISTS asset_type;
46
ALTER TABLE current_unified_fungible_asset_balances_to_be_renamed DROP COLUMN IF EXISTS token_standard;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
-- This file should undo anything in `up.sql`
2+
ALTER TABLE IF EXISTS current_fungible_asset_balances
3+
ALTER COLUMN is_primary DROP NOT NULL;
4+
ALTER TABLE IF EXISTS current_fungible_asset_balances
5+
ALTER COLUMN amount DROP NOT NULL;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
-- Your SQL goes here
2+
ALTER TABLE IF EXISTS current_fungible_asset_balances
3+
ALTER COLUMN is_primary
4+
SET NOT NULL;
5+
ALTER TABLE IF EXISTS current_fungible_asset_balances
6+
ALTER COLUMN amount
7+
SET NOT NULL;

rust/processor/src/db/postgres/schema.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -431,11 +431,11 @@ diesel::table! {
431431
asset_type_v2 -> Nullable<Varchar>,
432432
#[max_length = 1000]
433433
asset_type_v1 -> Nullable<Varchar>,
434-
is_primary -> Nullable<Bool>,
434+
is_primary -> Bool,
435435
is_frozen -> Bool,
436436
amount_v1 -> Nullable<Numeric>,
437437
amount_v2 -> Nullable<Numeric>,
438-
amount -> Nullable<Numeric>,
438+
amount -> Numeric,
439439
last_transaction_version_v1 -> Nullable<Int8>,
440440
last_transaction_version_v2 -> Nullable<Int8>,
441441
last_transaction_version -> Nullable<Int8>,

rust/processor/src/processors/fungible_asset_processor.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,9 +379,11 @@ impl ProcessorTrait for FungibleAssetProcessor {
379379
{
380380
(vec![], vec![])
381381
} else {
382+
// Basically we need to split the current unified balances into v1 and v2
383+
// by looking at whether asset_type_v1 is null (must be v1 if not null)
382384
current_unified_fungible_asset_balances
383385
.into_iter()
384-
.partition(|x| x.is_primary.is_none())
386+
.partition(|x| x.asset_type_v1.is_some())
385387
};
386388

387389
if self

0 commit comments

Comments
 (0)