-
Notifications
You must be signed in to change notification settings - Fork 82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[2/2][FA migration] Complete fa migration and rename table #494
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
-- This file should undo anything in `up.sql` | ||
ALTER TABLE current_fungible_asset_balances | ||
RENAME TO current_unified_fungible_asset_balances_to_be_renamed; | ||
ALTER TABLE current_fungible_asset_balances_legacy | ||
RENAME TO current_fungible_asset_balances; | ||
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,15 @@ | ||
-- Your SQL goes here | ||
ALTER TABLE current_unified_fungible_asset_balances_to_be_renamed | ||
ADD COLUMN IF NOT EXISTS asset_type VARCHAR(1000) NOT NULL GENERATED ALWAYS AS (COALESCE(asset_type_v1, asset_type_v2)) STORED; | ||
CREATE INDEX IF NOT EXISTS cufab_owner_at_index ON current_unified_fungible_asset_balances_to_be_renamed (owner_address, asset_type); | ||
ALTER TABLE current_unified_fungible_asset_balances_to_be_renamed | ||
ADD COLUMN IF NOT EXISTS token_standard VARCHAR(10) NOT NULL GENERATED ALWAYS AS ( | ||
CASE | ||
WHEN asset_type_v1 IS NOT NULL THEN 'v1' | ||
ELSE 'v2' | ||
END | ||
) STORED; | ||
ALTER TABLE current_fungible_asset_balances | ||
RENAME TO current_fungible_asset_balances_legacy; | ||
ALTER TABLE current_unified_fungible_asset_balances_to_be_renamed | ||
RENAME TO current_fungible_asset_balances; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -423,6 +423,35 @@ diesel::table! { | |
|
||
diesel::table! { | ||
current_fungible_asset_balances (storage_id) { | ||
#[max_length = 66] | ||
storage_id -> Varchar, | ||
#[max_length = 66] | ||
owner_address -> Varchar, | ||
#[max_length = 66] | ||
asset_type_v2 -> Nullable<Varchar>, | ||
#[max_length = 1000] | ||
asset_type_v1 -> Nullable<Varchar>, | ||
is_primary -> Nullable<Bool>, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This shouldn't be nullable to match with the legacy schema There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Synced offline, this will be fixed in next PR There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this isn't related to this PR. only popped up due to renaming table. We'll address it next PR. |
||
is_frozen -> Bool, | ||
amount_v1 -> Nullable<Numeric>, | ||
amount_v2 -> Nullable<Numeric>, | ||
amount -> Nullable<Numeric>, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should not be nullable There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Synced offline, this will be fixed in next PR There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this isn't related to this PR. only popped up due to renaming table. We'll address it next PR. |
||
last_transaction_version_v1 -> Nullable<Int8>, | ||
last_transaction_version_v2 -> Nullable<Int8>, | ||
last_transaction_version -> Nullable<Int8>, | ||
last_transaction_timestamp_v1 -> Nullable<Timestamp>, | ||
last_transaction_timestamp_v2 -> Nullable<Timestamp>, | ||
last_transaction_timestamp -> Nullable<Timestamp>, | ||
inserted_at -> Timestamp, | ||
#[max_length = 1000] | ||
asset_type -> Varchar, | ||
#[max_length = 10] | ||
token_standard -> Varchar, | ||
} | ||
} | ||
|
||
diesel::table! { | ||
current_fungible_asset_balances_legacy (storage_id) { | ||
#[max_length = 66] | ||
storage_id -> Varchar, | ||
#[max_length = 66] | ||
|
@@ -651,31 +680,6 @@ diesel::table! { | |
} | ||
} | ||
|
||
diesel::table! { | ||
current_unified_fungible_asset_balances_to_be_renamed (storage_id) { | ||
#[max_length = 66] | ||
storage_id -> Varchar, | ||
#[max_length = 66] | ||
owner_address -> Varchar, | ||
#[max_length = 66] | ||
asset_type_v2 -> Nullable<Varchar>, | ||
#[max_length = 1000] | ||
asset_type_v1 -> Nullable<Varchar>, | ||
is_primary -> Nullable<Bool>, | ||
is_frozen -> Bool, | ||
amount_v1 -> Nullable<Numeric>, | ||
amount_v2 -> Nullable<Numeric>, | ||
amount -> Nullable<Numeric>, | ||
last_transaction_version_v1 -> Nullable<Int8>, | ||
last_transaction_version_v2 -> Nullable<Int8>, | ||
last_transaction_version -> Nullable<Int8>, | ||
last_transaction_timestamp_v1 -> Nullable<Timestamp>, | ||
last_transaction_timestamp_v2 -> Nullable<Timestamp>, | ||
last_transaction_timestamp -> Nullable<Timestamp>, | ||
inserted_at -> Timestamp, | ||
} | ||
} | ||
|
||
diesel::table! { | ||
delegated_staking_activities (transaction_version, event_index) { | ||
transaction_version -> Int8, | ||
|
@@ -1300,6 +1304,7 @@ diesel::allow_tables_to_appear_in_same_query!( | |
current_delegated_voter, | ||
current_delegator_balances, | ||
current_fungible_asset_balances, | ||
current_fungible_asset_balances_legacy, | ||
current_objects, | ||
current_staking_pool_voter, | ||
current_table_items, | ||
|
@@ -1310,7 +1315,6 @@ diesel::allow_tables_to_appear_in_same_query!( | |
current_token_pending_claims, | ||
current_token_royalty_v1, | ||
current_token_v2_metadata, | ||
current_unified_fungible_asset_balances_to_be_renamed, | ||
delegated_staking_activities, | ||
delegated_staking_pool_balances, | ||
delegated_staking_pools, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to redo this migration because it has already been applied to the mainnet and testnet db.