From 9e7e0377a5a68c329abf458ff6eed13f60cc086a Mon Sep 17 00:00:00 2001 From: i-norden Date: Wed, 26 Jan 2022 13:01:41 -0600 Subject: [PATCH] split pk application into two parts --- db/migrations/00014_create_cid_indexes.sql | 12 ++--- .../00023_create_pk_constraints_part1.sql | 25 ++++++++++ ... => 00024_create_pk_constraints_part2.sql} | 50 +++++-------------- ...ogged.sql => 00025_make_tables_logged.sql} | 0 ...ions.sql => 00026_create_fk_relations.sql} | 0 ...=> 00027_create_postgraphile_comments.sql} | 0 ...dexes.sql => 00028_create_cid_indexes.sql} | 12 ++--- ....sql => 00029_create_stored_functions.sql} | 0 ...=> 00030_create_postgraphile_triggers.sql} | 0 9 files changed, 50 insertions(+), 49 deletions(-) create mode 100644 db/post_batch_processing_migrations/00023_create_pk_constraints_part1.sql rename db/post_batch_processing_migrations/{00023_create_pk_constraints.sql => 00024_create_pk_constraints_part2.sql} (62%) rename db/post_batch_processing_migrations/{00024_make_tables_logged.sql => 00025_make_tables_logged.sql} (100%) rename db/post_batch_processing_migrations/{00025_create_fk_relations.sql => 00026_create_fk_relations.sql} (100%) rename db/post_batch_processing_migrations/{00026_create_postgraphile_comments.sql => 00027_create_postgraphile_comments.sql} (100%) rename db/post_batch_processing_migrations/{00027_create_cid_indexes.sql => 00028_create_cid_indexes.sql} (89%) rename db/post_batch_processing_migrations/{00028_create_stored_functions.sql => 00029_create_stored_functions.sql} (100%) rename db/post_batch_processing_migrations/{00029_create_postgraphile_triggers.sql => 00030_create_postgraphile_triggers.sql} (100%) diff --git a/db/migrations/00014_create_cid_indexes.sql b/db/migrations/00014_create_cid_indexes.sql index 3759801..620808c 100644 --- a/db/migrations/00014_create_cid_indexes.sql +++ b/db/migrations/00014_create_cid_indexes.sql @@ -1,8 +1,8 @@ -- +goose Up -- header indexes 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 INDEX header_mh_index ON eth.header_cids USING btree (mh_key); +CREATE UNIQUE INDEX header_cid_index ON eth.header_cids USING btree (cid); +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 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 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 INDEX tx_mh_index ON eth.transaction_cids USING btree (mh_key); +CREATE UNIQUE INDEX tx_cid_index ON eth.transaction_cids USING btree (cid); +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_src_index ON eth.transaction_cids USING btree (src); -- receipt indexes -CREATE 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_cid_index ON eth.receipt_cids USING btree (leaf_cid); +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_hash_index ON eth.receipt_cids USING btree (contract_hash); diff --git a/db/post_batch_processing_migrations/00023_create_pk_constraints_part1.sql b/db/post_batch_processing_migrations/00023_create_pk_constraints_part1.sql new file mode 100644 index 0000000..700d273 --- /dev/null +++ b/db/post_batch_processing_migrations/00023_create_pk_constraints_part1.sql @@ -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; diff --git a/db/post_batch_processing_migrations/00023_create_pk_constraints.sql b/db/post_batch_processing_migrations/00024_create_pk_constraints_part2.sql similarity index 62% rename from db/post_batch_processing_migrations/00023_create_pk_constraints.sql rename to db/post_batch_processing_migrations/00024_create_pk_constraints_part2.sql index f574f21..ba40f0f 100644 --- a/db/post_batch_processing_migrations/00023_create_pk_constraints.sql +++ b/db/post_batch_processing_migrations/00024_create_pk_constraints_part2.sql @@ -1,16 +1,4 @@ -- +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 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); -- +goose Down -ALTER TABLE public.nodes -DROP CONSTRAINT pk_public_nodes; - -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.state_accounts +DROP CONSTRAINT pk_eth_state_accounts; ALTER TABLE eth.storage_cids DROP CONSTRAINT pk_eth_storage_cids; -ALTER TABLE eth.state_accounts -DROP CONSTRAINT pk_eth_state_accounts; +ALTER TABLE eth.state_cids +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; diff --git a/db/post_batch_processing_migrations/00024_make_tables_logged.sql b/db/post_batch_processing_migrations/00025_make_tables_logged.sql similarity index 100% rename from db/post_batch_processing_migrations/00024_make_tables_logged.sql rename to db/post_batch_processing_migrations/00025_make_tables_logged.sql diff --git a/db/post_batch_processing_migrations/00025_create_fk_relations.sql b/db/post_batch_processing_migrations/00026_create_fk_relations.sql similarity index 100% rename from db/post_batch_processing_migrations/00025_create_fk_relations.sql rename to db/post_batch_processing_migrations/00026_create_fk_relations.sql diff --git a/db/post_batch_processing_migrations/00026_create_postgraphile_comments.sql b/db/post_batch_processing_migrations/00027_create_postgraphile_comments.sql similarity index 100% rename from db/post_batch_processing_migrations/00026_create_postgraphile_comments.sql rename to db/post_batch_processing_migrations/00027_create_postgraphile_comments.sql diff --git a/db/post_batch_processing_migrations/00027_create_cid_indexes.sql b/db/post_batch_processing_migrations/00028_create_cid_indexes.sql similarity index 89% rename from db/post_batch_processing_migrations/00027_create_cid_indexes.sql rename to db/post_batch_processing_migrations/00028_create_cid_indexes.sql index 304d770..ef409de 100644 --- a/db/post_batch_processing_migrations/00027_create_cid_indexes.sql +++ b/db/post_batch_processing_migrations/00028_create_cid_indexes.sql @@ -1,8 +1,8 @@ -- +goose Up -- header indexes 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 INDEX header_mh_index ON eth.header_cids USING btree (mh_key); +CREATE UNIQUE INDEX header_cid_index ON eth.header_cids USING btree (cid); +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 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 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 INDEX tx_mh_index ON eth.transaction_cids USING btree (mh_key); +CREATE UNIQUE INDEX tx_cid_index ON eth.transaction_cids USING btree (cid); +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_src_index ON eth.transaction_cids USING btree (src); -- receipt indexes -CREATE 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_cid_index ON eth.receipt_cids USING btree (leaf_cid); +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_hash_index ON eth.receipt_cids USING btree (contract_hash); diff --git a/db/post_batch_processing_migrations/00028_create_stored_functions.sql b/db/post_batch_processing_migrations/00029_create_stored_functions.sql similarity index 100% rename from db/post_batch_processing_migrations/00028_create_stored_functions.sql rename to db/post_batch_processing_migrations/00029_create_stored_functions.sql diff --git a/db/post_batch_processing_migrations/00029_create_postgraphile_triggers.sql b/db/post_batch_processing_migrations/00030_create_postgraphile_triggers.sql similarity index 100% rename from db/post_batch_processing_migrations/00029_create_postgraphile_triggers.sql rename to db/post_batch_processing_migrations/00030_create_postgraphile_triggers.sql