status-go/appdatabase/migrations/sql/1686048341_transfers_receipt_json_blob_out.up.sql.up.sql
Stefan 5b6f7226bb feat(wallet) extract json blobs and add custom migration support
Extended the migration process with a generic way of applying custom
migration code on top of the SQL files. The implementation provides
a safer way to run GO code along with the SQL migrations and possibility
of rolling back the changes in case of failure to keep the database
consistent.
This custom GO migration is needed to extract the status from
the JSON blob receipt and store it in transfers table.

Other changes:
- Add NULL DB value tracking to JSONBlob helper
- Index status column on transfers table
- Remove unnecessary panic calls
- Move log_parser to wallet's common package and use to extract token
  identity from the logs

Notes:
- there is already an index on transfers table, sqlite creates one for
  each unique constraint therefore add only status to a new index
- the planned refactoring and improvements to the database have been
  postponed due to time constraints. Got the time to migrate the data
  though, extracting it can be done later for a more efficient
  implementation

Update status-desktop #10746
2023-06-08 13:54:40 +02:00

31 lines
1.5 KiB
SQL

-- This migration is done in GO code as a custom step.
-- This file serves as an anchor for the migration system
-- Check migrateWalletJsonBlobs from appdatabase/database.go
-- The following steps are done in GO code:
-- ALTER TABLE transfers ADD COLUMN status INT;
-- ALTER TABLE transfers ADD COLUMN receipt_type INT;
-- ALTER TABLE transfers ADD COLUMN tx_hash BLOB;
-- ALTER TABLE transfers ADD COLUMN log_index INT;
-- ALTER TABLE transfers ADD COLUMN block_hash BLOB;
-- ALTER TABLE transfers ADD COLUMN cumulative_gas_used INT;
-- ALTER TABLE transfers ADD COLUMN contract_address TEXT;
-- ALTER TABLE transfers ADD COLUMN gas_used INT;
-- ALTER TABLE transfers ADD COLUMN tx_index INT;
-- ALTER TABLE transfers ADD COLUMN tx_type INT;
-- ALTER TABLE transfers ADD COLUMN protected BOOLEAN;
-- ALTER TABLE transfers ADD COLUMN gas_limit UNSIGNED INT;
-- ALTER TABLE transfers ADD COLUMN gas_price_clamped64 INT;
-- ALTER TABLE transfers ADD COLUMN gas_tip_cap_clamped64 INT;
-- ALTER TABLE transfers ADD COLUMN gas_fee_cap_clamped64 INT;
-- ALTER TABLE transfers ADD COLUMN amount_padded128hex CHAR(32);
-- ALTER TABLE transfers ADD COLUMN account_nonce INT;
-- ALTER TABLE transfers ADD COLUMN size INT;
-- ALTER TABLE transfers ADD COLUMN token_address BLOB;
-- ALTER TABLE transfers ADD COLUMN token_id BLOB;
-- CREATE INDEX transfers_filter ON transfers (status, token_address, token_id);`
-- Extract tx and receipt data from the json blob and add the information into the new columns