split pk application into two parts

This commit is contained in:
i-norden 2022-01-26 13:01:41 -06:00
parent 36de257357
commit 9e7e0377a5
9 changed files with 50 additions and 49 deletions

View File

@ -1,8 +1,8 @@
-- +goose Up -- +goose Up
-- header indexes -- header indexes
CREATE INDEX block_number_index ON eth.header_cids USING brin (block_number); CREATE INDEX block_number_index ON eth.header_cids USING brin (block_number);
CREATE INDEX header_cid_index ON eth.header_cids USING btree (cid); CREATE UNIQUE INDEX header_cid_index ON eth.header_cids USING btree (cid);
CREATE INDEX header_mh_index ON eth.header_cids USING btree (mh_key); CREATE UNIQUE INDEX header_mh_index ON eth.header_cids USING btree (mh_key);
CREATE INDEX state_root_index ON eth.header_cids USING btree (state_root); CREATE INDEX state_root_index ON eth.header_cids USING btree (state_root);
CREATE INDEX timestamp_index ON eth.header_cids USING brin (timestamp); CREATE INDEX timestamp_index ON eth.header_cids USING brin (timestamp);
@ -11,14 +11,14 @@ CREATE INDEX uncle_header_id_index ON eth.uncle_cids USING btree (header_id);
-- transaction indexes -- transaction indexes
CREATE INDEX tx_header_id_index ON eth.transaction_cids USING btree (header_id); CREATE INDEX tx_header_id_index ON eth.transaction_cids USING btree (header_id);
CREATE INDEX tx_cid_index ON eth.transaction_cids USING btree (cid); CREATE UNIQUE INDEX tx_cid_index ON eth.transaction_cids USING btree (cid);
CREATE INDEX tx_mh_index ON eth.transaction_cids USING btree (mh_key); CREATE UNIQUE INDEX tx_mh_index ON eth.transaction_cids USING btree (mh_key);
CREATE INDEX tx_dst_index ON eth.transaction_cids USING btree (dst); CREATE INDEX tx_dst_index ON eth.transaction_cids USING btree (dst);
CREATE INDEX tx_src_index ON eth.transaction_cids USING btree (src); CREATE INDEX tx_src_index ON eth.transaction_cids USING btree (src);
-- receipt indexes -- receipt indexes
CREATE INDEX rct_leaf_cid_index ON eth.receipt_cids USING btree (leaf_cid); CREATE UNIQUE INDEX rct_leaf_cid_index ON eth.receipt_cids USING btree (leaf_cid);
CREATE INDEX rct_leaf_mh_index ON eth.receipt_cids USING btree (leaf_mh_key); CREATE UNIQUE INDEX rct_leaf_mh_index ON eth.receipt_cids USING btree (leaf_mh_key);
CREATE INDEX rct_contract_index ON eth.receipt_cids USING btree (contract); CREATE INDEX rct_contract_index ON eth.receipt_cids USING btree (contract);
CREATE INDEX rct_contract_hash_index ON eth.receipt_cids USING btree (contract_hash); CREATE INDEX rct_contract_hash_index ON eth.receipt_cids USING btree (contract_hash);

View File

@ -0,0 +1,25 @@
-- +goose Up
ALTER TABLE public.nodes
ADD CONSTRAINT pk_public_nodes PRIMARY KEY (node_id);
ALTER TABLE eth.header_cids
ADD CONSTRAINT pk_eth_header_cids PRIMARY KEY (block_hash);
ALTER TABLE eth.uncle_cids
ADD CONSTRAINT pk_eth_uncle_cids PRIMARY KEY (block_hash);
ALTER TABLE eth.transaction_cids
ADD CONSTRAINT pk_eth_transaction_cids PRIMARY KEY (tx_hash);
-- +goose Down
ALTER TABLE eth.transaction_cids
DROP CONSTRAINT pk_eth_transaction_cids;
ALTER TABLE eth.uncle_cids
DROP CONSTRAINT pk_eth_uncle_cids;
ALTER TABLE eth.header_cids
DROP CONSTRAINT pk_eth_header_cids;
ALTER TABLE public.nodes
DROP CONSTRAINT pk_public_nodes;

View File

