Skip to content

armgit / fider

Public Imported from GitHub
0

Open platform to collect and prioritize feedback

merged

goenning00a3880d5cce
diff --cc main.go
index b050ad44e,af9444684..2bf0354c9
--- a/main.go
+++ b/main.go
@@@ -3,22 -3,49 +3,46 @@@ package mai
import (
"runtime"
++ "fmt"
++
"github.com/WeCanHearYou/wechy/app/models"
"github.com/WeCanHearYou/wechy/app/pkg/dbx"
"github.com/WeCanHearYou/wechy/app/pkg/env"
"github.com/WeCanHearYou/wechy/app/pkg/oauth"
"github.com/WeCanHearYou/wechy/app/storage/postgres"
-
- "fmt"
+ _ "github.com/lib/pq"
+ mig "github.com/mattes/migrate"
+ _ "github.com/mattes/migrate/database/postgres"
+ _ "github.com/mattes/migrate/source/file"
-
- "fmt"
)
var buildtime string
var version = "0.2.0"
- func main() {
+ func migrate() {
+ fmt.Printf("Running migrations... \n")
+ m, err := mig.New(
+ "file://./migrations",
+ env.MustGet("DATABASE_URL"),
+ )
+
+ if err == nil {
+ err = m.Up()
+ }
+
+ if err != nil && err != mig.ErrNoChange {
+ fmt.Printf("Error: %s.\n", 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() {
db, err := dbx.New()
if err != nil {
panic(err)