From d9e2bece2763ee88f56c6ad1a96436e4695f996e Mon Sep 17 00:00:00 2001 From: Rob Mulholand Date: Mon, 18 Mar 2019 17:21:31 -0500 Subject: [PATCH] Consolidate migrations - Facilitate modifying migrations without cascading consequences for later migrations updating the same tables --- db/migrations/00001_create_blocks_table.sql | 22 ++++- db/migrations/00002_add_columns_to_blocks.sql | 13 --- .../00002_create_transactions_table.sql | 16 ++++ .../00003_add_block_index_to_blocks.sql | 6 ++ .../00003_initial_transaction_table.sql | 14 --- .../00004_add_primary_key_to_blocks.sql | 5 -- ...e.sql => 00004_create_contracts_table.sql} | 5 +- .../00005_add_block_id_to_transactions.sql | 11 --- db/migrations/00005_create_nodes_table.sql | 12 +++ db/migrations/00006_add_block_index.sql | 6 -- ...ks.sql => 00006_add_node_fk_to_blocks.sql} | 3 +- db/migrations/00007_add_blocks_columns.sql | 18 ---- ..._table.sql => 00007_create_logs_table.sql} | 0 ...ck_number_unique_constraint_to_blocks.sql} | 2 +- ...09_add_block_id_index_to_transactions.sql} | 0 .../00009_add_from_to_transactions.sql | 8 -- .../00010_add_abi_to_watched_contracts.sql | 7 -- ... => 00010_add_node_id_index_to_blocks.sql} | 0 db/migrations/00011_add_nodes_table.sql | 10 --- ...00011_add_tx_to_index_to_transactions.sql} | 0 ...012_add_tx_from_index_to_transactions.sql} | 0 ...t_hash_constraint_to_watched_contracts.sql | 8 -- ...le.sql => 00013_create_receipts_table.sql} | 0 ..._add_transaction_id_index_to_receipts.sql} | 0 ...015_add_cascade_delete_to_transactions.sql | 19 ---- ....sql => 00015_add_receipts_fk_to_logs.sql} | 0 .../00016_add_cascade_delete_to_blocks.sql | 18 ---- ...lters.sql => 00016_create_log_filters.sql} | 0 .../00017_add_is_final_to_blocks.sql | 7 -- ...ql => 00017_create_watched_event_logs.sql} | 0 ...pdate_log_filters_to_block_constraint.sql} | 0 ..._table.sql => 00019_rename_node_table.sql} | 0 ... 00020_associate_receipts_with_blocks.sql} | 0 ...21_add_eth_node_fingerprint_to_blocks.sql} | 0 ...ble.sql => 00022_create_headers_table.sql} | 0 db/migrations/00023_add_miner.sql | 7 -- ...=> 00023_create_checked_headers_table.sql} | 0 db/migrations/00024_add_extra_data.sql | 7 -- ...ge.sql => 00024_create_queued_storage.sql} | 0 .../00025_add_block_reward_uncle_reward.sql | 10 --- .../00026_add_data_input_to_transactions.sql | 7 -- db/migrations/00029_add_fields_to_node.sql | 9 -- db/migrations/00030_update_node_index.sql | 14 --- .../00034_update_gas_limit_gas_used.sql | 32 ------- db/migrations/00035_rename_block_columns.sql | 80 ----------------- db/migrations/00036_update_tx_table_names.sql | 38 -------- db/migrations/00038_update_eth18_types.sql | 8 -- db/schema.sql | 90 +++++++++---------- 48 files changed, 103 insertions(+), 409 deletions(-) delete mode 100644 db/migrations/00002_add_columns_to_blocks.sql create mode 100644 db/migrations/00002_create_transactions_table.sql create mode 100644 db/migrations/00003_add_block_index_to_blocks.sql delete mode 100644 db/migrations/00003_initial_transaction_table.sql delete mode 100644 db/migrations/00004_add_primary_key_to_blocks.sql rename db/migrations/{00008_add_contracts_table.sql => 00004_create_contracts_table.sql} (50%) delete mode 100644 db/migrations/00005_add_block_id_to_transactions.sql create mode 100644 db/migrations/00005_create_nodes_table.sql delete mode 100644 db/migrations/00006_add_block_index.sql rename db/migrations/{00012_add_node_fk_to_blocks.sql => 00006_add_node_fk_to_blocks.sql} (81%) delete mode 100644 db/migrations/00007_add_blocks_columns.sql rename db/migrations/{00014_add_logs_table.sql => 00007_create_logs_table.sql} (100%) rename db/migrations/{00018_add_unique_constraint_blocks_node.sql => 00008_add_node_block_number_unique_constraint_to_blocks.sql} (60%) rename db/migrations/{00019_add_block_id_index_on_transactions_table.sql => 00009_add_block_id_index_to_transactions.sql} (100%) delete mode 100644 db/migrations/00009_add_from_to_transactions.sql delete mode 100644 db/migrations/00010_add_abi_to_watched_contracts.sql rename db/migrations/{00020_add_node_id_index_on_blocks_table.sql => 00010_add_node_id_index_to_blocks.sql} (100%) delete mode 100644 db/migrations/00011_add_nodes_table.sql rename db/migrations/{00021_tx_to_index.sql => 00011_add_tx_to_index_to_transactions.sql} (100%) rename db/migrations/{00022_tx_from_index.sql => 00012_add_tx_from_index_to_transactions.sql} (100%) delete mode 100644 db/migrations/00013_add_contract_hash_constraint_to_watched_contracts.sql rename db/migrations/{00027_create_receipts_table.sql => 00013_create_receipts_table.sql} (100%) rename db/migrations/{00028_add_transaction_id_index_to_receipts.sql => 00014_add_transaction_id_index_to_receipts.sql} (100%) delete mode 100644 db/migrations/00015_add_cascade_delete_to_transactions.sql rename db/migrations/{00031_add_log_fk_constraint.sql => 00015_add_receipts_fk_to_logs.sql} (100%) delete mode 100644 db/migrations/00016_add_cascade_delete_to_blocks.sql rename db/migrations/{00032_add_log_filters.sql => 00016_create_log_filters.sql} (100%) delete mode 100644 db/migrations/00017_add_is_final_to_blocks.sql rename db/migrations/{00033_add_watched_event_logs.sql => 00017_create_watched_event_logs.sql} (100%) rename db/migrations/{00037_update_log_filters_to_block_constraint.sql => 00018_update_log_filters_to_block_constraint.sql} (100%) rename db/migrations/{00039_rename_node_table.sql => 00019_rename_node_table.sql} (100%) rename db/migrations/{00040_associate_receipts_with_blocks.sql => 00020_associate_receipts_with_blocks.sql} (100%) rename db/migrations/{00041_add_eth_node_fingerprint_to_blocks.sql => 00021_add_eth_node_fingerprint_to_blocks.sql} (100%) rename db/migrations/{00042_create_headers_table.sql => 00022_create_headers_table.sql} (100%) delete mode 100644 db/migrations/00023_add_miner.sql rename db/migrations/{00043_create_checked_headers_table.sql => 00023_create_checked_headers_table.sql} (100%) delete mode 100644 db/migrations/00024_add_extra_data.sql rename db/migrations/{00044_create_queued_storage.sql => 00024_create_queued_storage.sql} (100%) delete mode 100644 db/migrations/00025_add_block_reward_uncle_reward.sql delete mode 100644 db/migrations/00026_add_data_input_to_transactions.sql delete mode 100644 db/migrations/00029_add_fields_to_node.sql delete mode 100644 db/migrations/00030_update_node_index.sql delete mode 100644 db/migrations/00034_update_gas_limit_gas_used.sql delete mode 100644 db/migrations/00035_rename_block_columns.sql delete mode 100644 db/migrations/00036_update_tx_table_names.sql delete mode 100644 db/migrations/00038_update_eth18_types.sql diff --git a/db/migrations/00001_create_blocks_table.sql b/db/migrations/00001_create_blocks_table.sql index f5fe43a6..9f787381 100644 --- a/db/migrations/00001_create_blocks_table.sql +++ b/db/migrations/00001_create_blocks_table.sql @@ -1,9 +1,23 @@ -- +goose Up -CREATE TABLE public.blocks -( - block_number BIGINT +CREATE TABLE public.blocks ( + id SERIAL PRIMARY KEY, + difficulty BIGINT, + extra_data VARCHAR, + gaslimit BIGINT, + gasused BIGINT, + hash VARCHAR(66), + miner VARCHAR(42), + nonce VARCHAR(20), + "number" BIGINT, + parenthash VARCHAR(66), + reward DOUBLE PRECISION, + uncles_reward DOUBLE PRECISION, + "size" VARCHAR, + "time" BIGINT, + is_final BOOLEAN, + uncle_hash VARCHAR(66) ); -- +goose Down -DROP TABLE public.blocks; +DROP TABLE public.blocks; \ No newline at end of file diff --git a/db/migrations/00002_add_columns_to_blocks.sql b/db/migrations/00002_add_columns_to_blocks.sql deleted file mode 100644 index 4d6626ab..00000000 --- a/db/migrations/00002_add_columns_to_blocks.sql +++ /dev/null @@ -1,13 +0,0 @@ --- +goose Up -ALTER TABLE blocks - ADD COLUMN block_gaslimit DOUBLE PRECISION, - ADD COLUMN block_gasused DOUBLE PRECISION, - ADD COLUMN block_time DOUBLE PRECISION; - - --- +goose Down -ALTER TABLE blocks - DROP COLUMN block_gaslimit, - DROP COLUMN block_gasused, - DROP COLUMN block_time; - diff --git a/db/migrations/00002_create_transactions_table.sql b/db/migrations/00002_create_transactions_table.sql new file mode 100644 index 00000000..80aa4c7c --- /dev/null +++ b/db/migrations/00002_create_transactions_table.sql @@ -0,0 +1,16 @@ +-- +goose Up +CREATE TABLE transactions ( + id SERIAL PRIMARY KEY, + block_id INTEGER NOT NULL REFERENCES blocks(id) ON DELETE CASCADE, + input_data VARCHAR, + tx_from VARCHAR(66), + gaslimit NUMERIC, + gasprice NUMERIC, + hash VARCHAR(66), + nonce NUMERIC, + tx_to VARCHAR(66), + "value" NUMERIC +); + +-- +goose Down +DROP TABLE transactions; \ No newline at end of file diff --git a/db/migrations/00003_add_block_index_to_blocks.sql b/db/migrations/00003_add_block_index_to_blocks.sql new file mode 100644 index 00000000..4ce50e6e --- /dev/null +++ b/db/migrations/00003_add_block_index_to_blocks.sql @@ -0,0 +1,6 @@ +-- +goose Up +CREATE INDEX number_index ON blocks (number); + + +-- +goose Down +DROP INDEX number_index; diff --git a/db/migrations/00003_initial_transaction_table.sql b/db/migrations/00003_initial_transaction_table.sql deleted file mode 100644 index ba6b06a0..00000000 --- a/db/migrations/00003_initial_transaction_table.sql +++ /dev/null @@ -1,14 +0,0 @@ --- +goose Up -CREATE TABLE transactions -( - id SERIAL PRIMARY KEY, - tx_hash VARCHAR(66), - tx_nonce NUMERIC, - tx_to varchar(66), - tx_gaslimit NUMERIC, - tx_gasprice NUMERIC, - tx_value NUMERIC -); - --- +goose Down -DROP TABLE transactions; diff --git a/db/migrations/00004_add_primary_key_to_blocks.sql b/db/migrations/00004_add_primary_key_to_blocks.sql deleted file mode 100644 index 0f336243..00000000 --- a/db/migrations/00004_add_primary_key_to_blocks.sql +++ /dev/null @@ -1,5 +0,0 @@ --- +goose Up -ALTER TABLE blocks ADD COLUMN id SERIAL PRIMARY KEY; - --- +goose Down -ALTER TABLE blocks DROP id; diff --git a/db/migrations/00008_add_contracts_table.sql b/db/migrations/00004_create_contracts_table.sql similarity index 50% rename from db/migrations/00008_add_contracts_table.sql rename to db/migrations/00004_create_contracts_table.sql index d5016555..3ff43bef 100644 --- a/db/migrations/00008_add_contracts_table.sql +++ b/db/migrations/00004_create_contracts_table.sql @@ -1,8 +1,9 @@ -- +goose Up CREATE TABLE watched_contracts ( - contract_id SERIAL PRIMARY KEY, - contract_hash VARCHAR(66) + contract_id SERIAL PRIMARY KEY, + contract_abi json, + contract_hash VARCHAR(66) UNIQUE ); -- +goose Down diff --git a/db/migrations/00005_add_block_id_to_transactions.sql b/db/migrations/00005_add_block_id_to_transactions.sql deleted file mode 100644 index 08e5002a..00000000 --- a/db/migrations/00005_add_block_id_to_transactions.sql +++ /dev/null @@ -1,11 +0,0 @@ --- +goose Up -ALTER TABLE transactions - ADD COLUMN block_id INTEGER NOT NULL, - ADD CONSTRAINT fk_test - FOREIGN KEY (block_id) - REFERENCES blocks (id); - - --- +goose Down -ALTER TABLE transactions - DROP COLUMN block_id; diff --git a/db/migrations/00005_create_nodes_table.sql b/db/migrations/00005_create_nodes_table.sql new file mode 100644 index 00000000..c2c0c7b8 --- /dev/null +++ b/db/migrations/00005_create_nodes_table.sql @@ -0,0 +1,12 @@ +-- +goose Up +CREATE TABLE nodes ( + id SERIAL PRIMARY KEY, + client_name VARCHAR, + genesis_block VARCHAR(66), + network_id NUMERIC, + node_id VARCHAR(128), + CONSTRAINT node_uc UNIQUE (genesis_block, network_id, node_id) +); + +-- +goose Down +DROP TABLE nodes; diff --git a/db/migrations/00006_add_block_index.sql b/db/migrations/00006_add_block_index.sql deleted file mode 100644 index e04815ee..00000000 --- a/db/migrations/00006_add_block_index.sql +++ /dev/null @@ -1,6 +0,0 @@ --- +goose Up -CREATE INDEX block_number_index ON blocks (block_number); - - --- +goose Down -DROP INDEX block_number_index; diff --git a/db/migrations/00012_add_node_fk_to_blocks.sql b/db/migrations/00006_add_node_fk_to_blocks.sql similarity index 81% rename from db/migrations/00012_add_node_fk_to_blocks.sql rename to db/migrations/00006_add_node_fk_to_blocks.sql index 6f658caa..4db8c03f 100644 --- a/db/migrations/00012_add_node_fk_to_blocks.sql +++ b/db/migrations/00006_add_node_fk_to_blocks.sql @@ -3,7 +3,8 @@ ALTER TABLE blocks ADD COLUMN node_id INTEGER NOT NULL, ADD CONSTRAINT node_fk FOREIGN KEY (node_id) -REFERENCES nodes (id); +REFERENCES nodes (id) +ON DELETE CASCADE; -- +goose Down ALTER TABLE blocks diff --git a/db/migrations/00007_add_blocks_columns.sql b/db/migrations/00007_add_blocks_columns.sql deleted file mode 100644 index f12c6a5d..00000000 --- a/db/migrations/00007_add_blocks_columns.sql +++ /dev/null @@ -1,18 +0,0 @@ --- +goose Up -ALTER TABLE blocks - ADD COLUMN block_difficulty BIGINT, - ADD COLUMN block_hash VARCHAR(66), - ADD COLUMN block_nonce VARCHAR(20), - ADD COLUMN block_parenthash VARCHAR(66), - ADD COLUMN block_size BIGINT, - ADD COLUMN uncle_hash VARCHAR(66); - - --- +goose Down -ALTER TABLE blocks - Drop COLUMN block_difficulty, - Drop COLUMN block_hash, - drop COLUMN block_nonce, - drop COLUMN block_parenthash, - drop COLUMN block_size, - drop COLUMN uncle_hash; diff --git a/db/migrations/00014_add_logs_table.sql b/db/migrations/00007_create_logs_table.sql similarity index 100% rename from db/migrations/00014_add_logs_table.sql rename to db/migrations/00007_create_logs_table.sql diff --git a/db/migrations/00018_add_unique_constraint_blocks_node.sql b/db/migrations/00008_add_node_block_number_unique_constraint_to_blocks.sql similarity index 60% rename from db/migrations/00018_add_unique_constraint_blocks_node.sql rename to db/migrations/00008_add_node_block_number_unique_constraint_to_blocks.sql index e66e345f..30be138d 100644 --- a/db/migrations/00018_add_unique_constraint_blocks_node.sql +++ b/db/migrations/00008_add_node_block_number_unique_constraint_to_blocks.sql @@ -1,6 +1,6 @@ -- +goose Up ALTER TABLE blocks - ADD CONSTRAINT node_id_block_number_uc UNIQUE (block_number, node_id); + ADD CONSTRAINT node_id_block_number_uc UNIQUE (number, node_id); -- +goose Down ALTER TABLE blocks diff --git a/db/migrations/00019_add_block_id_index_on_transactions_table.sql b/db/migrations/00009_add_block_id_index_to_transactions.sql similarity index 100% rename from db/migrations/00019_add_block_id_index_on_transactions_table.sql rename to db/migrations/00009_add_block_id_index_to_transactions.sql diff --git a/db/migrations/00009_add_from_to_transactions.sql b/db/migrations/00009_add_from_to_transactions.sql deleted file mode 100644 index 3311b7e4..00000000 --- a/db/migrations/00009_add_from_to_transactions.sql +++ /dev/null @@ -1,8 +0,0 @@ --- +goose Up -ALTER TABLE transactions - ADD COLUMN tx_from VARCHAR(66); - - --- +goose Down -ALTER TABLE transactions - DROP COLUMN tx_from; diff --git a/db/migrations/00010_add_abi_to_watched_contracts.sql b/db/migrations/00010_add_abi_to_watched_contracts.sql deleted file mode 100644 index 4520b9b7..00000000 --- a/db/migrations/00010_add_abi_to_watched_contracts.sql +++ /dev/null @@ -1,7 +0,0 @@ --- +goose Up -ALTER TABLE watched_contracts - ADD COLUMN contract_abi json; - --- +goose Down -ALTER TABLE watched_contracts - DROP COLUMN contract_abi; diff --git a/db/migrations/00020_add_node_id_index_on_blocks_table.sql b/db/migrations/00010_add_node_id_index_to_blocks.sql similarity index 100% rename from db/migrations/00020_add_node_id_index_on_blocks_table.sql rename to db/migrations/00010_add_node_id_index_to_blocks.sql diff --git a/db/migrations/00011_add_nodes_table.sql b/db/migrations/00011_add_nodes_table.sql deleted file mode 100644 index 46f1d51d..00000000 --- a/db/migrations/00011_add_nodes_table.sql +++ /dev/null @@ -1,10 +0,0 @@ --- +goose Up -CREATE TABLE nodes ( - id SERIAL PRIMARY KEY, - genesis_block VARCHAR(66), - network_id NUMERIC, - CONSTRAINT node_uc UNIQUE (genesis_block, network_id) -); - --- +goose Down -DROP TABLE nodes; diff --git a/db/migrations/00021_tx_to_index.sql b/db/migrations/00011_add_tx_to_index_to_transactions.sql similarity index 100% rename from db/migrations/00021_tx_to_index.sql rename to db/migrations/00011_add_tx_to_index_to_transactions.sql diff --git a/db/migrations/00022_tx_from_index.sql b/db/migrations/00012_add_tx_from_index_to_transactions.sql similarity index 100% rename from db/migrations/00022_tx_from_index.sql rename to db/migrations/00012_add_tx_from_index_to_transactions.sql diff --git a/db/migrations/00013_add_contract_hash_constraint_to_watched_contracts.sql b/db/migrations/00013_add_contract_hash_constraint_to_watched_contracts.sql deleted file mode 100644 index 4f252cce..00000000 --- a/db/migrations/00013_add_contract_hash_constraint_to_watched_contracts.sql +++ /dev/null @@ -1,8 +0,0 @@ --- +goose Up -ALTER TABLE watched_contracts - ADD CONSTRAINT contract_hash_uc UNIQUE (contract_hash); - - --- +goose Down -ALTER TABLE watched_contracts - DROP CONSTRAINT contract_hash_uc; diff --git a/db/migrations/00027_create_receipts_table.sql b/db/migrations/00013_create_receipts_table.sql similarity index 100% rename from db/migrations/00027_create_receipts_table.sql rename to db/migrations/00013_create_receipts_table.sql diff --git a/db/migrations/00028_add_transaction_id_index_to_receipts.sql b/db/migrations/00014_add_transaction_id_index_to_receipts.sql similarity index 100% rename from db/migrations/00028_add_transaction_id_index_to_receipts.sql rename to db/migrations/00014_add_transaction_id_index_to_receipts.sql diff --git a/db/migrations/00015_add_cascade_delete_to_transactions.sql b/db/migrations/00015_add_cascade_delete_to_transactions.sql deleted file mode 100644 index f10d52dd..00000000 --- a/db/migrations/00015_add_cascade_delete_to_transactions.sql +++ /dev/null @@ -1,19 +0,0 @@ --- +goose Up -ALTER TABLE transactions - DROP CONSTRAINT fk_test; - -ALTER TABLE transactions - ADD CONSTRAINT blocks_fk -FOREIGN KEY (block_id) -REFERENCES blocks (id) -ON DELETE CASCADE; - - --- +goose Down -ALTER TABLE transactions - DROP CONSTRAINT blocks_fk; - -ALTER TABLE transactions - ADD CONSTRAINT fk_test -FOREIGN KEY (block_id) -REFERENCES blocks (id); diff --git a/db/migrations/00031_add_log_fk_constraint.sql b/db/migrations/00015_add_receipts_fk_to_logs.sql similarity index 100% rename from db/migrations/00031_add_log_fk_constraint.sql rename to db/migrations/00015_add_receipts_fk_to_logs.sql diff --git a/db/migrations/00016_add_cascade_delete_to_blocks.sql b/db/migrations/00016_add_cascade_delete_to_blocks.sql deleted file mode 100644 index 5a0a7e5f..00000000 --- a/db/migrations/00016_add_cascade_delete_to_blocks.sql +++ /dev/null @@ -1,18 +0,0 @@ --- +goose Up -ALTER TABLE blocks - DROP CONSTRAINT node_fk; - -ALTER TABLE blocks - ADD CONSTRAINT node_fk -FOREIGN KEY (node_id) -REFERENCES nodes (id) -ON DELETE CASCADE; - --- +goose Down -ALTER TABLE blocks - DROP CONSTRAINT node_fk; - -ALTER TABLE blocks - ADD CONSTRAINT node_fk -FOREIGN KEY (node_id) -REFERENCES nodes (id); diff --git a/db/migrations/00032_add_log_filters.sql b/db/migrations/00016_create_log_filters.sql similarity index 100% rename from db/migrations/00032_add_log_filters.sql rename to db/migrations/00016_create_log_filters.sql diff --git a/db/migrations/00017_add_is_final_to_blocks.sql b/db/migrations/00017_add_is_final_to_blocks.sql deleted file mode 100644 index bbb27d55..00000000 --- a/db/migrations/00017_add_is_final_to_blocks.sql +++ /dev/null @@ -1,7 +0,0 @@ --- +goose Up -ALTER TABLE blocks - ADD COLUMN is_final BOOLEAN; - --- +goose Down -ALTER TABLE blocks - DROP COLUMN is_final; diff --git a/db/migrations/00033_add_watched_event_logs.sql b/db/migrations/00017_create_watched_event_logs.sql similarity index 100% rename from db/migrations/00033_add_watched_event_logs.sql rename to db/migrations/00017_create_watched_event_logs.sql diff --git a/db/migrations/00037_update_log_filters_to_block_constraint.sql b/db/migrations/00018_update_log_filters_to_block_constraint.sql similarity index 100% rename from db/migrations/00037_update_log_filters_to_block_constraint.sql rename to db/migrations/00018_update_log_filters_to_block_constraint.sql diff --git a/db/migrations/00039_rename_node_table.sql b/db/migrations/00019_rename_node_table.sql similarity index 100% rename from db/migrations/00039_rename_node_table.sql rename to db/migrations/00019_rename_node_table.sql diff --git a/db/migrations/00040_associate_receipts_with_blocks.sql b/db/migrations/00020_associate_receipts_with_blocks.sql similarity index 100% rename from db/migrations/00040_associate_receipts_with_blocks.sql rename to db/migrations/00020_associate_receipts_with_blocks.sql diff --git a/db/migrations/00041_add_eth_node_fingerprint_to_blocks.sql b/db/migrations/00021_add_eth_node_fingerprint_to_blocks.sql similarity index 100% rename from db/migrations/00041_add_eth_node_fingerprint_to_blocks.sql rename to db/migrations/00021_add_eth_node_fingerprint_to_blocks.sql diff --git a/db/migrations/00042_create_headers_table.sql b/db/migrations/00022_create_headers_table.sql similarity index 100% rename from db/migrations/00042_create_headers_table.sql rename to db/migrations/00022_create_headers_table.sql diff --git a/db/migrations/00023_add_miner.sql b/db/migrations/00023_add_miner.sql deleted file mode 100644 index da1e120a..00000000 --- a/db/migrations/00023_add_miner.sql +++ /dev/null @@ -1,7 +0,0 @@ --- +goose Up -ALTER TABLE blocks - ADD COLUMN block_miner VARCHAR(42); - --- +goose Down -ALTER TABLE blocks - DROP COLUMN block_miner; diff --git a/db/migrations/00043_create_checked_headers_table.sql b/db/migrations/00023_create_checked_headers_table.sql similarity index 100% rename from db/migrations/00043_create_checked_headers_table.sql rename to db/migrations/00023_create_checked_headers_table.sql diff --git a/db/migrations/00024_add_extra_data.sql b/db/migrations/00024_add_extra_data.sql deleted file mode 100644 index 66ff016b..00000000 --- a/db/migrations/00024_add_extra_data.sql +++ /dev/null @@ -1,7 +0,0 @@ --- +goose Up -ALTER TABLE blocks - ADD COLUMN block_extra_data VARCHAR; - --- +goose Down -ALTER TABLE blocks - DROP COLUMN block_extra_data; diff --git a/db/migrations/00044_create_queued_storage.sql b/db/migrations/00024_create_queued_storage.sql similarity index 100% rename from db/migrations/00044_create_queued_storage.sql rename to db/migrations/00024_create_queued_storage.sql diff --git a/db/migrations/00025_add_block_reward_uncle_reward.sql b/db/migrations/00025_add_block_reward_uncle_reward.sql deleted file mode 100644 index 9932392f..00000000 --- a/db/migrations/00025_add_block_reward_uncle_reward.sql +++ /dev/null @@ -1,10 +0,0 @@ --- +goose Up -ALTER TABLE blocks - ADD COLUMN block_reward NUMERIC, - ADD COLUMN block_uncles_reward NUMERIC; - - --- +goose Down -ALTER TABLE blocks - DROP COLUMN block_reward, - DROP COLUMN block_uncles_reward; diff --git a/db/migrations/00026_add_data_input_to_transactions.sql b/db/migrations/00026_add_data_input_to_transactions.sql deleted file mode 100644 index 454dfa16..00000000 --- a/db/migrations/00026_add_data_input_to_transactions.sql +++ /dev/null @@ -1,7 +0,0 @@ --- +goose Up -ALTER TABLE transactions - ADD COLUMN tx_input_data VARCHAR; - --- +goose Down -ALTER TABLE transactions - DROP COLUMN tx_input_data; diff --git a/db/migrations/00029_add_fields_to_node.sql b/db/migrations/00029_add_fields_to_node.sql deleted file mode 100644 index b4dc223f..00000000 --- a/db/migrations/00029_add_fields_to_node.sql +++ /dev/null @@ -1,9 +0,0 @@ --- +goose Up -ALTER TABLE nodes - ADD COLUMN node_id VARCHAR(128), - ADD COLUMN client_name VARCHAR; - --- +goose Down -ALTER TABLE nodes - DROP COLUMN node_id, - DROP COLUMN client_name; diff --git a/db/migrations/00030_update_node_index.sql b/db/migrations/00030_update_node_index.sql deleted file mode 100644 index 02ad2b2d..00000000 --- a/db/migrations/00030_update_node_index.sql +++ /dev/null @@ -1,14 +0,0 @@ --- +goose Up -ALTER TABLE nodes - DROP CONSTRAINT node_uc; - -ALTER TABLE nodes - ADD CONSTRAINT node_uc UNIQUE (genesis_block, network_id, node_id); - - --- +goose Down -ALTER TABLE nodes - DROP CONSTRAINT node_uc; - -ALTER TABLE nodes - ADD CONSTRAINT node_uc UNIQUE (genesis_block, network_id); diff --git a/db/migrations/00034_update_gas_limit_gas_used.sql b/db/migrations/00034_update_gas_limit_gas_used.sql deleted file mode 100644 index 276de18e..00000000 --- a/db/migrations/00034_update_gas_limit_gas_used.sql +++ /dev/null @@ -1,32 +0,0 @@ --- +goose Up -ALTER TABLE blocks - ALTER COLUMN block_gaslimit TYPE BIGINT USING block_gaslimit :: BIGINT; - -ALTER TABLE blocks - ALTER COLUMN block_gasused TYPE BIGINT USING block_gasused :: BIGINT; - -ALTER TABLE blocks - ALTER COLUMN block_time TYPE BIGINT USING block_time :: BIGINT; - -ALTER TABLE blocks - ALTER COLUMN block_reward TYPE DOUBLE PRECISION USING block_time :: DOUBLE PRECISION; - -ALTER TABLE blocks - ALTER COLUMN block_uncles_reward TYPE DOUBLE PRECISION USING block_time :: DOUBLE PRECISION; - - --- +goose Down -ALTER TABLE blocks - ALTER COLUMN block_gaslimit TYPE DOUBLE PRECISION USING block_gaslimit :: DOUBLE PRECISION; - -ALTER TABLE blocks - ALTER COLUMN block_gasused TYPE DOUBLE PRECISION USING block_gasused :: DOUBLE PRECISION; - -ALTER TABLE blocks - ALTER COLUMN block_time TYPE DOUBLE PRECISION USING block_time :: DOUBLE PRECISION; - -ALTER TABLE blocks - ALTER COLUMN block_reward TYPE NUMERIC USING block_time :: NUMERIC; - -ALTER TABLE blocks - ALTER COLUMN block_uncles_reward TYPE NUMERIC USING block_time :: NUMERIC; diff --git a/db/migrations/00035_rename_block_columns.sql b/db/migrations/00035_rename_block_columns.sql deleted file mode 100644 index d093ddb4..00000000 --- a/db/migrations/00035_rename_block_columns.sql +++ /dev/null @@ -1,80 +0,0 @@ --- +goose Up -ALTER TABLE blocks - RENAME COLUMN block_number TO number; - -ALTER TABLE blocks - RENAME COLUMN block_gaslimit TO gaslimit; - -ALTER TABLE blocks - RENAME COLUMN block_gasused TO gasused; - -ALTER TABLE blocks - RENAME COLUMN block_time TO time; - -ALTER TABLE blocks - RENAME COLUMN block_difficulty TO difficulty; - -ALTER TABLE blocks - RENAME COLUMN block_hash TO hash; - -ALTER TABLE blocks - RENAME COLUMN block_nonce TO nonce; - -ALTER TABLE blocks - RENAME COLUMN block_parenthash TO parenthash; - -ALTER TABLE blocks - RENAME COLUMN block_size TO size; - -ALTER TABLE blocks - RENAME COLUMN block_miner TO miner; - -ALTER TABLE blocks - RENAME COLUMN block_extra_data TO extra_data; - -ALTER TABLE blocks - RENAME COLUMN block_reward TO reward; - -ALTER TABLE blocks - RENAME COLUMN block_uncles_reward TO uncles_reward; - - --- +goose Down -ALTER TABLE blocks - RENAME COLUMN number TO block_number; - -ALTER TABLE blocks - RENAME COLUMN gaslimit TO block_gaslimit; - -ALTER TABLE blocks - RENAME COLUMN gasused TO block_gasused; - -ALTER TABLE blocks - RENAME COLUMN TIME TO block_time; - -ALTER TABLE blocks - RENAME COLUMN difficulty TO block_difficulty; - -ALTER TABLE blocks - RENAME COLUMN HASH TO block_hash; - -ALTER TABLE blocks - RENAME COLUMN nonce TO block_nonce; - -ALTER TABLE blocks - RENAME COLUMN parenthash TO block_parenthash; - -ALTER TABLE blocks - RENAME COLUMN size TO block_size; - -ALTER TABLE blocks - RENAME COLUMN miner TO block_miner; - -ALTER TABLE blocks - RENAME COLUMN extra_data TO block_extra_data; - -ALTER TABLE blocks - RENAME COLUMN reward TO block_reward; - -ALTER TABLE blocks - RENAME COLUMN uncles_reward TO block_uncles_reward; diff --git a/db/migrations/00036_update_tx_table_names.sql b/db/migrations/00036_update_tx_table_names.sql deleted file mode 100644 index 41848828..00000000 --- a/db/migrations/00036_update_tx_table_names.sql +++ /dev/null @@ -1,38 +0,0 @@ --- +goose Up -ALTER TABLE transactions - RENAME COLUMN tx_hash TO hash; - -ALTER TABLE transactions - RENAME COLUMN tx_nonce TO nonce; - -ALTER TABLE transactions - RENAME COLUMN tx_gaslimit TO gaslimit; - -ALTER TABLE transactions - RENAME COLUMN tx_gasprice TO gasprice; - -ALTER TABLE transactions - RENAME COLUMN tx_value TO value; - -ALTER TABLE transactions - RENAME COLUMN tx_input_data TO input_data; - - --- +goose Down -ALTER TABLE transactions - RENAME COLUMN hash TO tx_hash; - -ALTER TABLE transactions - RENAME COLUMN nonce TO tx_nonce; - -ALTER TABLE transactions - RENAME COLUMN gaslimit TO tx_gaslimit; - -ALTER TABLE transactions - RENAME COLUMN gasprice TO tx_gasprice; - -ALTER TABLE transactions - RENAME COLUMN value TO tx_value; - -ALTER TABLE transactions - RENAME COLUMN input_data TO tx_input_data; diff --git a/db/migrations/00038_update_eth18_types.sql b/db/migrations/00038_update_eth18_types.sql deleted file mode 100644 index 3389d1aa..00000000 --- a/db/migrations/00038_update_eth18_types.sql +++ /dev/null @@ -1,8 +0,0 @@ --- +goose Up -ALTER TABLE blocks - ALTER COLUMN size TYPE VARCHAR USING size::VARCHAR; - - --- +goose Down -ALTER TABLE blocks - ALTER COLUMN size TYPE BIGINT USING size::BIGINT; diff --git a/db/schema.sql b/db/schema.sql index 2501592a..6e45cbaa 100644 --- a/db/schema.sql +++ b/db/schema.sql @@ -67,23 +67,23 @@ CREATE VIEW public.block_stats AS -- CREATE TABLE public.blocks ( - number bigint, - gaslimit bigint, - gasused bigint, - "time" bigint, id integer NOT NULL, difficulty bigint, - hash character varying(66), - nonce character varying(20), - parenthash character varying(66), - size character varying, - uncle_hash character varying(66), - eth_node_id integer NOT NULL, - is_final boolean, - miner character varying(42), extra_data character varying, + gaslimit bigint, + gasused bigint, + hash character varying(66), + miner character varying(42), + nonce character varying(20), + number bigint, + parenthash character varying(66), reward double precision, uncles_reward double precision, + size character varying, + "time" bigint, + is_final boolean, + uncle_hash character varying(66), + eth_node_id integer NOT NULL, eth_node_fingerprint character varying(128) NOT NULL ); @@ -144,10 +144,10 @@ ALTER SEQUENCE public.checked_headers_id_seq OWNED BY public.checked_headers.id; CREATE TABLE public.eth_nodes ( id integer NOT NULL, + client_name character varying, genesis_block character varying(66), network_id numeric, - eth_node_id character varying(128), - client_name character varying + eth_node_id character varying(128) ); @@ -374,15 +374,15 @@ ALTER SEQUENCE public.receipts_id_seq OWNED BY public.receipts.id; CREATE TABLE public.transactions ( id integer NOT NULL, + block_id integer NOT NULL, + input_data character varying, + tx_from character varying(66), + gaslimit numeric, + gasprice numeric, hash character varying(66), nonce numeric, tx_to character varying(66), - gaslimit numeric, - gasprice numeric, - value numeric, - block_id integer NOT NULL, - tx_from character varying(66), - input_data character varying + value numeric ); @@ -412,8 +412,8 @@ ALTER SEQUENCE public.transactions_id_seq OWNED BY public.transactions.id; CREATE TABLE public.watched_contracts ( contract_id integer NOT NULL, - contract_hash character varying(66), - contract_abi json + contract_abi json, + contract_hash character varying(66) ); @@ -561,14 +561,6 @@ ALTER TABLE ONLY public.checked_headers ADD CONSTRAINT checked_headers_pkey PRIMARY KEY (id); --- --- Name: watched_contracts contract_hash_uc; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.watched_contracts - ADD CONSTRAINT contract_hash_uc UNIQUE (contract_hash); - - -- -- Name: blocks eth_node_id_block_number_uc; Type: CONSTRAINT; Schema: public; Owner: - -- @@ -649,6 +641,14 @@ ALTER TABLE ONLY public.transactions ADD CONSTRAINT transactions_pkey PRIMARY KEY (id); +-- +-- Name: watched_contracts watched_contracts_contract_hash_key; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.watched_contracts + ADD CONSTRAINT watched_contracts_contract_hash_key UNIQUE (contract_hash); + + -- -- Name: watched_contracts watched_contracts_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- @@ -664,13 +664,6 @@ ALTER TABLE ONLY public.watched_contracts CREATE INDEX block_id_index ON public.transactions USING btree (block_id); --- --- Name: block_number_index; Type: INDEX; Schema: public; Owner: - --- - -CREATE INDEX block_number_index ON public.blocks USING btree (number); - - -- -- Name: headers_block_number; Type: INDEX; Schema: public; Owner: - -- @@ -685,6 +678,13 @@ CREATE INDEX headers_block_number ON public.headers USING btree (block_number); CREATE INDEX node_id_index ON public.blocks USING btree (eth_node_id); +-- +-- Name: number_index; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX number_index ON public.blocks USING btree (number); + + -- -- Name: tx_from_index; Type: INDEX; Schema: public; Owner: - -- @@ -699,14 +699,6 @@ CREATE INDEX tx_from_index ON public.transactions USING btree (tx_from); CREATE INDEX tx_to_index ON public.transactions USING btree (tx_to); --- --- Name: transactions blocks_fk; Type: FK CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.transactions - ADD CONSTRAINT blocks_fk FOREIGN KEY (block_id) REFERENCES public.blocks(id) ON DELETE CASCADE; - - -- -- Name: receipts blocks_fk; Type: FK CONSTRAINT; Schema: public; Owner: - -- @@ -747,6 +739,14 @@ ALTER TABLE ONLY public.logs ADD CONSTRAINT receipts_fk FOREIGN KEY (receipt_id) REFERENCES public.receipts(id) ON DELETE CASCADE; +-- +-- Name: transactions transactions_block_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.transactions + ADD CONSTRAINT transactions_block_id_fkey FOREIGN KEY (block_id) REFERENCES public.blocks(id) ON DELETE CASCADE; + + -- -- PostgreSQL database dump complete --