fastpastebin/database/migrations/exported.go

35 lines
670 B
Go
Raw Normal View History

2018-04-30 18:42:17 +05:00
package migrations
import (
// local
"github.com/pztrn/fastpastebin/context"
// other
//"github.com/jmoiron/sqlx"
"github.com/pressly/goose"
)
var (
c *context.Context
)
// New initializes migrations.
2018-04-30 18:42:17 +05:00
func New(cc *context.Context) {
c = cc
}
// Migrate launching migrations.
2018-04-30 18:42:17 +05:00
func Migrate() {
c.Logger.Info().Msg("Migrating database...")
goose.SetDialect("mysql")
goose.AddNamedMigration("1_initial.go", InitialUp, nil)
// Add new migrations BEFORE this message.
2018-04-30 18:42:17 +05:00
dbConn := c.Database.GetDatabaseConnection()
err := goose.Up(dbConn.DB, ".")
if err != nil {
c.Logger.Panic().Msgf("Failed to migrate database to latest version: %s", err.Error())
}
}