From 8ef2ed3d10827da274fc54828ad0fa7c56c4cb02 Mon Sep 17 00:00:00 2001 From: scx1332 Date: Mon, 9 Sep 2024 12:00:53 +0200 Subject: [PATCH] Fix migrations to contain lf only --- .../migrations/20231103000000_init.sql | 288 +++++++++--------- .../20240118000000_add_allocation_id.sql | 86 +++--- .../migrations/20240301000000_deposit_id.sql | 6 +- .../migrations/20240312000000_add_finish.sql | 96 +++--- .../migrations/20240320000000_add_idx.sql | 14 +- 5 files changed, 245 insertions(+), 245 deletions(-) diff --git a/crates/erc20_payment_lib_common/migrations/20231103000000_init.sql b/crates/erc20_payment_lib_common/migrations/20231103000000_init.sql index 90c2adbf..0eccd279 100644 --- a/crates/erc20_payment_lib_common/migrations/20231103000000_init.sql +++ b/crates/erc20_payment_lib_common/migrations/20231103000000_init.sql @@ -1,144 +1,144 @@ -DROP TABLE IF EXISTS allowance; -DROP TABLE IF EXISTS chain_transfer; -DROP TABLE IF EXISTS chain_tx; -DROP TABLE IF EXISTS scan_info; -DROP TABLE IF EXISTS token_transfer; -DROP TABLE IF EXISTS transfer_in; -DROP TABLE IF EXISTS tx; - -CREATE TABLE "tx" -( - id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, - method TEXT NOT NULL, - from_addr TEXT NOT NULL, - to_addr TEXT NOT NULL, - chain_id INTEGER NOT NULL, - gas_limit INTEGER NULL, - max_fee_per_gas TEXT NULL, - priority_fee TEXT NULL, - val TEXT NOT NULL, - nonce INTEGER NULL, - processing INTEGER NOT NULL, - call_data TEXT NULL, - created_date TEXT NOT NULL, - first_processed TEXT NULL, - tx_hash TEXT NULL, - signed_raw_data TEXT NULL, - signed_date TEXT NULL, - broadcast_date TEXT NULL, - broadcast_count INTEGER NOT NULL, - first_stuck_date TEXT NULL, - confirm_date TEXT NULL, - blockchain_date TEXT NULL, - gas_used INTEGER NULL, - block_number INTEGER NULL, - chain_status INTEGER NULL, - block_gas_price TEXT NULL, - effective_gas_price TEXT NULL, - fee_paid TEXT NULL, - error TEXT NULL, - orig_tx_id INTEGER NULL -) strict; - -CREATE INDEX "idx_tx_created_date" ON "tx" (created_date); -CREATE INDEX "idx_tx_first_processed" ON "tx" (first_processed); -CREATE INDEX "idx_tx_processing" ON "tx" (processing); - -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, - 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; - -CREATE TABLE "allowance" -( - id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, - owner TEXT NOT NULL, - token_addr TEXT NULL, - spender TEXT NOT NULL, - allowance TEXT NOT NULL, - chain_id INTEGER NOT NULL, - tx_id INTEGER NULL, - fee_paid TEXT NULL, - confirm_date TEXT NULL, - error TEXT NULL, - CONSTRAINT "fk_allowance_tx" FOREIGN KEY ("tx_id") REFERENCES "tx" ("id") -) strict; - -CREATE TABLE "chain_tx" -( - id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, - tx_hash TEXT NOT NULL, - method TEXT NOT NULL, - from_addr TEXT NOT NULL, - to_addr TEXT NOT NULL, - chain_id INTEGER NOT NULL, - gas_used INTEGER NULL, - gas_limit INTEGER NULL, - block_gas_price TEXT NULL, - effective_gas_price TEXT NULL, - max_fee_per_gas TEXT NULL, - priority_fee TEXT NULL, - val TEXT NOT NULL, - nonce INTEGER NOT NULL, - checked_date TEXT NOT NULL, - blockchain_date TEXT NOT NULL, - block_number INTEGER NOT NULL, - chain_status INTEGER NOT NULL, - fee_paid TEXT NULL, - error TEXT NULL, - balance_eth TEXT NULL, - balance_glm TEXT NULL -) strict; - - -CREATE TABLE "transfer_in" -( - id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, - payment_id TEXT NOT 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, - tx_hash TEXT NULL, - requested_date TEXT NOT NULL, - received_date TEXT NULL -) strict; - -CREATE TABLE "chain_transfer" -( - id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, - from_addr TEXT NOT NULL, - receiver_addr TEXT NOT NULL, - chain_id INTEGER NOT NULL, - token_addr TEXT NULL, - token_amount TEXT NOT NULL, - chain_tx_id INTEGER NOT NULL, - fee_paid TEXT NOT NULL, - blockchain_date TEXT NOT NULL, - CONSTRAINT "fk_chain_transfer_tx" FOREIGN KEY ("chain_tx_id") REFERENCES "chain_tx" ("id") -) strict; - -CREATE TABLE "scan_info" -( - id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, - chain_id INTEGER NOT NULL, - filter TEXT NOT NULL, - start_block INTEGER NOT NULL, - last_block INTEGER NOT NULL -) strict; - -CREATE UNIQUE INDEX "idx_scan_info_chain_id" ON "scan_info" ("chain_id", "filter"); - +DROP TABLE IF EXISTS allowance; +DROP TABLE IF EXISTS chain_transfer; +DROP TABLE IF EXISTS chain_tx; +DROP TABLE IF EXISTS scan_info; +DROP TABLE IF EXISTS token_transfer; +DROP TABLE IF EXISTS transfer_in; +DROP TABLE IF EXISTS tx; + +CREATE TABLE "tx" +( + id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + method TEXT NOT NULL, + from_addr TEXT NOT NULL, + to_addr TEXT NOT NULL, + chain_id INTEGER NOT NULL, + gas_limit INTEGER NULL, + max_fee_per_gas TEXT NULL, + priority_fee TEXT NULL, + val TEXT NOT NULL, + nonce INTEGER NULL, + processing INTEGER NOT NULL, + call_data TEXT NULL, + created_date TEXT NOT NULL, + first_processed TEXT NULL, + tx_hash TEXT NULL, + signed_raw_data TEXT NULL, + signed_date TEXT NULL, + broadcast_date TEXT NULL, + broadcast_count INTEGER NOT NULL, + first_stuck_date TEXT NULL, + confirm_date TEXT NULL, + blockchain_date TEXT NULL, + gas_used INTEGER NULL, + block_number INTEGER NULL, + chain_status INTEGER NULL, + block_gas_price TEXT NULL, + effective_gas_price TEXT NULL, + fee_paid TEXT NULL, + error TEXT NULL, + orig_tx_id INTEGER NULL +) strict; + +CREATE INDEX "idx_tx_created_date" ON "tx" (created_date); +CREATE INDEX "idx_tx_first_processed" ON "tx" (first_processed); +CREATE INDEX "idx_tx_processing" ON "tx" (processing); + +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, + 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; + +CREATE TABLE "allowance" +( + id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + owner TEXT NOT NULL, + token_addr TEXT NULL, + spender TEXT NOT NULL, + allowance TEXT NOT NULL, + chain_id INTEGER NOT NULL, + tx_id INTEGER NULL, + fee_paid TEXT NULL, + confirm_date TEXT NULL, + error TEXT NULL, + CONSTRAINT "fk_allowance_tx" FOREIGN KEY ("tx_id") REFERENCES "tx" ("id") +) strict; + +CREATE TABLE "chain_tx" +( + id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + tx_hash TEXT NOT NULL, + method TEXT NOT NULL, + from_addr TEXT NOT NULL, + to_addr TEXT NOT NULL, + chain_id INTEGER NOT NULL, + gas_used INTEGER NULL, + gas_limit INTEGER NULL, + block_gas_price TEXT NULL, + effective_gas_price TEXT NULL, + max_fee_per_gas TEXT NULL, + priority_fee TEXT NULL, + val TEXT NOT NULL, + nonce INTEGER NOT NULL, + checked_date TEXT NOT NULL, + blockchain_date TEXT NOT NULL, + block_number INTEGER NOT NULL, + chain_status INTEGER NOT NULL, + fee_paid TEXT NULL, + error TEXT NULL, + balance_eth TEXT NULL, + balance_glm TEXT NULL +) strict; + + +CREATE TABLE "transfer_in" +( + id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + payment_id TEXT NOT 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, + tx_hash TEXT NULL, + requested_date TEXT NOT NULL, + received_date TEXT NULL +) strict; + +CREATE TABLE "chain_transfer" +( + id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + from_addr TEXT NOT NULL, + receiver_addr TEXT NOT NULL, + chain_id INTEGER NOT NULL, + token_addr TEXT NULL, + token_amount TEXT NOT NULL, + chain_tx_id INTEGER NOT NULL, + fee_paid TEXT NOT NULL, + blockchain_date TEXT NOT NULL, + CONSTRAINT "fk_chain_transfer_tx" FOREIGN KEY ("chain_tx_id") REFERENCES "chain_tx" ("id") +) strict; + +CREATE TABLE "scan_info" +( + id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + chain_id INTEGER NOT NULL, + filter TEXT NOT NULL, + start_block INTEGER NOT NULL, + last_block INTEGER NOT NULL +) strict; + +CREATE UNIQUE INDEX "idx_scan_info_chain_id" ON "scan_info" ("chain_id", "filter"); + diff --git a/crates/erc20_payment_lib_common/migrations/20240118000000_add_allocation_id.sql b/crates/erc20_payment_lib_common/migrations/20240118000000_add_allocation_id.sql index 08498bb1..72d32e84 100644 --- a/crates/erc20_payment_lib_common/migrations/20240118000000_add_allocation_id.sql +++ b/crates/erc20_payment_lib_common/migrations/20240118000000_add_allocation_id.sql @@ -1,43 +1,43 @@ -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, - 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, - allocation_id TEXT NULL, - use_internal 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, create_date, paid_date, tx_id, fee_paid, error) SELECT id, payment_id, from_addr, receiver_addr, chain_id, token_addr, token_amount, create_date, paid_date, tx_id, fee_paid, error FROM old_table; +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, + 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, + allocation_id TEXT NULL, + use_internal 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, create_date, paid_date, tx_id, fee_paid, error) SELECT id, payment_id, from_addr, receiver_addr, chain_id, token_addr, token_amount, create_date, paid_date, tx_id, fee_paid, error FROM old_table; diff --git a/crates/erc20_payment_lib_common/migrations/20240301000000_deposit_id.sql b/crates/erc20_payment_lib_common/migrations/20240301000000_deposit_id.sql index 248929f5..a802cf82 100644 --- a/crates/erc20_payment_lib_common/migrations/20240301000000_deposit_id.sql +++ b/crates/erc20_payment_lib_common/migrations/20240301000000_deposit_id.sql @@ -1,3 +1,3 @@ - -ALTER TABLE token_transfer RENAME COLUMN allocation_id TO deposit_id; -ALTER TABLE token_transfer DROP COLUMN use_internal; + +ALTER TABLE token_transfer RENAME COLUMN allocation_id TO deposit_id; +ALTER TABLE token_transfer DROP COLUMN use_internal; diff --git a/crates/erc20_payment_lib_common/migrations/20240312000000_add_finish.sql b/crates/erc20_payment_lib_common/migrations/20240312000000_add_finish.sql index 9bad53cb..6ae364ca 100644 --- a/crates/erc20_payment_lib_common/migrations/20240312000000_add_finish.sql +++ b/crates/erc20_payment_lib_common/migrations/20240312000000_add_finish.sql @@ -1,48 +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); +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); diff --git a/crates/erc20_payment_lib_common/migrations/20240320000000_add_idx.sql b/crates/erc20_payment_lib_common/migrations/20240320000000_add_idx.sql index 67841b8b..faab7a4d 100644 --- a/crates/erc20_payment_lib_common/migrations/20240320000000_add_idx.sql +++ b/crates/erc20_payment_lib_common/migrations/20240320000000_add_idx.sql @@ -1,7 +1,7 @@ -DELETE FROM chain_tx; -CREATE UNIQUE INDEX "idx_chain_tx_tx_hash" ON "chain_tx" ("tx_hash"); -CREATE INDEX "idx_chain_tx_blockchain_date" ON "chain_tx" ("blockchain_date"); -CREATE INDEX "idx_chain_transfer_blockchain_date" ON "chain_transfer" ("blockchain_date"); -CREATE INDEX "idx_chain_transfer_receiver_address" ON "chain_transfer" ("receiver_addr"); -CREATE INDEX "idx_chain_transfer_from_address" ON "chain_transfer" ("from_addr"); - +DELETE FROM chain_tx; +CREATE UNIQUE INDEX "idx_chain_tx_tx_hash" ON "chain_tx" ("tx_hash"); +CREATE INDEX "idx_chain_tx_blockchain_date" ON "chain_tx" ("blockchain_date"); +CREATE INDEX "idx_chain_transfer_blockchain_date" ON "chain_transfer" ("blockchain_date"); +CREATE INDEX "idx_chain_transfer_receiver_address" ON "chain_transfer" ("receiver_addr"); +CREATE INDEX "idx_chain_transfer_from_address" ON "chain_transfer" ("from_addr"); +