From 18299c76e22b1a700a689f7e66e0b789931d1bb1 Mon Sep 17 00:00:00 2001 From: Ian Norden Date: Mon, 13 Jul 2020 10:39:51 -0500 Subject: [PATCH] refactor migrations for new db instance, add mh_key rows --- ...sql => 00001_create_ipfs_blocks_table.sql} | 0 ...table.sql => 00002_create_nodes_table.sql} | 0 ...schema.sql => 00003_create_eth_schema.sql} | 0 ...=> 00004_create_eth_header_cids_table.sql} | 8 + ... => 00005_create_eth_uncle_cids_table.sql} | 1 + ...006_create_eth_transaction_cids_table.sql} | 1 + ...> 00007_create_eth_receipt_cids_table.sql} | 6 +- .../00007_create_eth_state_cids_table.sql | 12 - .../00008_create_eth_state_cids_table.sql | 15 ++ .../00008_create_eth_storage_cids_table.sql | 12 - .../00009_create_eth_storage_cids_table.sql | 15 ++ ... 00010_create_eth_state_accouts_table.sql} | 0 .../00011_create_btc_header_cids_table.sql | 15 -- ...schema.sql => 00011_create_btc_schema.sql} | 0 .../00012_create_btc_header_cids_table.sql | 17 ++ ...013_create_btc_transaction_cids_table.sql} | 1 + ... => 00014_create_btc_tx_outputs_table.sql} | 0 ...l => 00015_create_btc_tx_inputs_table.sql} | 0 .../00015_create_eth_queued_data_table.sql | 9 - .../00016_create_btc_queued_data_table.sql | 9 - ...=> 00016_create_postgraphile_comments.sql} | 2 - db/migrations/00018_update_state_cids.sql | 37 --- db/migrations/00019_update_storage_cids.sql | 37 --- db/migrations/00020_update_header_cids.sql | 37 --- db/migrations/00022_rename_to_leaf_key.sql | 13 -- db/migrations/00023_update_receipt_cids.sql | 22 -- db/migrations/00024_add_times_validated.sql | 13 -- db/migrations/00025_eth_add_diff_row.sql | 13 -- db/schema.sql | 212 +++++++----------- 29 files changed, 144 insertions(+), 363 deletions(-) rename db/migrations/{00009_create_ipfs_blocks_table.sql => 00001_create_ipfs_blocks_table.sql} (100%) rename db/migrations/{00001_create_nodes_table.sql => 00002_create_nodes_table.sql} (100%) rename db/migrations/{00002_create_eth_schema.sql => 00003_create_eth_schema.sql} (100%) rename db/migrations/{00003_create_eth_header_cids_table.sql => 00004_create_eth_header_cids_table.sql} (53%) rename db/migrations/{00004_create_eth_uncle_cids_table.sql => 00005_create_eth_uncle_cids_table.sql} (79%) rename db/migrations/{00005_create_eth_transaction_cids_table.sql => 00006_create_eth_transaction_cids_table.sql} (81%) rename db/migrations/{00006_create_eth_receipt_cids_table.sql => 00007_create_eth_receipt_cids_table.sql} (64%) delete mode 100644 db/migrations/00007_create_eth_state_cids_table.sql create mode 100644 db/migrations/00008_create_eth_state_cids_table.sql delete mode 100644 db/migrations/00008_create_eth_storage_cids_table.sql create mode 100644 db/migrations/00009_create_eth_storage_cids_table.sql rename db/migrations/{00021_create_eth_state_accouts_table.sql => 00010_create_eth_state_accouts_table.sql} (100%) delete mode 100644 db/migrations/00011_create_btc_header_cids_table.sql rename db/migrations/{00010_create_btc_schema.sql => 00011_create_btc_schema.sql} (100%) create mode 100644 db/migrations/00012_create_btc_header_cids_table.sql rename db/migrations/{00012_create_btc_transaction_cids_table.sql => 00013_create_btc_transaction_cids_table.sql} (78%) rename db/migrations/{00013_create_btc_tx_outputs_table.sql => 00014_create_btc_tx_outputs_table.sql} (100%) rename db/migrations/{00014_create_btc_tx_inputs_table.sql => 00015_create_btc_tx_inputs_table.sql} (100%) delete mode 100644 db/migrations/00015_create_eth_queued_data_table.sql delete mode 100644 db/migrations/00016_create_btc_queued_data_table.sql rename db/migrations/{00017_create_postgraphile_comments.sql => 00016_create_postgraphile_comments.sql} (81%) delete mode 100644 db/migrations/00018_update_state_cids.sql delete mode 100644 db/migrations/00019_update_storage_cids.sql delete mode 100644 db/migrations/00020_update_header_cids.sql delete mode 100644 db/migrations/00022_rename_to_leaf_key.sql delete mode 100644 db/migrations/00023_update_receipt_cids.sql delete mode 100644 db/migrations/00024_add_times_validated.sql delete mode 100644 db/migrations/00025_eth_add_diff_row.sql diff --git a/db/migrations/00009_create_ipfs_blocks_table.sql b/db/migrations/00001_create_ipfs_blocks_table.sql similarity index 100% rename from db/migrations/00009_create_ipfs_blocks_table.sql rename to db/migrations/00001_create_ipfs_blocks_table.sql diff --git a/db/migrations/00001_create_nodes_table.sql b/db/migrations/00002_create_nodes_table.sql similarity index 100% rename from db/migrations/00001_create_nodes_table.sql rename to db/migrations/00002_create_nodes_table.sql diff --git a/db/migrations/00002_create_eth_schema.sql b/db/migrations/00003_create_eth_schema.sql similarity index 100% rename from db/migrations/00002_create_eth_schema.sql rename to db/migrations/00003_create_eth_schema.sql diff --git a/db/migrations/00003_create_eth_header_cids_table.sql b/db/migrations/00004_create_eth_header_cids_table.sql similarity index 53% rename from db/migrations/00003_create_eth_header_cids_table.sql rename to db/migrations/00004_create_eth_header_cids_table.sql index c689ec40..339eb427 100644 --- a/db/migrations/00003_create_eth_header_cids_table.sql +++ b/db/migrations/00004_create_eth_header_cids_table.sql @@ -5,9 +5,17 @@ CREATE TABLE eth.header_cids ( block_hash VARCHAR(66) NOT NULL, parent_hash VARCHAR(66) NOT NULL, cid TEXT NOT NULL, + mh_key TEXT NOT NULL REFERENCES public.blocks (key) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, td NUMERIC NOT NULL, node_id INTEGER NOT NULL REFERENCES nodes (id) ON DELETE CASCADE, reward NUMERIC NOT NULL, + state_root VARCHAR(66) NOT NULL, + tx_root VARCHAR(66) NOT NULL, + receipt_root VARCHAR(66) NOT NULL, + uncle_root VARCHAR(66) NOT NULL, + bloom BYTEA NOT NULL, + timestamp NUMERIC NOT NULL, + times_validated INTEGER NOT NULL DEFAULT 1, UNIQUE (block_number, block_hash) ); diff --git a/db/migrations/00004_create_eth_uncle_cids_table.sql b/db/migrations/00005_create_eth_uncle_cids_table.sql similarity index 79% rename from db/migrations/00004_create_eth_uncle_cids_table.sql rename to db/migrations/00005_create_eth_uncle_cids_table.sql index 8e372e4c..c46cafb9 100644 --- a/db/migrations/00004_create_eth_uncle_cids_table.sql +++ b/db/migrations/00005_create_eth_uncle_cids_table.sql @@ -5,6 +5,7 @@ CREATE TABLE eth.uncle_cids ( block_hash VARCHAR(66) NOT NULL, parent_hash VARCHAR(66) NOT NULL, cid TEXT NOT NULL, + mh_key TEXT NOT NULL REFERENCES public.blocks (key) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, reward NUMERIC NOT NULL, UNIQUE (header_id, block_hash) ); diff --git a/db/migrations/00005_create_eth_transaction_cids_table.sql b/db/migrations/00006_create_eth_transaction_cids_table.sql similarity index 81% rename from db/migrations/00005_create_eth_transaction_cids_table.sql rename to db/migrations/00006_create_eth_transaction_cids_table.sql index e3750ced..cbbef782 100644 --- a/db/migrations/00005_create_eth_transaction_cids_table.sql +++ b/db/migrations/00006_create_eth_transaction_cids_table.sql @@ -5,6 +5,7 @@ CREATE TABLE eth.transaction_cids ( tx_hash VARCHAR(66) NOT NULL, index INTEGER NOT NULL, cid TEXT NOT NULL, + mh_key TEXT NOT NULL REFERENCES public.blocks (key) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, dst VARCHAR(66) NOT NULL, src VARCHAR(66) NOT NULL, UNIQUE (header_id, tx_hash) diff --git a/db/migrations/00006_create_eth_receipt_cids_table.sql b/db/migrations/00007_create_eth_receipt_cids_table.sql similarity index 64% rename from db/migrations/00006_create_eth_receipt_cids_table.sql rename to db/migrations/00007_create_eth_receipt_cids_table.sql index a8f77de0..5d4ae0cc 100644 --- a/db/migrations/00006_create_eth_receipt_cids_table.sql +++ b/db/migrations/00007_create_eth_receipt_cids_table.sql @@ -3,11 +3,15 @@ CREATE TABLE eth.receipt_cids ( id SERIAL PRIMARY KEY, tx_id INTEGER NOT NULL REFERENCES eth.transaction_cids (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, cid TEXT NOT NULL, + mh_key TEXT NOT NULL REFERENCES public.blocks (key) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, contract VARCHAR(66), + contract_hash VARCHAR(66), topic0s VARCHAR(66)[], topic1s VARCHAR(66)[], topic2s VARCHAR(66)[], - topic3s VARCHAR(66)[] + topic3s VARCHAR(66)[], + log_contracts VARCHAR(66)[], + UNIQUE (tx_id) ); -- +goose Down diff --git a/db/migrations/00007_create_eth_state_cids_table.sql b/db/migrations/00007_create_eth_state_cids_table.sql deleted file mode 100644 index 6f0170a5..00000000 --- a/db/migrations/00007_create_eth_state_cids_table.sql +++ /dev/null @@ -1,12 +0,0 @@ --- +goose Up -CREATE TABLE eth.state_cids ( - id SERIAL PRIMARY KEY, - header_id INTEGER NOT NULL REFERENCES eth.header_cids (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, - state_key VARCHAR(66) NOT NULL, - leaf BOOLEAN NOT NULL, - cid TEXT NOT NULL, - UNIQUE (header_id, state_key) -); - --- +goose Down -DROP TABLE eth.state_cids; \ No newline at end of file diff --git a/db/migrations/00008_create_eth_state_cids_table.sql b/db/migrations/00008_create_eth_state_cids_table.sql new file mode 100644 index 00000000..e0bf6e57 --- /dev/null +++ b/db/migrations/00008_create_eth_state_cids_table.sql @@ -0,0 +1,15 @@ +-- +goose Up +CREATE TABLE eth.state_cids ( + id SERIAL PRIMARY KEY, + header_id INTEGER NOT NULL REFERENCES eth.header_cids (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, + state_leaf_key VARCHAR(66), + cid TEXT NOT NULL, + mh_key TEXT NOT NULL REFERENCES public.blocks (key) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, + state_path BYTEA, + node_type INTEGER, + diff BOOLEAN NOT NULL DEFAULT FALSE, + UNIQUE (header_id, state_path) +); + +-- +goose Down +DROP TABLE eth.state_cids; \ No newline at end of file diff --git a/db/migrations/00008_create_eth_storage_cids_table.sql b/db/migrations/00008_create_eth_storage_cids_table.sql deleted file mode 100644 index 070eda45..00000000 --- a/db/migrations/00008_create_eth_storage_cids_table.sql +++ /dev/null @@ -1,12 +0,0 @@ --- +goose Up -CREATE TABLE eth.storage_cids ( - id SERIAL PRIMARY KEY, - state_id INTEGER NOT NULL REFERENCES eth.state_cids (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, - storage_key VARCHAR(66) NOT NULL, - leaf BOOLEAN NOT NULL, - cid TEXT NOT NULL, - UNIQUE (state_id, storage_key) -); - --- +goose Down -DROP TABLE eth.storage_cids; \ No newline at end of file diff --git a/db/migrations/00009_create_eth_storage_cids_table.sql b/db/migrations/00009_create_eth_storage_cids_table.sql new file mode 100644 index 00000000..944d39ed --- /dev/null +++ b/db/migrations/00009_create_eth_storage_cids_table.sql @@ -0,0 +1,15 @@ +-- +goose Up +CREATE TABLE eth.storage_cids ( + id SERIAL PRIMARY KEY, + state_id INTEGER NOT NULL REFERENCES eth.state_cids (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, + storage_leaf_key VARCHAR(66), + cid TEXT NOT NULL, + mh_key TEXT NOT NULL REFERENCES public.blocks (key) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, + storage_path BYTEA, + node_type INTEGER NOT NULL, + diff BOOLEAN NOT NULL DEFAULT FALSE, + UNIQUE (state_id, storage_path) +); + +-- +goose Down +DROP TABLE eth.storage_cids; \ No newline at end of file diff --git a/db/migrations/00021_create_eth_state_accouts_table.sql b/db/migrations/00010_create_eth_state_accouts_table.sql similarity index 100% rename from db/migrations/00021_create_eth_state_accouts_table.sql rename to db/migrations/00010_create_eth_state_accouts_table.sql diff --git a/db/migrations/00011_create_btc_header_cids_table.sql b/db/migrations/00011_create_btc_header_cids_table.sql deleted file mode 100644 index 04a6f65e..00000000 --- a/db/migrations/00011_create_btc_header_cids_table.sql +++ /dev/null @@ -1,15 +0,0 @@ --- +goose Up -CREATE TABLE btc.header_cids ( - id SERIAL PRIMARY KEY, - block_number BIGINT NOT NULL, - block_hash VARCHAR(66) NOT NULL, - parent_hash VARCHAR(66) NOT NULL, - cid TEXT NOT NULL, - timestamp NUMERIC NOT NULL, - bits BIGINT NOT NULL, - node_id INTEGER NOT NULL REFERENCES nodes (id) ON DELETE CASCADE, - UNIQUE (block_number, block_hash) -); - --- +goose Down -DROP TABLE btc.header_cids; \ No newline at end of file diff --git a/db/migrations/00010_create_btc_schema.sql b/db/migrations/00011_create_btc_schema.sql similarity index 100% rename from db/migrations/00010_create_btc_schema.sql rename to db/migrations/00011_create_btc_schema.sql diff --git a/db/migrations/00012_create_btc_header_cids_table.sql b/db/migrations/00012_create_btc_header_cids_table.sql new file mode 100644 index 00000000..fcdb075d --- /dev/null +++ b/db/migrations/00012_create_btc_header_cids_table.sql @@ -0,0 +1,17 @@ +-- +goose Up +CREATE TABLE btc.header_cids ( + id SERIAL PRIMARY KEY, + block_number BIGINT NOT NULL, + block_hash VARCHAR(66) NOT NULL, + parent_hash VARCHAR(66) NOT NULL, + cid TEXT NOT NULL, + mh_key TEXT NOT NULL REFERENCES public.blocks (key) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, + timestamp NUMERIC NOT NULL, + bits BIGINT NOT NULL, + node_id INTEGER NOT NULL REFERENCES nodes (id) ON DELETE CASCADE, + times_validated INTEGER NOT NULL DEFAULT 1, + UNIQUE (block_number, block_hash) +); + +-- +goose Down +DROP TABLE btc.header_cids; \ No newline at end of file diff --git a/db/migrations/00012_create_btc_transaction_cids_table.sql b/db/migrations/00013_create_btc_transaction_cids_table.sql similarity index 78% rename from db/migrations/00012_create_btc_transaction_cids_table.sql rename to db/migrations/00013_create_btc_transaction_cids_table.sql index 2648c6ef..aabf8af9 100644 --- a/db/migrations/00012_create_btc_transaction_cids_table.sql +++ b/db/migrations/00013_create_btc_transaction_cids_table.sql @@ -5,6 +5,7 @@ CREATE TABLE btc.transaction_cids ( index INTEGER NOT NULL, tx_hash VARCHAR(66) NOT NULL UNIQUE, cid TEXT NOT NULL, + mh_key TEXT NOT NULL REFERENCES public.blocks (key) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, segwit BOOL NOT NULL, witness_hash VARCHAR(66) ); diff --git a/db/migrations/00013_create_btc_tx_outputs_table.sql b/db/migrations/00014_create_btc_tx_outputs_table.sql similarity index 100% rename from db/migrations/00013_create_btc_tx_outputs_table.sql rename to db/migrations/00014_create_btc_tx_outputs_table.sql diff --git a/db/migrations/00014_create_btc_tx_inputs_table.sql b/db/migrations/00015_create_btc_tx_inputs_table.sql similarity index 100% rename from db/migrations/00014_create_btc_tx_inputs_table.sql rename to db/migrations/00015_create_btc_tx_inputs_table.sql diff --git a/db/migrations/00015_create_eth_queued_data_table.sql b/db/migrations/00015_create_eth_queued_data_table.sql deleted file mode 100644 index 87f58ad8..00000000 --- a/db/migrations/00015_create_eth_queued_data_table.sql +++ /dev/null @@ -1,9 +0,0 @@ --- +goose Up -CREATE TABLE eth.queue_data ( - id SERIAL PRIMARY KEY, - data BYTEA NOT NULL, - height BIGINT UNIQUE NOT NULL -); - --- +goose Down -DROP TABLE eth.queue_data; \ No newline at end of file diff --git a/db/migrations/00016_create_btc_queued_data_table.sql b/db/migrations/00016_create_btc_queued_data_table.sql deleted file mode 100644 index c1344f86..00000000 --- a/db/migrations/00016_create_btc_queued_data_table.sql +++ /dev/null @@ -1,9 +0,0 @@ --- +goose Up -CREATE TABLE btc.queue_data ( - id SERIAL PRIMARY KEY, - data BYTEA NOT NULL, - height BIGINT UNIQUE NOT NULL -); - --- +goose Down -DROP TABLE btc.queue_data; \ No newline at end of file diff --git a/db/migrations/00017_create_postgraphile_comments.sql b/db/migrations/00016_create_postgraphile_comments.sql similarity index 81% rename from db/migrations/00017_create_postgraphile_comments.sql rename to db/migrations/00016_create_postgraphile_comments.sql index 6d7668ba..c426efd1 100644 --- a/db/migrations/00017_create_postgraphile_comments.sql +++ b/db/migrations/00016_create_postgraphile_comments.sql @@ -2,10 +2,8 @@ COMMENT ON TABLE public.nodes IS E'@name NodeInfo'; COMMENT ON TABLE btc.header_cids IS E'@name BtcHeaderCids'; COMMENT ON TABLE btc.transaction_cids IS E'@name BtcTransactionCids'; -COMMENT ON TABLE btc.queue_data IS E'@name BtcQueueData'; COMMENT ON TABLE eth.transaction_cids IS E'@name EthTransactionCids'; COMMENT ON TABLE eth.header_cids IS E'@name EthHeaderCids'; -COMMENT ON TABLE eth.queue_data IS E'@name EthQueueData'; COMMENT ON COLUMN public.nodes.node_id IS E'@name ChainNodeID'; COMMENT ON COLUMN eth.header_cids.node_id IS E'@name EthNodeID'; COMMENT ON COLUMN btc.header_cids.node_id IS E'@name BtcNodeID'; \ No newline at end of file diff --git a/db/migrations/00018_update_state_cids.sql b/db/migrations/00018_update_state_cids.sql deleted file mode 100644 index daea294b..00000000 --- a/db/migrations/00018_update_state_cids.sql +++ /dev/null @@ -1,37 +0,0 @@ --- +goose Up -ALTER TABLE eth.state_cids -ADD COLUMN state_path BYTEA; - -ALTER TABLE eth.state_cids -DROP COLUMN leaf; - -ALTER TABLE eth.state_cids -ADD COLUMN node_type INTEGER; - -ALTER TABLE eth.state_cids -ALTER COLUMN state_key DROP NOT NULL; - -ALTER TABLE eth.state_cids -DROP CONSTRAINT state_cids_header_id_state_key_key; - -ALTER TABLE eth.state_cids -ADD CONSTRAINT state_cids_header_id_state_path_key UNIQUE (header_id, state_path); - --- +goose Down -ALTER TABLE eth.state_cids -ADD CONSTRAINT state_cids_header_id_state_key_key UNIQUE (header_id, state_key); - -ALTER TABLE eth.state_cids -DROP CONSTRAINT state_cids_header_id_state_path_key; - -ALTER TABLE eth.state_cids -ALTER COLUMN state_key SET NOT NULL; - -ALTER TABLE eth.state_cids -DROP COLUMN node_type; - -ALTER TABLE eth.state_cids -ADD COLUMN leaf BOOLEAN NOT NULL; - -ALTER TABLE eth.state_cids -DROP COLUMN state_path; \ No newline at end of file diff --git a/db/migrations/00019_update_storage_cids.sql b/db/migrations/00019_update_storage_cids.sql deleted file mode 100644 index 385f2468..00000000 --- a/db/migrations/00019_update_storage_cids.sql +++ /dev/null @@ -1,37 +0,0 @@ --- +goose Up -ALTER TABLE eth.storage_cids -ADD COLUMN storage_path BYTEA; - -ALTER TABLE eth.storage_cids -DROP COLUMN leaf; - -ALTER TABLE eth.storage_cids -ADD COLUMN node_type INTEGER; - -ALTER TABLE eth.storage_cids -ALTER COLUMN storage_key DROP NOT NULL; - -ALTER TABLE eth.storage_cids -DROP CONSTRAINT storage_cids_state_id_storage_key_key; - -ALTER TABLE eth.storage_cids -ADD CONSTRAINT storage_cids_state_id_storage_path_key UNIQUE (state_id, storage_path); - --- +goose Down -ALTER TABLE eth.storage_cids -DROP CONSTRAINT storage_cids_state_id_storage_path_key; - -ALTER TABLE eth.storage_cids -ADD CONSTRAINT storage_cids_state_id_storage_key_key UNIQUE (state_id, storage_key); - -ALTER TABLE eth.storage_cids -ALTER COLUMN storage_key SET NOT NULL; - -ALTER TABLE eth.storage_cids -DROP COLUMN node_type; - -ALTER TABLE eth.storage_cids -ADD COLUMN leaf BOOLEAN NOT NULL; - -ALTER TABLE eth.storage_cids -DROP COLUMN storage_path; \ No newline at end of file diff --git a/db/migrations/00020_update_header_cids.sql b/db/migrations/00020_update_header_cids.sql deleted file mode 100644 index 1c69c11c..00000000 --- a/db/migrations/00020_update_header_cids.sql +++ /dev/null @@ -1,37 +0,0 @@ --- +goose Up -ALTER TABLE eth.header_cids -ADD COLUMN state_root VARCHAR(66); - -ALTER TABLE eth.header_cids -ADD COLUMN tx_root VARCHAR(66); - -ALTER TABLE eth.header_cids -ADD COLUMN receipt_root VARCHAR(66); - -ALTER TABLE eth.header_cids -ADD COLUMN uncle_root VARCHAR(66); - -ALTER TABLE eth.header_cids -ADD COLUMN bloom BYTEA; - -ALTER TABLE eth.header_cids -ADD COLUMN timestamp NUMERIC; - --- +goose Down -ALTER TABLE eth.header_cids -DROP COLUMN timestamp; - -ALTER TABLE eth.header_cids -DROP COLUMN bloom; - -ALTER TABLE eth.header_cids -DROP COLUMN uncle_root; - -ALTER TABLE eth.header_cids -DROP COLUMN receipt_root; - -ALTER TABLE eth.header_cids -DROP COLUMN tx_root; - -ALTER TABLE eth.header_cids -DROP COLUMN state_root; \ No newline at end of file diff --git a/db/migrations/00022_rename_to_leaf_key.sql b/db/migrations/00022_rename_to_leaf_key.sql deleted file mode 100644 index 0bcf28bf..00000000 --- a/db/migrations/00022_rename_to_leaf_key.sql +++ /dev/null @@ -1,13 +0,0 @@ --- +goose Up -ALTER TABLE eth.state_cids -RENAME COLUMN state_key TO state_leaf_key; - -ALTER TABLE eth.storage_cids -RENAME COLUMN storage_key TO storage_leaf_key; - --- +goose Down -ALTER TABLE eth.storage_cids -RENAME COLUMN storage_leaf_key TO storage_key; - -ALTER TABLE eth.state_cids -RENAME COLUMN state_leaf_key TO state_key; \ No newline at end of file diff --git a/db/migrations/00023_update_receipt_cids.sql b/db/migrations/00023_update_receipt_cids.sql deleted file mode 100644 index 15ec931e..00000000 --- a/db/migrations/00023_update_receipt_cids.sql +++ /dev/null @@ -1,22 +0,0 @@ --- +goose Up -ALTER TABLE eth.receipt_cids -ADD COLUMN log_contracts VARCHAR(66)[]; - -ALTER TABLE eth.receipt_cids -ADD COLUMN contract_hash VARCHAR(66); - -WITH uniques AS (SELECT DISTINCT ON (tx_id) * FROM eth.receipt_cids) -DELETE FROM eth.receipt_cids WHERE receipt_cids.id NOT IN (SELECT id FROM uniques); - -ALTER TABLE eth.receipt_cids -ADD CONSTRAINT receipt_cids_tx_id_key UNIQUE (tx_id); - --- +goose Down -ALTER TABLE eth.receipt_cids -DROP CONSTRAINT receipt_cids_tx_id_key; - -ALTER TABLE eth.receipt_cids -DROP COLUMN contract_hash; - -ALTER TABLE eth.receipt_cids -DROP COLUMN log_contracts; \ No newline at end of file diff --git a/db/migrations/00024_add_times_validated.sql b/db/migrations/00024_add_times_validated.sql deleted file mode 100644 index eb8cbd27..00000000 --- a/db/migrations/00024_add_times_validated.sql +++ /dev/null @@ -1,13 +0,0 @@ --- +goose Up -ALTER TABLE eth.header_cids -ADD COLUMN times_validated INTEGER NOT NULL DEFAULT 1; - -ALTER TABLE btc.header_cids -ADD COLUMN times_validated INTEGER NOT NULL DEFAULT 1; - --- +goose Down -ALTER TABLE btc.header_cids -DROP COLUMN times_validated; - -ALTER TABLE eth.header_cids -DROP COLUMN times_validated; \ No newline at end of file diff --git a/db/migrations/00025_eth_add_diff_row.sql b/db/migrations/00025_eth_add_diff_row.sql deleted file mode 100644 index fa2c5640..00000000 --- a/db/migrations/00025_eth_add_diff_row.sql +++ /dev/null @@ -1,13 +0,0 @@ --- +goose Up -ALTER TABLE eth.state_cids -ADD COLUMN diff BOOLEAN NOT NULL DEFAULT FALSE; - -ALTER TABLE eth.storage_cids -ADD COLUMN diff BOOLEAN NOT NULL DEFAULT FALSE; - --- +goose Down -ALTER TABLE eth.state_cids -DROP COLUMN diff; - -ALTER TABLE eth.storage_cids -DROP COLUMN diff; \ No newline at end of file diff --git a/db/schema.sql b/db/schema.sql index 3520e20b..caa1bb67 100644 --- a/db/schema.sql +++ b/db/schema.sql @@ -44,6 +44,7 @@ CREATE TABLE btc.header_cids ( block_hash character varying(66) NOT NULL, parent_hash character varying(66) NOT NULL, cid text NOT NULL, + mh_key text NOT NULL, "timestamp" numeric NOT NULL, bits bigint NOT NULL, node_id integer NOT NULL, @@ -85,44 +86,6 @@ CREATE SEQUENCE btc.header_cids_id_seq ALTER SEQUENCE btc.header_cids_id_seq OWNED BY btc.header_cids.id; --- --- Name: queue_data; Type: TABLE; Schema: btc; Owner: - --- - -CREATE TABLE btc.queue_data ( - id integer NOT NULL, - data bytea NOT NULL, - height bigint NOT NULL -); - - --- --- Name: TABLE queue_data; Type: COMMENT; Schema: btc; Owner: - --- - -COMMENT ON TABLE btc.queue_data IS '@name BtcQueueData'; - - --- --- Name: queue_data_id_seq; Type: SEQUENCE; Schema: btc; Owner: - --- - -CREATE SEQUENCE btc.queue_data_id_seq - AS integer - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - --- --- Name: queue_data_id_seq; Type: SEQUENCE OWNED BY; Schema: btc; Owner: - --- - -ALTER SEQUENCE btc.queue_data_id_seq OWNED BY btc.queue_data.id; - - -- -- Name: transaction_cids; Type: TABLE; Schema: btc; Owner: - -- @@ -133,6 +96,7 @@ CREATE TABLE btc.transaction_cids ( index integer NOT NULL, tx_hash character varying(66) NOT NULL, cid text NOT NULL, + mh_key text NOT NULL, segwit boolean NOT NULL, witness_hash character varying(66) ); @@ -246,15 +210,16 @@ CREATE TABLE eth.header_cids ( block_hash character varying(66) NOT NULL, parent_hash character varying(66) NOT NULL, cid text NOT NULL, + mh_key text NOT NULL, td numeric NOT NULL, node_id integer NOT NULL, reward numeric NOT NULL, - state_root character varying(66), - tx_root character varying(66), - receipt_root character varying(66), - uncle_root character varying(66), - bloom bytea, - "timestamp" numeric, + state_root character varying(66) NOT NULL, + tx_root character varying(66) NOT NULL, + receipt_root character varying(66) NOT NULL, + uncle_root character varying(66) NOT NULL, + bloom bytea NOT NULL, + "timestamp" numeric NOT NULL, times_validated integer DEFAULT 1 NOT NULL ); @@ -293,44 +258,6 @@ CREATE SEQUENCE eth.header_cids_id_seq ALTER SEQUENCE eth.header_cids_id_seq OWNED BY eth.header_cids.id; --- --- Name: queue_data; Type: TABLE; Schema: eth; Owner: - --- - -CREATE TABLE eth.queue_data ( - id integer NOT NULL, - data bytea NOT NULL, - height bigint NOT NULL -); - - --- --- Name: TABLE queue_data; Type: COMMENT; Schema: eth; Owner: - --- - -COMMENT ON TABLE eth.queue_data IS '@name EthQueueData'; - - --- --- Name: queue_data_id_seq; Type: SEQUENCE; Schema: eth; Owner: - --- - -CREATE SEQUENCE eth.queue_data_id_seq - AS integer - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - --- --- Name: queue_data_id_seq; Type: SEQUENCE OWNED BY; Schema: eth; Owner: - --- - -ALTER SEQUENCE eth.queue_data_id_seq OWNED BY eth.queue_data.id; - - -- -- Name: receipt_cids; Type: TABLE; Schema: eth; Owner: - -- @@ -339,13 +266,14 @@ CREATE TABLE eth.receipt_cids ( id integer NOT NULL, tx_id integer NOT NULL, cid text NOT NULL, + mh_key text NOT NULL, contract character varying(66), + contract_hash character varying(66), topic0s character varying(66)[], topic1s character varying(66)[], topic2s character varying(66)[], topic3s character varying(66)[], - log_contracts character varying(66)[], - contract_hash character varying(66) + log_contracts character varying(66)[] ); @@ -412,6 +340,7 @@ CREATE TABLE eth.state_cids ( header_id integer NOT NULL, state_leaf_key character varying(66), cid text NOT NULL, + mh_key text NOT NULL, state_path bytea, node_type integer, diff boolean DEFAULT false NOT NULL @@ -447,8 +376,9 @@ CREATE TABLE eth.storage_cids ( state_id integer NOT NULL, storage_leaf_key character varying(66), cid text NOT NULL, + mh_key text NOT NULL, storage_path bytea, - node_type integer, + node_type integer NOT NULL, diff boolean DEFAULT false NOT NULL ); @@ -483,6 +413,7 @@ CREATE TABLE eth.transaction_cids ( tx_hash character varying(66) NOT NULL, index integer NOT NULL, cid text NOT NULL, + mh_key text NOT NULL, dst character varying(66) NOT NULL, src character varying(66) NOT NULL ); @@ -525,6 +456,7 @@ CREATE TABLE eth.uncle_cids ( block_hash character varying(66) NOT NULL, parent_hash character varying(66) NOT NULL, cid text NOT NULL, + mh_key text NOT NULL, reward numeric NOT NULL ); @@ -645,13 +577,6 @@ ALTER SEQUENCE public.nodes_id_seq OWNED BY public.nodes.id; ALTER TABLE ONLY btc.header_cids ALTER COLUMN id SET DEFAULT nextval('btc.header_cids_id_seq'::regclass); --- --- Name: queue_data id; Type: DEFAULT; Schema: btc; Owner: - --- - -ALTER TABLE ONLY btc.queue_data ALTER COLUMN id SET DEFAULT nextval('btc.queue_data_id_seq'::regclass); - - -- -- Name: transaction_cids id; Type: DEFAULT; Schema: btc; Owner: - -- @@ -680,13 +605,6 @@ ALTER TABLE ONLY btc.tx_outputs ALTER COLUMN id SET DEFAULT nextval('btc.tx_outp ALTER TABLE ONLY eth.header_cids ALTER COLUMN id SET DEFAULT nextval('eth.header_cids_id_seq'::regclass); --- --- Name: queue_data id; Type: DEFAULT; Schema: eth; Owner: - --- - -ALTER TABLE ONLY eth.queue_data ALTER COLUMN id SET DEFAULT nextval('eth.queue_data_id_seq'::regclass); - - -- -- Name: receipt_cids id; Type: DEFAULT; Schema: eth; Owner: - -- @@ -759,22 +677,6 @@ ALTER TABLE ONLY btc.header_cids ADD CONSTRAINT header_cids_pkey PRIMARY KEY (id); --- --- Name: queue_data queue_data_height_key; Type: CONSTRAINT; Schema: btc; Owner: - --- - -ALTER TABLE ONLY btc.queue_data - ADD CONSTRAINT queue_data_height_key UNIQUE (height); - - --- --- Name: queue_data queue_data_pkey; Type: CONSTRAINT; Schema: btc; Owner: - --- - -ALTER TABLE ONLY btc.queue_data - ADD CONSTRAINT queue_data_pkey PRIMARY KEY (id); - - -- -- Name: transaction_cids transaction_cids_pkey; Type: CONSTRAINT; Schema: btc; Owner: - -- @@ -839,22 +741,6 @@ ALTER TABLE ONLY eth.header_cids ADD CONSTRAINT header_cids_pkey PRIMARY KEY (id); --- --- Name: queue_data queue_data_height_key; Type: CONSTRAINT; Schema: eth; Owner: - --- - -ALTER TABLE ONLY eth.queue_data - ADD CONSTRAINT queue_data_height_key UNIQUE (height); - - --- --- Name: queue_data queue_data_pkey; Type: CONSTRAINT; Schema: eth; Owner: - --- - -ALTER TABLE ONLY eth.queue_data - ADD CONSTRAINT queue_data_pkey PRIMARY KEY (id); - - -- -- Name: receipt_cids receipt_cids_pkey; Type: CONSTRAINT; Schema: eth; Owner: - -- @@ -983,6 +869,14 @@ ALTER TABLE ONLY public.nodes ADD CONSTRAINT nodes_pkey PRIMARY KEY (id); +-- +-- Name: header_cids header_cids_mh_key_fkey; Type: FK CONSTRAINT; Schema: btc; Owner: - +-- + +ALTER TABLE ONLY btc.header_cids + ADD CONSTRAINT header_cids_mh_key_fkey FOREIGN KEY (mh_key) REFERENCES public.blocks(key) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED; + + -- -- Name: header_cids header_cids_node_id_fkey; Type: FK CONSTRAINT; Schema: btc; Owner: - -- @@ -999,6 +893,14 @@ ALTER TABLE ONLY btc.transaction_cids ADD CONSTRAINT transaction_cids_header_id_fkey FOREIGN KEY (header_id) REFERENCES btc.header_cids(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED; +-- +-- Name: transaction_cids transaction_cids_mh_key_fkey; Type: FK CONSTRAINT; Schema: btc; Owner: - +-- + +ALTER TABLE ONLY btc.transaction_cids + ADD CONSTRAINT transaction_cids_mh_key_fkey FOREIGN KEY (mh_key) REFERENCES public.blocks(key) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED; + + -- -- Name: tx_inputs tx_inputs_tx_id_fkey; Type: FK CONSTRAINT; Schema: btc; Owner: - -- @@ -1015,6 +917,14 @@ ALTER TABLE ONLY btc.tx_outputs ADD CONSTRAINT tx_outputs_tx_id_fkey FOREIGN KEY (tx_id) REFERENCES btc.transaction_cids(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED; +-- +-- Name: header_cids header_cids_mh_key_fkey; Type: FK CONSTRAINT; Schema: eth; Owner: - +-- + +ALTER TABLE ONLY eth.header_cids + ADD CONSTRAINT header_cids_mh_key_fkey FOREIGN KEY (mh_key) REFERENCES public.blocks(key) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED; + + -- -- Name: header_cids header_cids_node_id_fkey; Type: FK CONSTRAINT; Schema: eth; Owner: - -- @@ -1023,6 +933,14 @@ ALTER TABLE ONLY eth.header_cids ADD CONSTRAINT header_cids_node_id_fkey FOREIGN KEY (node_id) REFERENCES public.nodes(id) ON DELETE CASCADE; +-- +-- Name: receipt_cids receipt_cids_mh_key_fkey; Type: FK CONSTRAINT; Schema: eth; Owner: - +-- + +ALTER TABLE ONLY eth.receipt_cids + ADD CONSTRAINT receipt_cids_mh_key_fkey FOREIGN KEY (mh_key) REFERENCES public.blocks(key) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED; + + -- -- Name: receipt_cids receipt_cids_tx_id_fkey; Type: FK CONSTRAINT; Schema: eth; Owner: - -- @@ -1047,6 +965,22 @@ ALTER TABLE ONLY eth.state_cids ADD CONSTRAINT state_cids_header_id_fkey FOREIGN KEY (header_id) REFERENCES eth.header_cids(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED; +-- +-- Name: state_cids state_cids_mh_key_fkey; Type: FK CONSTRAINT; Schema: eth; Owner: - +-- + +ALTER TABLE ONLY eth.state_cids + ADD CONSTRAINT state_cids_mh_key_fkey FOREIGN KEY (mh_key) REFERENCES public.blocks(key) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED; + + +-- +-- Name: storage_cids storage_cids_mh_key_fkey; Type: FK CONSTRAINT; Schema: eth; Owner: - +-- + +ALTER TABLE ONLY eth.storage_cids + ADD CONSTRAINT storage_cids_mh_key_fkey FOREIGN KEY (mh_key) REFERENCES public.blocks(key) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED; + + -- -- Name: storage_cids storage_cids_state_id_fkey; Type: FK CONSTRAINT; Schema: eth; Owner: - -- @@ -1063,6 +997,14 @@ ALTER TABLE ONLY eth.transaction_cids ADD CONSTRAINT transaction_cids_header_id_fkey FOREIGN KEY (header_id) REFERENCES eth.header_cids(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED; +-- +-- Name: transaction_cids transaction_cids_mh_key_fkey; Type: FK CONSTRAINT; Schema: eth; Owner: - +-- + +ALTER TABLE ONLY eth.transaction_cids + ADD CONSTRAINT transaction_cids_mh_key_fkey FOREIGN KEY (mh_key) REFERENCES public.blocks(key) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED; + + -- -- Name: uncle_cids uncle_cids_header_id_fkey; Type: FK CONSTRAINT; Schema: eth; Owner: - -- @@ -1071,6 +1013,14 @@ ALTER TABLE ONLY eth.uncle_cids ADD CONSTRAINT uncle_cids_header_id_fkey FOREIGN KEY (header_id) REFERENCES eth.header_cids(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED; +-- +-- Name: uncle_cids uncle_cids_mh_key_fkey; Type: FK CONSTRAINT; Schema: eth; Owner: - +-- + +ALTER TABLE ONLY eth.uncle_cids + ADD CONSTRAINT uncle_cids_mh_key_fkey FOREIGN KEY (mh_key) REFERENCES public.blocks(key) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED; + + -- -- PostgreSQL database dump complete --