Compare commits

..
10 Commits
15 changed files with 75 additions and 11 deletions
+27 -2
View File
@@ -1,10 +1,14 @@
ifndef GOPATH
override GOPATH = $(HOME)/go
endif
BIN = $(GOPATH)/bin BIN = $(GOPATH)/bin
# Tools # Tools
## Migration tool ## Migration tool
GOOSE = $(BIN)/goose GOOSE = $(BIN)/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 .PHONY: installtools
installtools: | $(GOOSE) installtools: | $(GOOSE)
@@ -44,12 +48,28 @@ rollback: $(GOOSE) checkdbvars
$(GOOSE) -dir db/migrations postgres "$(CONNECT_STRING)" down $(GOOSE) -dir db/migrations postgres "$(CONNECT_STRING)" down
pg_dump -O -s $(CONNECT_STRING) > schema.sql pg_dump -O -s $(CONNECT_STRING) > schema.sql
## Rollback to a select migration (id/timestamp) ## Rollback to a select migration (id/timestamp)
.PHONY: rollback_to .PHONY: rollback_to
rollback_to: $(GOOSE) checkmigration checkdbvars rollback_to: $(GOOSE) checkmigration checkdbvars
$(GOOSE) -dir db/migrations postgres "$(CONNECT_STRING)" down-to "$(MIGRATION)" $(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
pg_dump -O -s $(CONNECT_STRING) > schema.sql
## 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
pg_dump -O -s $(CONNECT_STRING) > schema.sql
## 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 ## Apply all migrations not already run
.PHONY: migrate .PHONY: migrate
migrate: $(GOOSE) checkdbvars migrate: $(GOOSE) checkdbvars
@@ -61,6 +81,11 @@ migrate: $(GOOSE) checkdbvars
migrate_pre_batch_set: $(GOOSE) checkdbvars migrate_pre_batch_set: $(GOOSE) checkdbvars
$(GOOSE) -dir db/pre_batch_processing_migrations postgres "$(CONNECT_STRING)" up $(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 ## Apply migrations to be ran after a batch processing
.PHONY: migrate_post_batch_set .PHONY: migrate_post_batch_set
migrate_post_batch_set: $(GOOSE) checkdbvars migrate_post_batch_set: $(GOOSE) checkdbvars
+3 -3
View File
@@ -1,6 +1,6 @@
-- +goose Up -- +goose Up
INSERT INTO public.db_version (singleton, version) VALUES (true, 'v0.3.2') INSERT INTO public.db_version (singleton, version) VALUES (true, 'v3.0.0')
ON CONFLICT (singleton) DO UPDATE SET (version, tstamp) = ('v0.3.2', NOW()); ON CONFLICT (singleton) DO UPDATE SET (version, tstamp) = ('v3.0.0', NOW());
-- +goose Down -- +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_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_hash_index ON eth.header_cids USING btree (block_hash);
CREATE INDEX tx_header_hash_index ON eth.transaction_cids USING btree (header_id);
CREATE INDEX transaction_hash_index ON eth.transaction_cids USING btree (tx_hash);
CREATE INDEX log_tx_hash_index ON eth.log_cids USING btree (rct_id);
-- +goose Down
DROP INDEX eth.log_tx_hash_index;
DROP INDEX eth.transaction_hash_index;
DROP INDEX eth.tx_header_hash_index;
DROP INDEX eth.header_hash_index;
DROP INDEX eth.block_number_index;
DROP INDEX eth.log_mh_index_index;
@@ -0,0 +1,15 @@
-- +goose Up
DROP INDEX eth.log_tx_hash_index;
DROP INDEX eth.transaction_hash_index;
DROP INDEX eth.tx_header_hash_index;
DROP INDEX eth.header_hash_index;
DROP INDEX eth.block_number_index;
DROP INDEX eth.log_mh_index_index;
-- +goose Down
CREATE INDEX log_mh_index_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_hash_index ON eth.header_cids USING btree (block_hash);
CREATE INDEX tx_header_hash_index ON eth.transaction_cids USING btree (header_id);
CREATE INDEX transaction_hash_index ON eth.transaction_cids USING btree (tx_hash);
CREATE INDEX log_tx_hash_index ON eth.log_cids USING btree (rct_id);
@@ -1,7 +1,4 @@
-- +goose Up -- +goose Up
ALTER TABLE public.blocks
ADD CONSTRAINT pk_public_blocks PRIMARY KEY (key);
ALTER TABLE public.nodes ALTER TABLE public.nodes
ADD CONSTRAINT pk_public_nodes PRIMARY KEY (node_id); ADD CONSTRAINT pk_public_nodes PRIMARY KEY (node_id);
@@ -33,9 +30,6 @@ 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.blocks
DROP CONSTRAINT pk_public_blocks;
ALTER TABLE public.nodes ALTER TABLE public.nodes
DROP CONSTRAINT pk_public_nodes; DROP CONSTRAINT pk_public_nodes;