@ -1,16 +1,4 @@
-- +goose Up -- +goose Up
ALTER TABLE public.nodes
ADD CONSTRAINT pk_public_nodes PRIMARY KEY (node_id);
ALTER TABLE eth.header_cids
ADD CONSTRAINT pk_eth_header_cids PRIMARY KEY (block_hash);
ALTER TABLE eth.uncle_cids
ADD CONSTRAINT pk_eth_uncle_cids PRIMARY KEY (block_hash);
ALTER TABLE eth.transaction_cids
ADD CONSTRAINT pk_eth_transaction_cids PRIMARY KEY (tx_hash);
ALTER TABLE eth.receipt_cids ALTER TABLE eth.receipt_cids
ADD CONSTRAINT pk_eth_receipt_cids PRIMARY KEY (tx_id); ADD CONSTRAINT pk_eth_receipt_cids PRIMARY KEY (tx_id);
@ -30,32 +18,20 @@ ALTER TABLE eth.state_accounts
ADD CONSTRAINT pk_eth_state_accounts PRIMARY KEY (header_id, state_path); ADD CONSTRAINT pk_eth_state_accounts PRIMARY KEY (header_id, state_path);
-- +goose Down -- +goose Down
ALTER TABLE public.nodes ALTER TABLE eth.state_accounts
DROP CONSTRAINT pk_public_nodes; DROP CONSTRAINT pk_eth_state_accounts;
ALTER TABLE eth.header_cids
DROP CONSTRAINT pk_eth_header_cids;
ALTER TABLE eth.uncle_cids
DROP CONSTRAINT pk_eth_uncle_cids;
ALTER TABLE eth.transaction_cids
DROP CONSTRAINT pk_eth_transaction_cids;
ALTER TABLE eth.receipt_cids
DROP CONSTRAINT pk_eth_receipt_cids;
ALTER TABLE eth.access_list_elements
DROP CONSTRAINT pk_eth_access_list_elements;
ALTER TABLE eth.log_cids
DROP CONSTRAINT pk_eth_log_cids;
ALTER TABLE eth.state_cids
DROP CONSTRAINT pk_eth_state_cids;
ALTER TABLE eth.storage_cids ALTER TABLE eth.storage_cids
DROP CONSTRAINT pk_eth_storage_cids; DROP CONSTRAINT pk_eth_storage_cids;
ALTER TABLE eth.state_accounts ALTER TABLE eth.state_cids
DROP CONSTRAINT pk_eth_state_accounts; DROP CONSTRAINT pk_eth_state_cids;
ALTER TABLE eth.log_cids
DROP CONSTRAINT pk_eth_log_cids;
ALTER TABLE eth.access_list_elements
DROP CONSTRAINT pk_eth_access_list_elements;
ALTER TABLE eth.receipt_cids
DROP CONSTRAINT pk_eth_receipt_cids;

View File

@ -1,8 +1,8 @@
-- +goose Up -- +goose Up
-- header indexes -- header indexes
CREATE INDEX block_number_index ON eth.header_cids USING brin (block_number); CREATE INDEX block_number_index ON eth.header_cids USING brin (block_number);
CREATE INDEX header_cid_index ON eth.header_cids USING btree (cid); CREATE UNIQUE INDEX header_cid_index ON eth.header_cids USING btree (cid);
CREATE INDEX header_mh_index ON eth.header_cids USING btree (mh_key); CREATE UNIQUE INDEX header_mh_index ON eth.header_cids USING btree (mh_key);
CREATE INDEX state_root_index ON eth.header_cids USING btree (state_root); CREATE INDEX state_root_index ON eth.header_cids USING btree (state_root);
CREATE INDEX timestamp_index ON eth.header_cids USING brin (timestamp); CREATE INDEX timestamp_index ON eth.header_cids USING brin (timestamp);
@ -11,14 +11,14 @@ CREATE INDEX uncle_header_id_index ON eth.uncle_cids USING btree (header_id);
-- transaction indexes -- transaction indexes
CREATE INDEX tx_header_id_index ON eth.transaction_cids USING btree (header_id); CREATE INDEX tx_header_id_index ON eth.transaction_cids USING btree (header_id);
CREATE INDEX tx_cid_index ON eth.transaction_cids USING btree (cid); CREATE UNIQUE INDEX tx_cid_index ON eth.transaction_cids USING btree (cid);
CREATE INDEX tx_mh_index ON eth.transaction_cids USING btree (mh_key); CREATE UNIQUE INDEX tx_mh_index ON eth.transaction_cids USING btree (mh_key);
CREATE INDEX tx_dst_index ON eth.transaction_cids USING btree (dst); CREATE INDEX tx_dst_index ON eth.transaction_cids USING btree (dst);
CREATE INDEX tx_src_index ON eth.transaction_cids USING btree (src); CREATE INDEX tx_src_index ON eth.transaction_cids USING btree (src);
-- receipt indexes -- receipt indexes
CREATE INDEX rct_leaf_cid_index ON eth.receipt_cids USING btree (leaf_cid); CREATE UNIQUE INDEX rct_leaf_cid_index ON eth.receipt_cids USING btree (leaf_cid);
CREATE INDEX rct_leaf_mh_index ON eth.receipt_cids USING btree (leaf_mh_key); CREATE UNIQUE INDEX rct_leaf_mh_index ON eth.receipt_cids USING btree (leaf_mh_key);
CREATE INDEX rct_contract_index ON eth.receipt_cids USING btree (contract); CREATE INDEX rct_contract_index ON eth.receipt_cids USING btree (contract);
CREATE INDEX rct_contract_hash_index ON eth.receipt_cids USING btree (contract_hash); CREATE INDEX rct_contract_hash_index ON eth.receipt_cids USING btree (contract_hash);