Skip to content

armgit / fider

Public Imported from GitHub
0

Open platform to collect and prioritize feedback

run migrations on startup

goenning209df08e13d9
diff --git a/Makefile b/Makefile
index ad2037fce..fcbbc4faf 100644
--- a/Makefile
+++ b/Makefile
@@ -29,13 +29,6 @@ ifeq ($(TRAVIS_PULL_REQUEST), false)
docker push WeCanHearYou/wechy
endif
-migrate:
-ifeq ($(GO_ENV), development)
- migrate -url postgres://wechy:wechy-pw@localhost:5555/wechy?sslmode=disable -path ./migrations up
-else
- migrate -url ${DATABASE_URL} -path ./migrations up
-endif
-
build:
go build -ldflags='-X main.buildtime=${BUILD_TIME}'
diff --git a/Procfile b/Procfile
index b8639e142..d5bcd841c 100644
--- a/Procfile
+++ b/Procfile
@@ -1,2 +1 @@
-release: make migrate
web: make run
\ No newline at end of file
diff --git a/main.go b/main.go
index cf4760429..8344d136c 100644
--- a/main.go
+++ b/main.go
@@ -8,15 +8,31 @@ import (
"github.com/WeCanHearYou/wechy/app/postgres"
"github.com/WeCanHearYou/wechy/app/toolbox/env"
_ "github.com/lib/pq"
+ _ "github.com/mattes/migrate/driver/postgres"
+ mig "github.com/mattes/migrate/migrate"
"fmt"
)
var buildtime string
+func migrate() {
+ fmt.Printf("Running migrations... \n")
+ errors, ok := mig.UpSync(env.MustGet("DATABASE_URL"), "./migrations")
+ if !ok {
+ for i, err := range errors {
+ fmt.Printf("Error #%d: %s.\n", i, err)
+ }
+ panic("Migrations failed.")
+ } else {
+ fmt.Printf("Migrations finished with success.\n")
+ }
+}
+
func init() {
fmt.Printf("Application is starting...\n")
fmt.Printf("GO_ENV: %s\n", env.Current())
+ migrate()
}
func main() {