From 222252f89aae53cf0903eae0f55f5d8c0c6202fd Mon Sep 17 00:00:00 2001 From: Rob Mulholand Date: Mon, 26 Aug 2019 22:11:28 -0500 Subject: [PATCH] Remove extraneous migration formatting --- db/migrations/00001_create_blocks_table.sql | 35 +++++++------ ...02_create_full_sync_transactions_table.sql | 27 +++++----- .../00004_create_contracts_table.sql | 6 +-- db/migrations/00005_create_nodes_table.sql | 15 +++--- db/migrations/00006_add_node_fk_to_blocks.sql | 12 ++--- ...ock_number_unique_constraint_to_blocks.sql | 4 +- ..._tx_to_index_to_full_sync_transactions.sql | 2 +- ...x_from_index_to_full_sync_transactions.sql | 2 +- db/migrations/00017_create_log_filters.sql | 23 ++++----- ...update_log_filters_to_block_constraint.sql | 8 +-- db/migrations/00020_rename_node_table.sql | 51 ++++++++----------- .../00021_associate_receipts_with_blocks.sql | 36 ++++++------- ...022_add_eth_node_fingerprint_to_blocks.sql | 10 ++-- db/migrations/00023_create_headers_table.sql | 17 +++---- db/migrations/00025_create_queued_storage.sql | 17 +++---- ..._create_header_sync_transactions_table.sql | 29 +++++------ db/migrations/00028_create_uncles_table.sql | 23 ++++----- 17 files changed, 150 insertions(+), 167 deletions(-) diff --git a/db/migrations/00001_create_blocks_table.sql b/db/migrations/00001_create_blocks_table.sql index fb85c820..c11cf1de 100644 --- a/db/migrations/00001_create_blocks_table.sql +++ b/db/migrations/00001_create_blocks_table.sql @@ -1,22 +1,21 @@ -- +goose Up -CREATE TABLE public.blocks -( - id SERIAL PRIMARY KEY, - difficulty BIGINT, - extra_data VARCHAR, - gas_limit BIGINT, - gas_used BIGINT, - hash VARCHAR(66), - miner VARCHAR(42), - nonce VARCHAR(20), - "number" BIGINT, - parent_hash VARCHAR(66), - reward NUMERIC, - uncles_reward NUMERIC, - "size" VARCHAR, - "time" BIGINT, - is_final BOOLEAN, - uncle_hash VARCHAR(66) +CREATE TABLE public.blocks ( + id SERIAL PRIMARY KEY, + difficulty BIGINT, + extra_data VARCHAR, + gas_limit BIGINT, + gas_used BIGINT, + hash VARCHAR(66), + miner VARCHAR(42), + nonce VARCHAR(20), + "number" BIGINT, + parent_hash VARCHAR(66), + reward NUMERIC, + uncles_reward NUMERIC, + "size" VARCHAR, + "time" BIGINT, + is_final BOOLEAN, + uncle_hash VARCHAR(66) ); diff --git a/db/migrations/00002_create_full_sync_transactions_table.sql b/db/migrations/00002_create_full_sync_transactions_table.sql index 84c3d433..72548c95 100644 --- a/db/migrations/00002_create_full_sync_transactions_table.sql +++ b/db/migrations/00002_create_full_sync_transactions_table.sql @@ -1,18 +1,17 @@ -- +goose Up -CREATE TABLE full_sync_transactions -( - id SERIAL PRIMARY KEY, - block_id INTEGER NOT NULL REFERENCES blocks (id) ON DELETE CASCADE, - gas_limit NUMERIC, - gas_price NUMERIC, - hash VARCHAR(66), - input_data BYTEA, - nonce NUMERIC, - raw BYTEA, - tx_from VARCHAR(66), - tx_index INTEGER, - tx_to VARCHAR(66), - "value" NUMERIC +CREATE TABLE full_sync_transactions ( + id SERIAL PRIMARY KEY, + block_id INTEGER NOT NULL REFERENCES blocks(id) ON DELETE CASCADE, + gas_limit NUMERIC, + gas_price NUMERIC, + hash VARCHAR(66), + input_data BYTEA, + nonce NUMERIC, + raw BYTEA, + tx_from VARCHAR(66), + tx_index INTEGER, + tx_to VARCHAR(66), + "value" NUMERIC ); -- +goose Down diff --git a/db/migrations/00004_create_contracts_table.sql b/db/migrations/00004_create_contracts_table.sql index 9d288a79..3ff43bef 100644 --- a/db/migrations/00004_create_contracts_table.sql +++ b/db/migrations/00004_create_contracts_table.sql @@ -1,9 +1,9 @@ -- +goose Up CREATE TABLE watched_contracts ( - contract_id SERIAL PRIMARY KEY, - contract_abi json, - contract_hash VARCHAR(66) UNIQUE + contract_id SERIAL PRIMARY KEY, + contract_abi json, + contract_hash VARCHAR(66) UNIQUE ); -- +goose Down diff --git a/db/migrations/00005_create_nodes_table.sql b/db/migrations/00005_create_nodes_table.sql index 4a38a934..c2c0c7b8 100644 --- a/db/migrations/00005_create_nodes_table.sql +++ b/db/migrations/00005_create_nodes_table.sql @@ -1,12 +1,11 @@ -- +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) +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 diff --git a/db/migrations/00006_add_node_fk_to_blocks.sql b/db/migrations/00006_add_node_fk_to_blocks.sql index dc8e0545..4db8c03f 100644 --- a/db/migrations/00006_add_node_fk_to_blocks.sql +++ b/db/migrations/00006_add_node_fk_to_blocks.sql @@ -1,11 +1,11 @@ -- +goose Up ALTER TABLE blocks - ADD COLUMN node_id INTEGER NOT NULL, - ADD CONSTRAINT node_fk - FOREIGN KEY (node_id) - REFERENCES nodes (id) - ON DELETE CASCADE; + ADD COLUMN node_id INTEGER NOT NULL, + ADD CONSTRAINT node_fk +FOREIGN KEY (node_id) +REFERENCES nodes (id) +ON DELETE CASCADE; -- +goose Down ALTER TABLE blocks - DROP COLUMN node_id; + DROP COLUMN node_id; diff --git a/db/migrations/00008_add_node_block_number_unique_constraint_to_blocks.sql b/db/migrations/00008_add_node_block_number_unique_constraint_to_blocks.sql index 40bbbb7f..30be138d 100644 --- a/db/migrations/00008_add_node_block_number_unique_constraint_to_blocks.sql +++ b/db/migrations/00008_add_node_block_number_unique_constraint_to_blocks.sql @@ -1,7 +1,7 @@ -- +goose Up ALTER TABLE blocks - ADD CONSTRAINT node_id_block_number_uc UNIQUE (number, node_id); + ADD CONSTRAINT node_id_block_number_uc UNIQUE (number, node_id); -- +goose Down ALTER TABLE blocks - DROP CONSTRAINT node_id_block_number_uc; + DROP CONSTRAINT node_id_block_number_uc; diff --git a/db/migrations/00011_add_tx_to_index_to_full_sync_transactions.sql b/db/migrations/00011_add_tx_to_index_to_full_sync_transactions.sql index 51d66c12..cf2977d1 100644 --- a/db/migrations/00011_add_tx_to_index_to_full_sync_transactions.sql +++ b/db/migrations/00011_add_tx_to_index_to_full_sync_transactions.sql @@ -1,5 +1,5 @@ -- +goose Up -CREATE INDEX tx_to_index ON full_sync_transactions (tx_to); +CREATE INDEX tx_to_index ON full_sync_transactions(tx_to); -- +goose Down DROP INDEX tx_to_index; diff --git a/db/migrations/00012_add_tx_from_index_to_full_sync_transactions.sql b/db/migrations/00012_add_tx_from_index_to_full_sync_transactions.sql index 8db62a3d..fa6f0543 100644 --- a/db/migrations/00012_add_tx_from_index_to_full_sync_transactions.sql +++ b/db/migrations/00012_add_tx_from_index_to_full_sync_transactions.sql @@ -1,5 +1,5 @@ -- +goose Up -CREATE INDEX tx_from_index ON full_sync_transactions (tx_from); +CREATE INDEX tx_from_index ON full_sync_transactions(tx_from); -- +goose Down DROP INDEX tx_from_index; diff --git a/db/migrations/00017_create_log_filters.sql b/db/migrations/00017_create_log_filters.sql index 28772b01..0367f5e5 100644 --- a/db/migrations/00017_create_log_filters.sql +++ b/db/migrations/00017_create_log_filters.sql @@ -1,16 +1,15 @@ -- +goose Up -CREATE TABLE log_filters -( - id SERIAL, - name VARCHAR NOT NULL CHECK (name <> ''), - from_block BIGINT CHECK (from_block >= 0), - to_block BIGINT CHECK (from_block >= 0), - address VARCHAR(66), - topic0 VARCHAR(66), - topic1 VARCHAR(66), - topic2 VARCHAR(66), - topic3 VARCHAR(66), - CONSTRAINT name_uc UNIQUE (name) +CREATE TABLE log_filters ( + id SERIAL, + name VARCHAR NOT NULL CHECK (name <> ''), + from_block BIGINT CHECK (from_block >= 0), + to_block BIGINT CHECK (from_block >= 0), + address VARCHAR(66), + topic0 VARCHAR(66), + topic1 VARCHAR(66), + topic2 VARCHAR(66), + topic3 VARCHAR(66), + CONSTRAINT name_uc UNIQUE (name) ); -- +goose Down diff --git a/db/migrations/00019_update_log_filters_to_block_constraint.sql b/db/migrations/00019_update_log_filters_to_block_constraint.sql index 2d43618c..512a44db 100644 --- a/db/migrations/00019_update_log_filters_to_block_constraint.sql +++ b/db/migrations/00019_update_log_filters_to_block_constraint.sql @@ -1,14 +1,14 @@ -- +goose Up ALTER TABLE log_filters - DROP CONSTRAINT log_filters_from_block_check1; + DROP CONSTRAINT log_filters_from_block_check1; ALTER TABLE log_filters - ADD CONSTRAINT log_filters_to_block_check CHECK (to_block >= 0); + ADD CONSTRAINT log_filters_to_block_check CHECK (to_block >= 0); -- +goose Down ALTER TABLE log_filters - DROP CONSTRAINT log_filters_to_block_check; + DROP CONSTRAINT log_filters_to_block_check; ALTER TABLE log_filters - ADD CONSTRAINT log_filters_from_block_check1 CHECK (to_block >= 0); + ADD CONSTRAINT log_filters_from_block_check1 CHECK (to_block >= 0); diff --git a/db/migrations/00020_rename_node_table.sql b/db/migrations/00020_rename_node_table.sql index c1592823..061fda57 100644 --- a/db/migrations/00020_rename_node_table.sql +++ b/db/migrations/00020_rename_node_table.sql @@ -1,52 +1,43 @@ -- +goose Up -ALTER TABLE public.nodes - RENAME TO eth_nodes; +ALTER TABLE public.nodes RENAME TO eth_nodes; +ALTER TABLE public.eth_nodes RENAME COLUMN node_id TO eth_node_id; + +ALTER TABLE public.eth_nodes DROP CONSTRAINT node_uc; ALTER TABLE public.eth_nodes - RENAME COLUMN node_id TO eth_node_id; + ADD CONSTRAINT eth_node_uc UNIQUE (genesis_block, network_id, eth_node_id); -ALTER TABLE public.eth_nodes - DROP CONSTRAINT node_uc; -ALTER TABLE public.eth_nodes - ADD CONSTRAINT eth_node_uc UNIQUE (genesis_block, network_id, eth_node_id); +ALTER TABLE public.blocks RENAME COLUMN node_id TO eth_node_id; +ALTER TABLE public.blocks DROP CONSTRAINT node_id_block_number_uc; ALTER TABLE public.blocks - RENAME COLUMN node_id TO eth_node_id; + ADD CONSTRAINT eth_node_id_block_number_uc UNIQUE (number, eth_node_id); +ALTER TABLE public.blocks DROP CONSTRAINT node_fk; ALTER TABLE public.blocks - DROP CONSTRAINT node_id_block_number_uc; -ALTER TABLE public.blocks - ADD CONSTRAINT eth_node_id_block_number_uc UNIQUE (number, eth_node_id); - -ALTER TABLE public.blocks - DROP CONSTRAINT node_fk; -ALTER TABLE public.blocks - ADD CONSTRAINT node_fk - FOREIGN KEY (eth_node_id) REFERENCES eth_nodes (id) ON DELETE CASCADE; + ADD CONSTRAINT node_fk +FOREIGN KEY (eth_node_id) REFERENCES eth_nodes (id) ON DELETE CASCADE; -- +goose Down ALTER TABLE public.eth_nodes - RENAME TO nodes; + RENAME TO nodes; ALTER TABLE public.nodes - RENAME COLUMN eth_node_id TO node_id; + RENAME COLUMN eth_node_id TO node_id; ALTER TABLE public.nodes - DROP CONSTRAINT eth_node_uc; + DROP CONSTRAINT eth_node_uc; ALTER TABLE public.nodes - ADD CONSTRAINT node_uc UNIQUE (genesis_block, network_id, node_id); + ADD CONSTRAINT node_uc UNIQUE (genesis_block, network_id, node_id); -ALTER TABLE public.blocks - RENAME COLUMN eth_node_id TO node_id; +ALTER TABLE public.blocks RENAME COLUMN eth_node_id TO node_id; +ALTER TABLE public.blocks DROP CONSTRAINT eth_node_id_block_number_uc; ALTER TABLE public.blocks - DROP CONSTRAINT eth_node_id_block_number_uc; -ALTER TABLE public.blocks - ADD CONSTRAINT node_id_block_number_uc UNIQUE (number, node_id); + ADD CONSTRAINT node_id_block_number_uc UNIQUE (number, node_id); +ALTER TABLE public.blocks DROP CONSTRAINT node_fk; ALTER TABLE public.blocks - DROP CONSTRAINT node_fk; -ALTER TABLE public.blocks - ADD CONSTRAINT node_fk - FOREIGN KEY (node_id) REFERENCES nodes (id) ON DELETE CASCADE; + ADD CONSTRAINT node_fk +FOREIGN KEY (node_id) REFERENCES nodes (id) ON DELETE CASCADE; diff --git a/db/migrations/00021_associate_receipts_with_blocks.sql b/db/migrations/00021_associate_receipts_with_blocks.sql index d8d3934a..b60aa2d4 100644 --- a/db/migrations/00021_associate_receipts_with_blocks.sql +++ b/db/migrations/00021_associate_receipts_with_blocks.sql @@ -1,44 +1,44 @@ -- +goose Up ALTER TABLE full_sync_receipts - ADD COLUMN block_id INT; + ADD COLUMN block_id INT; UPDATE full_sync_receipts -SET block_id = ( + SET block_id = ( SELECT block_id FROM full_sync_transactions WHERE full_sync_transactions.id = full_sync_receipts.transaction_id -); + ); ALTER TABLE full_sync_receipts - ALTER COLUMN block_id SET NOT NULL; + ALTER COLUMN block_id SET NOT NULL; ALTER TABLE full_sync_receipts - ADD CONSTRAINT blocks_fk - FOREIGN KEY (block_id) - REFERENCES blocks (id) - ON DELETE CASCADE; + ADD CONSTRAINT blocks_fk +FOREIGN KEY (block_id) +REFERENCES blocks (id) +ON DELETE CASCADE; ALTER TABLE full_sync_receipts - DROP COLUMN transaction_id; + DROP COLUMN transaction_id; -- +goose Down ALTER TABLE full_sync_receipts - ADD COLUMN transaction_id INT; + ADD COLUMN transaction_id INT; CREATE INDEX transaction_id_index ON full_sync_receipts (transaction_id); UPDATE full_sync_receipts -SET transaction_id = ( + SET transaction_id = ( SELECT id FROM full_sync_transactions WHERE full_sync_transactions.hash = full_sync_receipts.tx_hash -); + ); ALTER TABLE full_sync_receipts - ALTER COLUMN transaction_id SET NOT NULL; + ALTER COLUMN transaction_id SET NOT NULL; ALTER TABLE full_sync_receipts - ADD CONSTRAINT transaction_fk - FOREIGN KEY (transaction_id) - REFERENCES full_sync_transactions (id) - ON DELETE CASCADE; + ADD CONSTRAINT transaction_fk +FOREIGN KEY (transaction_id) +REFERENCES full_sync_transactions (id) +ON DELETE CASCADE; ALTER TABLE full_sync_receipts - DROP COLUMN block_id; + DROP COLUMN block_id; diff --git a/db/migrations/00022_add_eth_node_fingerprint_to_blocks.sql b/db/migrations/00022_add_eth_node_fingerprint_to_blocks.sql index b295abc8..5c48c03e 100644 --- a/db/migrations/00022_add_eth_node_fingerprint_to_blocks.sql +++ b/db/migrations/00022_add_eth_node_fingerprint_to_blocks.sql @@ -1,16 +1,16 @@ -- +goose Up ALTER TABLE blocks - ADD COLUMN eth_node_fingerprint VARCHAR(128); + ADD COLUMN eth_node_fingerprint VARCHAR(128); UPDATE blocks -SET eth_node_fingerprint = ( + SET eth_node_fingerprint = ( SELECT eth_node_id FROM eth_nodes WHERE eth_nodes.id = blocks.eth_node_id -); + ); ALTER TABLE blocks - ALTER COLUMN eth_node_fingerprint SET NOT NULL; + ALTER COLUMN eth_node_fingerprint SET NOT NULL; -- +goose Down ALTER TABLE blocks - DROP COLUMN eth_node_fingerprint; + DROP COLUMN eth_node_fingerprint; diff --git a/db/migrations/00023_create_headers_table.sql b/db/migrations/00023_create_headers_table.sql index 2c8f30a1..925c202b 100644 --- a/db/migrations/00023_create_headers_table.sql +++ b/db/migrations/00023_create_headers_table.sql @@ -1,13 +1,12 @@ -- +goose Up -CREATE TABLE public.headers -( - id SERIAL PRIMARY KEY, - hash VARCHAR(66), - block_number BIGINT, - raw JSONB, - block_timestamp NUMERIC, - eth_node_id INTEGER NOT NULL REFERENCES eth_nodes (id) ON DELETE CASCADE, - eth_node_fingerprint VARCHAR(128) +CREATE TABLE public.headers ( + id SERIAL PRIMARY KEY, + hash VARCHAR(66), + block_number BIGINT, + raw JSONB, + block_timestamp NUMERIC, + eth_node_id INTEGER NOT NULL REFERENCES eth_nodes (id) ON DELETE CASCADE, + eth_node_fingerprint VARCHAR(128) ); -- Index is removed when table is diff --git a/db/migrations/00025_create_queued_storage.sql b/db/migrations/00025_create_queued_storage.sql index 71ab8886..79a3a548 100644 --- a/db/migrations/00025_create_queued_storage.sql +++ b/db/migrations/00025_create_queued_storage.sql @@ -1,13 +1,12 @@ -- +goose Up -CREATE TABLE public.queued_storage -( - id SERIAL PRIMARY KEY, - block_height BIGINT, - block_hash BYTEA, - contract BYTEA, - storage_key BYTEA, - storage_value BYTEA, - UNIQUE (block_height, block_hash, contract, storage_key, storage_value) +CREATE TABLE public.queued_storage ( + id SERIAL PRIMARY KEY, + block_height BIGINT, + block_hash BYTEA, + contract BYTEA, + storage_key BYTEA, + storage_value BYTEA, + UNIQUE (block_height, block_hash, contract, storage_key, storage_value) ); -- +goose Down diff --git a/db/migrations/00026_create_header_sync_transactions_table.sql b/db/migrations/00026_create_header_sync_transactions_table.sql index 358ce65c..469f8f85 100644 --- a/db/migrations/00026_create_header_sync_transactions_table.sql +++ b/db/migrations/00026_create_header_sync_transactions_table.sql @@ -1,19 +1,18 @@ -- +goose Up -CREATE TABLE header_sync_transactions -( - id SERIAL PRIMARY KEY, - header_id INTEGER NOT NULL REFERENCES headers (id) ON DELETE CASCADE, - hash VARCHAR(66), - gas_limit NUMERIC, - gas_price NUMERIC, - input_data BYTEA, - nonce NUMERIC, - raw BYTEA, - tx_from VARCHAR(44), - tx_index INTEGER, - tx_to VARCHAR(44), - "value" NUMERIC, - UNIQUE (header_id, hash) +CREATE TABLE header_sync_transactions ( + id SERIAL PRIMARY KEY, + header_id INTEGER NOT NULL REFERENCES headers(id) ON DELETE CASCADE, + hash VARCHAR(66), + gas_limit NUMERIC, + gas_price NUMERIC, + input_data BYTEA, + nonce NUMERIC, + raw BYTEA, + tx_from VARCHAR(44), + tx_index INTEGER, + tx_to VARCHAR(44), + "value" NUMERIC, + UNIQUE (header_id, hash) ); -- +goose Down diff --git a/db/migrations/00028_create_uncles_table.sql b/db/migrations/00028_create_uncles_table.sql index 703d50f2..9ec0ffa7 100644 --- a/db/migrations/00028_create_uncles_table.sql +++ b/db/migrations/00028_create_uncles_table.sql @@ -1,16 +1,15 @@ -- +goose Up -CREATE TABLE public.uncles -( - id SERIAL PRIMARY KEY, - hash VARCHAR(66) NOT NULL, - block_id INTEGER NOT NULL REFERENCES blocks (id) ON DELETE CASCADE, - reward NUMERIC NOT NULL, - miner VARCHAR(42) NOT NULL, - raw JSONB, - block_timestamp NUMERIC, - eth_node_id INTEGER NOT NULL REFERENCES eth_nodes (id) ON DELETE CASCADE, - eth_node_fingerprint VARCHAR(128), - UNIQUE (block_id, hash) +CREATE TABLE public.uncles ( + id SERIAL PRIMARY KEY, + hash VARCHAR(66) NOT NULL, + block_id INTEGER NOT NULL REFERENCES blocks (id) ON DELETE CASCADE, + reward NUMERIC NOT NULL, + miner VARCHAR(42) NOT NULL, + raw JSONB, + block_timestamp NUMERIC, + eth_node_id INTEGER NOT NULL REFERENCES eth_nodes (id) ON DELETE CASCADE, + eth_node_fingerprint VARCHAR(128), + UNIQUE (block_id, hash) ); -- +goose Down