From 8e644ebdf4b5890526872096b9c47e807225a756 Mon Sep 17 00:00:00 2001 From: i-norden Date: Mon, 15 Nov 2021 11:08:56 -0600 Subject: [PATCH] set of migrations for the parallel batch processing --- .../00001_create_ipfs_blocks_table.sql | 8 +++++++ .../00002_create_nodes_table.sql | 13 +++++++++++ .../00003_create_eth_schema.sql | 5 +++++ .../00004_create_eth_header_cids_table.sql | 22 +++++++++++++++++++ .../00005_create_eth_uncle_cids_table.sql | 12 ++++++++++ ...0006_create_eth_transaction_cids_table.sql | 15 +++++++++++++ .../00007_create_eth_receipt_cids_table.sql | 14 ++++++++++++ .../00008_create_eth_state_cids_table.sql | 13 +++++++++++ .../00009_create_eth_storage_cids_table.sql | 14 ++++++++++++ .../00010_create_eth_state_accouts_table.sql | 12 ++++++++++ ..._create_eth_access_list_elements_table.sql | 10 +++++++++ .../00012_create_eth_log_cids_table.sql | 17 ++++++++++++++ 12 files changed, 155 insertions(+) create mode 100644 db/batch_process_migrations/00001_create_ipfs_blocks_table.sql create mode 100644 db/batch_process_migrations/00002_create_nodes_table.sql create mode 100644 db/batch_process_migrations/00003_create_eth_schema.sql create mode 100644 db/batch_process_migrations/00004_create_eth_header_cids_table.sql create mode 100644 db/batch_process_migrations/00005_create_eth_uncle_cids_table.sql create mode 100644 db/batch_process_migrations/00006_create_eth_transaction_cids_table.sql create mode 100644 db/batch_process_migrations/00007_create_eth_receipt_cids_table.sql create mode 100644 db/batch_process_migrations/00008_create_eth_state_cids_table.sql create mode 100644 db/batch_process_migrations/00009_create_eth_storage_cids_table.sql create mode 100644 db/batch_process_migrations/00010_create_eth_state_accouts_table.sql create mode 100644 db/batch_process_migrations/00011_create_eth_access_list_elements_table.sql create mode 100644 db/batch_process_migrations/00012_create_eth_log_cids_table.sql diff --git a/db/batch_process_migrations/00001_create_ipfs_blocks_table.sql b/db/batch_process_migrations/00001_create_ipfs_blocks_table.sql new file mode 100644 index 0000000..4b017bc --- /dev/null +++ b/db/batch_process_migrations/00001_create_ipfs_blocks_table.sql @@ -0,0 +1,8 @@ +-- +goose Up +CREATE TABLE IF NOT EXISTS public.blocks ( + key TEXT PRIMARY KEY, + data BYTEA NOT NULL +); + +-- +goose Down +DROP TABLE public.blocks; diff --git a/db/batch_process_migrations/00002_create_nodes_table.sql b/db/batch_process_migrations/00002_create_nodes_table.sql new file mode 100644 index 0000000..e70c144 --- /dev/null +++ b/db/batch_process_migrations/00002_create_nodes_table.sql @@ -0,0 +1,13 @@ +-- +goose Up +CREATE TABLE nodes ( + id SERIAL PRIMARY KEY, + client_name VARCHAR, + genesis_block VARCHAR(66), + network_id VARCHAR, + node_id VARCHAR(128), + chain_id INTEGER DEFAULT 1, + CONSTRAINT node_uc UNIQUE (genesis_block, network_id, node_id, chain_id) +); + +-- +goose Down +DROP TABLE nodes; diff --git a/db/batch_process_migrations/00003_create_eth_schema.sql b/db/batch_process_migrations/00003_create_eth_schema.sql new file mode 100644 index 0000000..84d6f4b --- /dev/null +++ b/db/batch_process_migrations/00003_create_eth_schema.sql @@ -0,0 +1,5 @@ +-- +goose Up +CREATE SCHEMA eth; + +-- +goose Down +DROP SCHEMA eth; \ No newline at end of file diff --git a/db/batch_process_migrations/00004_create_eth_header_cids_table.sql b/db/batch_process_migrations/00004_create_eth_header_cids_table.sql new file mode 100644 index 0000000..f54c834 --- /dev/null +++ b/db/batch_process_migrations/00004_create_eth_header_cids_table.sql @@ -0,0 +1,22 @@ +-- +goose Up +CREATE TABLE eth.header_cids ( + block_hash VARCHAR(66) NOT NULL, + block_number BIGINT NOT NULL, + parent_hash VARCHAR(66) NOT NULL, + cid TEXT NOT NULL, + mh_key TEXT NOT NULL, + 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, + base_fee BIGINT +); + +-- +goose Down +DROP TABLE eth.header_cids; diff --git a/db/batch_process_migrations/00005_create_eth_uncle_cids_table.sql b/db/batch_process_migrations/00005_create_eth_uncle_cids_table.sql new file mode 100644 index 0000000..434b594 --- /dev/null +++ b/db/batch_process_migrations/00005_create_eth_uncle_cids_table.sql @@ -0,0 +1,12 @@ +-- +goose Up +CREATE TABLE eth.uncle_cids ( + block_hash VARCHAR(66) NOT NULL, + header_id VARCHAR(66) NOT NULL, + parent_hash VARCHAR(66) NOT NULL, + cid TEXT NOT NULL, + mh_key TEXT NOT NULL, + reward NUMERIC NOT NULL +); + +-- +goose Down +DROP TABLE eth.uncle_cids; diff --git a/db/batch_process_migrations/00006_create_eth_transaction_cids_table.sql b/db/batch_process_migrations/00006_create_eth_transaction_cids_table.sql new file mode 100644 index 0000000..3edf232 --- /dev/null +++ b/db/batch_process_migrations/00006_create_eth_transaction_cids_table.sql @@ -0,0 +1,15 @@ +-- +goose Up +CREATE TABLE eth.transaction_cids ( + tx_hash VARCHAR(66) NOT NULL, + header_id VARCHAR(66) NOT NULL, + index INTEGER NOT NULL, + cid TEXT NOT NULL, + mh_key TEXT NOT NULL, + dst VARCHAR(66) NOT NULL, + src VARCHAR(66) NOT NULL, + tx_data BYTEA, + tx_type INTEGER +); + +-- +goose Down +DROP TABLE eth.transaction_cids; diff --git a/db/batch_process_migrations/00007_create_eth_receipt_cids_table.sql b/db/batch_process_migrations/00007_create_eth_receipt_cids_table.sql new file mode 100644 index 0000000..84f1d1c --- /dev/null +++ b/db/batch_process_migrations/00007_create_eth_receipt_cids_table.sql @@ -0,0 +1,14 @@ +-- +goose Up +CREATE TABLE eth.receipt_cids ( + tx_id VARCHAR(66) NOT NULL, + leaf_cid TEXT NOT NULL, + leaf_mh_key TEXT NOT NULL, + contract VARCHAR(66), + contract_hash VARCHAR(66), + post_state VARCHAR(66), + post_status INTEGER, + log_root VARCHAR(66) +); + +-- +goose Down +DROP TABLE eth.receipt_cids; diff --git a/db/batch_process_migrations/00008_create_eth_state_cids_table.sql b/db/batch_process_migrations/00008_create_eth_state_cids_table.sql new file mode 100644 index 0000000..8417bd5 --- /dev/null +++ b/db/batch_process_migrations/00008_create_eth_state_cids_table.sql @@ -0,0 +1,13 @@ +-- +goose Up +CREATE TABLE eth.state_cids ( + header_id VARCHAR(66) NOT NULL, + state_leaf_key VARCHAR(66), + cid TEXT NOT NULL, + mh_key TEXT NOT NULL, + state_path BYTEA NOT NULL, + node_type INTEGER NOT NULL, + diff BOOLEAN NOT NULL DEFAULT FALSE +); + +-- +goose Down +DROP TABLE eth.state_cids; diff --git a/db/batch_process_migrations/00009_create_eth_storage_cids_table.sql b/db/batch_process_migrations/00009_create_eth_storage_cids_table.sql new file mode 100644 index 0000000..dbe60ab --- /dev/null +++ b/db/batch_process_migrations/00009_create_eth_storage_cids_table.sql @@ -0,0 +1,14 @@ +-- +goose Up +CREATE TABLE eth.storage_cids ( + header_id VARCHAR(66) NOT NULL, + state_path BYTEA NOT NULL, + storage_leaf_key VARCHAR(66), + cid TEXT NOT NULL, + mh_key TEXT NOT NULL, + storage_path BYTEA NOT NULL, + node_type INTEGER NOT NULL, + diff BOOLEAN NOT NULL DEFAULT FALSE +); + +-- +goose Down +DROP TABLE eth.storage_cids; diff --git a/db/batch_process_migrations/00010_create_eth_state_accouts_table.sql b/db/batch_process_migrations/00010_create_eth_state_accouts_table.sql new file mode 100644 index 0000000..c508b83 --- /dev/null +++ b/db/batch_process_migrations/00010_create_eth_state_accouts_table.sql @@ -0,0 +1,12 @@ +-- +goose Up +CREATE TABLE eth.state_accounts ( + header_id VARCHAR(66) NOT NULL, + state_path BYTEA NOT NULL, + balance NUMERIC NOT NULL, + nonce INTEGER NOT NULL, + code_hash BYTEA NOT NULL, + storage_root VARCHAR(66) NOT NULL +); + +-- +goose Down +DROP TABLE eth.state_accounts; diff --git a/db/batch_process_migrations/00011_create_eth_access_list_elements_table.sql b/db/batch_process_migrations/00011_create_eth_access_list_elements_table.sql new file mode 100644 index 0000000..c5cf02d --- /dev/null +++ b/db/batch_process_migrations/00011_create_eth_access_list_elements_table.sql @@ -0,0 +1,10 @@ +-- +goose Up +CREATE TABLE eth.access_list_element ( + tx_id VARCHAR(66) NOT NULL, + index INTEGER NOT NULL, + address VARCHAR(66), + storage_keys VARCHAR(66)[] +); + +-- +goose Down +DROP TABLE eth.access_list_element; diff --git a/db/batch_process_migrations/00012_create_eth_log_cids_table.sql b/db/batch_process_migrations/00012_create_eth_log_cids_table.sql new file mode 100644 index 0000000..bf567bd --- /dev/null +++ b/db/batch_process_migrations/00012_create_eth_log_cids_table.sql @@ -0,0 +1,17 @@ +-- +goose Up +CREATE TABLE eth.log_cids ( + rct_id VARCHAR(66) NOT NULL, + leaf_cid TEXT NOT NULL, + leaf_mh_key TEXT NOT NULL, + address VARCHAR(66) NOT NULL, + log_data BYTEA, + index INTEGER NOT NULL, + topic0 VARCHAR(66), + topic1 VARCHAR(66), + topic2 VARCHAR(66), + topic3 VARCHAR(66) +); + +-- +goose Down +-- log indexes +DROP TABLE eth.log_cids;