From bd121495947fb32e6ae25a174846e8ab7db2bd1d Mon Sep 17 00:00:00 2001 From: anon Date: Wed, 10 Apr 2019 17:56:31 -0400 Subject: [PATCH 1/4] Database config --- Gopkg.lock | 1 - Makefile | 4 +++- environments/composeAndExecuteAccountTransformer.toml | 2 +- pkg/plugin/manager/manager.go | 8 +++++++- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/Gopkg.lock b/Gopkg.lock index adc6f867..aa20c4f7 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -542,7 +542,6 @@ "github.com/ethereum/go-ethereum/ethdb", "github.com/ethereum/go-ethereum/p2p", "github.com/ethereum/go-ethereum/p2p/discv5", - "github.com/ethereum/go-ethereum/params", "github.com/ethereum/go-ethereum/rlp", "github.com/ethereum/go-ethereum/rpc", "github.com/hashicorp/golang-lru", diff --git a/Makefile b/Makefile index f8658e97..a46a8e2b 100644 --- a/Makefile +++ b/Makefile @@ -70,7 +70,8 @@ build: dep HOST_NAME = localhost PORT = 5432 NAME = -CONNECT_STRING=postgresql://$(HOST_NAME):$(PORT)/$(NAME)?sslmode=disable +USER = vulcanize +CONNECT_STRING=postgresql://$(USER)@$(HOST_NAME):$(PORT)/$(NAME)?sslmode=disable # Parameter checks ## Check that DB variables are provided @@ -79,6 +80,7 @@ checkdbvars: test -n "$(HOST_NAME)" # $$HOST_NAME test -n "$(PORT)" # $$PORT test -n "$(NAME)" # $$NAME + test -n "$(USER)" # $$USER @echo $(CONNECT_STRING) ## Check that the migration variable (id/timestamp) is provided diff --git a/environments/composeAndExecuteAccountTransformer.toml b/environments/composeAndExecuteAccountTransformer.toml index 97a2b21a..6ea2c14a 100644 --- a/environments/composeAndExecuteAccountTransformer.toml +++ b/environments/composeAndExecuteAccountTransformer.toml @@ -1,7 +1,7 @@ [database] name = "vulcanize_public" hostname = "localhost" - port = 5432 + port = 3333 [client] ipcPath = "" diff --git a/pkg/plugin/manager/manager.go b/pkg/plugin/manager/manager.go index e19fbd0b..74e9c182 100644 --- a/pkg/plugin/manager/manager.go +++ b/pkg/plugin/manager/manager.go @@ -128,7 +128,13 @@ func (m *manager) fixAndRun(path string) error { return errors.New(fmt.Sprintf("version fixing for plugin migrations at %s failed: %s", path, err.Error())) } // Run the copied migrations with goose - pgStr := fmt.Sprintf("postgres://%s:%d/%s?sslmode=disable", m.DBConfig.Hostname, m.DBConfig.Port, m.DBConfig.Name) + var pgStr string + if len(m.DBConfig.User) > 0 && len(m.DBConfig.Password) > 0 { + pgStr = fmt.Sprintf("postgresql://%s:%s@%s:%d/%s?sslmode=disable", + m.DBConfig.User, m.DBConfig.Password, m.DBConfig.Hostname, m.DBConfig.Port, m.DBConfig.Name) + } else { + pgStr = fmt.Sprintf("postgres://%s:%d/%s?sslmode=disable", m.DBConfig.Hostname, m.DBConfig.Port, m.DBConfig.Name) + } cmd = exec.Command("goose", "postgres", pgStr, "up") cmd.Dir = m.tmpMigDir err = cmd.Run() From 2a9b7b1414e358323fdf02b4f7a81fd2ed160dee Mon Sep 17 00:00:00 2001 From: anon Date: Wed, 10 Apr 2019 17:59:23 -0400 Subject: [PATCH 2/4] Don't change default toml --- environments/composeAndExecuteAccountTransformer.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/environments/composeAndExecuteAccountTransformer.toml b/environments/composeAndExecuteAccountTransformer.toml index 6ea2c14a..97a2b21a 100644 --- a/environments/composeAndExecuteAccountTransformer.toml +++ b/environments/composeAndExecuteAccountTransformer.toml @@ -1,7 +1,7 @@ [database] name = "vulcanize_public" hostname = "localhost" - port = 3333 + port = 5432 [client] ipcPath = "" From aac2d852ca8d71c1ce96650edfc999f4f444faab Mon Sep 17 00:00:00 2001 From: anon Date: Wed, 10 Apr 2019 18:18:58 -0400 Subject: [PATCH 3/4] Default user is postgres --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index a46a8e2b..806febaf 100644 --- a/Makefile +++ b/Makefile @@ -70,7 +70,7 @@ build: dep HOST_NAME = localhost PORT = 5432 NAME = -USER = vulcanize +USER = postgres CONNECT_STRING=postgresql://$(USER)@$(HOST_NAME):$(PORT)/$(NAME)?sslmode=disable # Parameter checks From 4e8485810efc273c05d2978c5fc0ed08b8692d3a Mon Sep 17 00:00:00 2001 From: anon Date: Thu, 11 Apr 2019 13:14:04 -0400 Subject: [PATCH 4/4] Add note to readme --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 3315847d..4bb63f69 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,7 @@ Lastly, ensure that `GOPATH` is defined in your shell. If necessary, `GOPATH` ca 1. `createdb vulcanize_public` 1. `cd $GOPATH/src/github.com/vulcanize/vulcanizedb` 1. Run the migrations: `make migrate HOST_NAME=localhost NAME=vulcanize_public PORT=5432` + - There is an optional var `USER=username` if the database user is not the default user `postgres` - To rollback a single step: `make rollback NAME=vulcanize_public` - To rollback to a certain migration: `make rollback_to MIGRATION=n NAME=vulcanize_public` - To see status of migrations: `make migration_status NAME=vulcanize_public`