Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
16e17abb7e | ||
|
|
9e7e0377a5 | ||
|
|
36de257357 | ||
|
|
0710ed1bb1 | ||
|
|
c4254bdff1 | ||
|
|
1088313ab7 | ||
|
|
ffdf0a0d4d | ||
|
|
edabfcc9c9 | ||
|
|
6612edabbe | ||
|
|
ae1a6e9d31 | ||
|
|
35a1ba7218 | ||
|
|
4699385a21 | ||
|
|
a2c98550b7 | ||
|
|
4ad1250ea1 | ||
|
|
3fb695c1e6 | ||
|
|
b5b9950f1d | ||
|
|
858d6ee85a | ||
|
|
d313d4823e | ||
|
|
8b64621f46 | ||
|
|
70d571e03e |
@@ -1,10 +1,14 @@
|
||||
ifndef GOPATH
|
||||
override GOPATH = $(HOME)/go
|
||||
endif
|
||||
|
||||
BIN = $(GOPATH)/bin
|
||||
|
||||
# Tools
|
||||
## Migration tool
|
||||
GOOSE = $(BIN)/goose
|
||||
$(BIN)/goose:
|
||||
go get -u github.com/pressly/goose/cmd/goose
|
||||
GO111MODULE=off go get -u github.com/pressly/goose/cmd/goose
|
||||
|
||||
.PHONY: installtools
|
||||
installtools: | $(GOOSE)
|
||||
@@ -44,12 +48,26 @@ rollback: $(GOOSE) checkdbvars
|
||||
$(GOOSE) -dir db/migrations postgres "$(CONNECT_STRING)" down
|
||||
pg_dump -O -s $(CONNECT_STRING) > schema.sql
|
||||
|
||||
|
||||
## Rollback to a select migration (id/timestamp)
|
||||
.PHONY: rollback_to
|
||||
rollback_to: $(GOOSE) checkmigration checkdbvars
|
||||
$(GOOSE) -dir db/migrations postgres "$(CONNECT_STRING)" down-to "$(MIGRATION)"
|
||||
|
||||
## Rollback pre_batch_set
|
||||
.PHONY: `rollback_pre_batch_set`
|
||||
rollback_pre_batch_set: $(GOOSE) checkdbvars
|
||||
$(GOOSE) -dir db/pre_batch_processing_migrations postgres "$(CONNECT_STRING)" down
|
||||
|
||||
## Rollback post_batch_set
|
||||
.PHONY: rollback_post_batch_set
|
||||
rollback_post_batch_set: $(GOOSE) checkdbvars
|
||||
$(GOOSE) -dir db/post_batch_processing_migrations postgres "$(CONNECT_STRING)" down
|
||||
|
||||
## Apply the next up migration
|
||||
.PHONY: migrate_up_by_one
|
||||
migrate_up_by_one: $(GOOSE) checkdbvars
|
||||
$(GOOSE) -dir db/migrations postgres "$(CONNECT_STRING)" up-by-one
|
||||
|
||||
## Apply all migrations not already run
|
||||
.PHONY: migrate
|
||||
migrate: $(GOOSE) checkdbvars
|
||||
@@ -61,6 +79,11 @@ migrate: $(GOOSE) checkdbvars
|
||||
migrate_pre_batch_set: $(GOOSE) checkdbvars
|
||||
$(GOOSE) -dir db/pre_batch_processing_migrations postgres "$(CONNECT_STRING)" up
|
||||
|
||||
## Apply migrations to be ran after a batch processing, one-by-one
|
||||
.PHONY: migrate_post_batch_set_up_by_one
|
||||
migrate_post_batch_set_up_by_one: $(GOOSE) checkdbvars
|
||||
$(GOOSE) -dir db/post_batch_processing_migrations postgres "$(CONNECT_STRING)" up-by-one
|
||||
|
||||
## Apply migrations to be ran after a batch processing
|
||||
.PHONY: migrate_post_batch_set
|
||||
migrate_post_batch_set: $(GOOSE) checkdbvars
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
-- +goose Up
|
||||
INSERT INTO public.db_version (singleton, version) VALUES (true, 'v0.3.2')
|
||||
ON CONFLICT (singleton) DO UPDATE SET (version, tstamp) = ('v0.3.2', NOW());
|
||||
INSERT INTO public.db_version (singleton, version) VALUES (true, 'v3.0.0')
|
||||
ON CONFLICT (singleton) DO UPDATE SET (version, tstamp) = ('v3.0.0', NOW());
|
||||
|
||||
-- +goose Down
|
||||
DELETE FROM public.db_version WHERE version = 'v0.3.2';
|
||||
DELETE FROM public.db_version WHERE version = 'v3.0.0';
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
-- +goose Up
|
||||
ALTER TABLE public.blocks
|
||||
ADD CONSTRAINT pk_public_blocks PRIMARY KEY (key);
|
||||
|
||||
-- +goose Down
|
||||
ALTER TABLE public.blocks
|
||||
DROP CONSTRAINT pk_public_blocks;
|
||||
@@ -0,0 +1,8 @@
|
||||
-- +goose Up
|
||||
INSERT INTO public.db_version (singleton, version) VALUES (true, 'v3.0.0')
|
||||
ON CONFLICT (singleton) DO UPDATE SET (version, tstamp) = ('v3.0.0', NOW());
|
||||
|
||||
-- +goose Down
|
||||
DELETE FROM public.db_version WHERE version = 'v3.0.0';
|
||||
INSERT INTO public.db_version (singleton, version) VALUES (true, 'v0.3.2')
|
||||
ON CONFLICT (singleton) DO UPDATE SET (version, tstamp) = ('v0.3.2', NOW());
|
||||
@@ -0,0 +1,15 @@
|
||||
-- +goose Up
|
||||
CREATE INDEX log_mh_index ON eth.log_cids USING btree (leaf_mh_key);
|
||||
CREATE INDEX block_number_index ON eth.header_cids USING brin (block_number);
|
||||
CREATE INDEX header_block_hash_index ON eth.header_cids USING btree (block_hash);
|
||||
CREATE INDEX tx_header_id_index ON eth.transaction_cids USING btree (header_id);
|
||||
CREATE INDEX tx_tx_hash_index ON eth.transaction_cids USING btree (tx_hash);
|
||||
CREATE INDEX log_cids_index ON eth.log_cids USING btree (rct_id, index);
|
||||
|
||||
-- +goose Down
|
||||
DROP INDEX eth.log_cids_index;
|
||||
DROP INDEX eth.tx_tx_hash_index;
|
||||
DROP INDEX eth.tx_header_id_index;
|
||||
DROP INDEX eth.header_block_hash_index;
|
||||
DROP INDEX eth.block_number_index;
|
||||
DROP INDEX eth.log_mh_index;
|
||||
@@ -0,0 +1,9 @@
|
||||
-- +goose Up
|
||||
ALTER TABLE eth.log_cids
|
||||
ADD CONSTRAINT fk_log_leaf_mh_key
|
||||
FOREIGN KEY (leaf_mh_key) REFERENCES public.blocks (key)
|
||||
ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED;
|
||||
|
||||
-- +goose Down
|
||||
ALTER TABLE eth.log_cids
|
||||
DROP CONSTRAINT fk_log_leaf_mh_key;
|
||||
@@ -0,0 +1,53 @@
|
||||
-- +goose Up
|
||||
UPDATE pg_index
|
||||
SET indisready=false
|
||||
WHERE indrelid = (
|
||||
SELECT oid
|
||||
FROM pg_class
|
||||
WHERE relname='eth.log_cids'
|
||||
);
|
||||
UPDATE pg_index
|
||||
SET indisready=false
|
||||
WHERE indrelid = (
|
||||
SELECT oid
|
||||
FROM pg_class
|
||||
WHERE relname='eth.transaction_cids'
|
||||
);
|
||||
UPDATE pg_index
|
||||
SET indisready=false
|
||||
WHERE indrelid = (
|
||||
SELECT oid
|
||||
FROM pg_class
|
||||
WHERE relname='eth.header_cids'
|
||||
);
|
||||
|
||||
ALTER TABLE eth.log_cids
|
||||
DROP CONSTRAINT fk_log_leaf_mh_key;
|
||||
|
||||
-- +goose Down
|
||||
ALTER TABLE eth.log_cids
|
||||
ADD CONSTRAINT fk_log_leaf_mh_key
|
||||
FOREIGN KEY (leaf_mh_key) REFERENCES public.blocks (key)
|
||||
ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED;
|
||||
|
||||
UPDATE pg_index
|
||||
SET indisready=true
|
||||
WHERE indrelid = (
|
||||
SELECT oid
|
||||
FROM pg_class
|
||||
WHERE relname='eth.header_cids'
|
||||
);
|
||||
UPDATE pg_index
|
||||
SET indisready=true
|
||||
WHERE indrelid = (
|
||||
SELECT oid
|
||||
FROM pg_class
|
||||
WHERE relname='eth.transaction_cids'
|
||||
);
|
||||
UPDATE pg_index
|
||||
SET indisready=true
|
||||
WHERE indrelid = (
|
||||
SELECT oid
|
||||
FROM pg_class
|
||||
WHERE relname='eth.log_cids'
|
||||
);
|
||||
@@ -0,0 +1,53 @@
|
||||
-- +goose Up
|
||||
UPDATE pg_index
|
||||
SET indisready=true
|
||||
WHERE indrelid = (
|
||||
SELECT oid
|
||||
FROM pg_class
|
||||
WHERE relname='eth.header_cids'
|
||||
);
|
||||
UPDATE pg_index
|
||||
SET indisready=true
|
||||
WHERE indrelid = (
|
||||
SELECT oid
|
||||
FROM pg_class
|
||||
WHERE relname='eth.transaction_cids'
|
||||
);
|
||||
UPDATE pg_index
|
||||
SET indisready=true
|
||||
WHERE indrelid = (
|
||||
SELECT oid
|
||||
FROM pg_class
|
||||
WHERE relname='eth.log_cids'
|
||||
);
|
||||
|
||||
DROP INDEX eth.tx_header_id_index;
|
||||
DROP INDEX eth.block_number_index;
|
||||
DROP INDEX eth.log_mh_index;
|
||||
|
||||
-- +goose Down
|
||||
CREATE INDEX log_mh_index ON eth.log_cids USING btree (leaf_mh_key);
|
||||
CREATE INDEX block_number_index ON eth.header_cids USING brin (block_number);
|
||||
CREATE INDEX tx_header_id_index ON eth.transaction_cids USING btree (header_id);
|
||||
|
||||
UPDATE pg_index
|
||||
SET indisready=false
|
||||
WHERE indrelid = (
|
||||
SELECT oid
|
||||
FROM pg_class
|
||||
WHERE relname='eth.log_cids'
|
||||
);
|
||||
UPDATE pg_index
|
||||
SET indisready=false
|
||||
WHERE indrelid = (
|
||||
SELECT oid
|
||||
FROM pg_class
|
||||
WHERE relname='eth.transaction_cids'
|
||||
);
|
||||
UPDATE pg_index
|
||||
SET indisready=false
|
||||
WHERE indrelid = (
|
||||
SELECT oid
|
||||
FROM pg_class
|
||||
WHERE relname='eth.header_cids'
|
||||
);
|
||||
@@ -0,0 +1,9 @@
|
||||
-- +goose Up
|
||||
DROP INDEX eth.log_cids_index;
|
||||
DROP INDEX eth.tx_tx_hash_index;
|
||||
DROP INDEX eth.header_block_hash_index;
|
||||
|
||||
-- +goose Down
|
||||
CREATE INDEX header_block_hash_index ON eth.header_cids USING btree (block_hash);
|
||||
CREATE INDEX tx_tx_hash_index ON eth.transaction_cids USING btree (tx_hash);
|
||||
CREATE INDEX log_cids_index ON eth.log_cids USING btree (rct_id, index);
|
||||
@@ -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;
|
||||
+13
-43
@@ -1,19 +1,4 @@
|
||||
-- +goose Up
|
||||
ALTER TABLE public.blocks
|
||||
ADD CONSTRAINT pk_public_blocks PRIMARY KEY (key);
|
||||
|
||||
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);
|
||||
|
||||
@@ -33,35 +18,20 @@ ALTER TABLE eth.state_accounts
|
||||
ADD CONSTRAINT pk_eth_state_accounts PRIMARY KEY (header_id, state_path);
|
||||
|
||||
-- +goose Down
|
||||
ALTER TABLE public.blocks
|
||||
DROP CONSTRAINT pk_public_blocks;
|
||||
|
||||
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;
|
||||
+8
-8
@@ -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);
|
||||
|
||||
@@ -46,8 +46,8 @@ CREATE INDEX access_list_element_address_index ON eth.access_list_elements USING
|
||||
CREATE INDEX access_list_storage_keys_index ON eth.access_list_elements USING gin (storage_keys);
|
||||
|
||||
-- log indexes
|
||||
CREATE INDEX log_mh_index ON eth.log_cids USING btree (leaf_mh_key);
|
||||
CREATE INDEX log_cid_index ON eth.log_cids USING btree (leaf_cid);
|
||||
CREATE INDEX log_mh_index ON eth.log_cids USING btree (leaf_mh_key);
|
||||
CREATE INDEX log_address_index ON eth.log_cids USING btree (address);
|
||||
CREATE INDEX log_topic0_index ON eth.log_cids USING btree (topic0);
|
||||
CREATE INDEX log_topic1_index ON eth.log_cids USING btree (topic1);
|
||||
@@ -61,8 +61,8 @@ DROP INDEX eth.log_topic2_index;
|
||||
DROP INDEX eth.log_topic1_index;
|
||||
DROP INDEX eth.log_topic0_index;
|
||||
DROP INDEX eth.log_address_index;
|
||||
DROP INDEX eth.log_cid_index;
|
||||
DROP INDEX eth.log_mh_index;
|
||||
DROP INDEX eth.log_cid_index;
|
||||
|
||||
-- access list indexes
|
||||
DROP INDEX eth.access_list_storage_keys_index;
|
||||
Reference in New Issue
Block a user