-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
48 additions
and
0 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
crates/erc20_payment_lib_common/migrations/20240312000000_add_final.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
DROP TABLE IF EXISTS "old_table"; | ||
DROP TABLE IF EXISTS "new_table"; | ||
|
||
CREATE TABLE "old_table" | ||
( | ||
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, | ||
payment_id TEXT NULL, | ||
from_addr TEXT NOT NULL, | ||
receiver_addr TEXT NOT NULL, | ||
chain_id INTEGER NOT NULL, | ||
token_addr TEXT NULL, | ||
token_amount TEXT NOT NULL, | ||
deposit_id TEXT NULL, | ||
create_date TEXT NOT NULL, | ||
paid_date TEXT NULL, | ||
tx_id INTEGER NULL, | ||
fee_paid TEXT NULL, | ||
error TEXT NULL | ||
) strict; | ||
|
||
INSERT INTO old_table SELECT * FROM token_transfer; | ||
|
||
DROP TABLE token_transfer; | ||
|
||
CREATE TABLE token_transfer | ||
( | ||
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, | ||
payment_id TEXT NULL, | ||
from_addr TEXT NOT NULL, | ||
receiver_addr TEXT NOT NULL, | ||
chain_id INTEGER NOT NULL, | ||
token_addr TEXT NULL, | ||
token_amount TEXT NOT NULL, | ||
deposit_id TEXT NULL, | ||
deposit_finish INTEGER NOT NULL DEFAULT 0, | ||
create_date TEXT NOT NULL, | ||
paid_date TEXT NULL, | ||
tx_id INTEGER NULL, | ||
fee_paid TEXT NULL, | ||
error TEXT NULL, | ||
CONSTRAINT "fk_token_transfer_tx" FOREIGN KEY ("tx_id") REFERENCES "tx" ("id") | ||
) strict; | ||
|
||
INSERT INTO token_transfer(id, payment_id, from_addr, receiver_addr, chain_id, token_addr, token_amount, deposit_id, create_date, paid_date, tx_id, fee_paid, error) | ||
SELECT id, payment_id, from_addr, receiver_addr, chain_id, token_addr, token_amount, deposit_id, create_date, paid_date, tx_id, fee_paid, error FROM old_table; | ||
|
||
-- Make sure that extracting transfers for given deposit_id is fast | ||
CREATE INDEX "idx_deposit_id" ON "token_transfer" (deposit_id); |