diff --git a/Makefile b/Makefile index 6e8a377..c2dc144 100644 --- a/Makefile +++ b/Makefile @@ -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) @@ -50,6 +54,11 @@ rollback: $(GOOSE) checkdbvars rollback_to: $(GOOSE) checkmigration checkdbvars $(GOOSE) -dir db/migrations postgres "$(CONNECT_STRING)" down-to "$(MIGRATION)" +## 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 +70,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 diff --git a/db/migrations/00010_create_eth_state_accouts_table.sql b/db/migrations/00010_create_eth_state_accounts_table.sql similarity index 100% rename from db/migrations/00010_create_eth_state_accouts_table.sql rename to db/migrations/00010_create_eth_state_accounts_table.sql diff --git a/db/post_batch_processing_migrations/00016_create_ipld_pk_constraint.sql b/db/post_batch_processing_migrations/00016_create_ipld_pk_constraint.sql new file mode 100644 index 0000000..8d2fab7 --- /dev/null +++ b/db/post_batch_processing_migrations/00016_create_ipld_pk_constraint.sql @@ -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; diff --git a/db/post_batch_processing_migrations/00017_create_pk_constraints.sql b/db/post_batch_processing_migrations/00017_create_pk_constraints.sql index 5290087..f574f21 100644 --- a/db/post_batch_processing_migrations/00017_create_pk_constraints.sql +++ b/db/post_batch_processing_migrations/00017_create_pk_constraints.sql @@ -1,7 +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); @@ -33,9 +30,6 @@ 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; diff --git a/db/post_batch_processing_migrations/00016_make_tables_logged.sql b/db/post_batch_processing_migrations/00018_make_tables_logged.sql similarity index 100% rename from db/post_batch_processing_migrations/00016_make_tables_logged.sql rename to db/post_batch_processing_migrations/00018_make_tables_logged.sql diff --git a/db/post_batch_processing_migrations/00018_create_fk_relations.sql b/db/post_batch_processing_migrations/00019_create_fk_relations.sql similarity index 100% rename from db/post_batch_processing_migrations/00018_create_fk_relations.sql rename to db/post_batch_processing_migrations/00019_create_fk_relations.sql diff --git a/db/post_batch_processing_migrations/00019_create_postgraphile_comments.sql b/db/post_batch_processing_migrations/00020_create_postgraphile_comments.sql similarity index 100% rename from db/post_batch_processing_migrations/00019_create_postgraphile_comments.sql rename to db/post_batch_processing_migrations/00020_create_postgraphile_comments.sql diff --git a/db/post_batch_processing_migrations/00020_create_cid_indexes.sql b/db/post_batch_processing_migrations/00021_create_cid_indexes.sql similarity index 100% rename from db/post_batch_processing_migrations/00020_create_cid_indexes.sql rename to db/post_batch_processing_migrations/00021_create_cid_indexes.sql diff --git a/db/post_batch_processing_migrations/00021_create_stored_functions.sql b/db/post_batch_processing_migrations/00022_create_stored_functions.sql similarity index 100% rename from db/post_batch_processing_migrations/00021_create_stored_functions.sql rename to db/post_batch_processing_migrations/00022_create_stored_functions.sql diff --git a/db/post_batch_processing_migrations/00022_create_postgraphile_triggers.sql b/db/post_batch_processing_migrations/00023_create_postgraphile_triggers.sql similarity index 100% rename from db/post_batch_processing_migrations/00022_create_postgraphile_triggers.sql rename to db/post_batch_processing_migrations/00023_create_postgraphile_triggers.sql diff --git a/db/pre_batch_processing_migrations/00010_create_eth_state_accouts_table.sql b/db/pre_batch_processing_migrations/00010_create_eth_state_accounts_table.sql similarity index 100% rename from db/pre_batch_processing_migrations/00010_create_eth_state_accouts_table.sql rename to db/pre_batch_processing_migrations/00010_create_eth_state_accounts_table.sql