46 lines
856 B
Go
46 lines
856 B
Go
package migration
|
|
|
|
import (
|
|
"text/template"
|
|
|
|
"git.ostiwe.com/ostiwe-com/status/modules/db"
|
|
appLog "git.ostiwe.com/ostiwe-com/status/modules/log"
|
|
"github.com/pressly/goose/v3"
|
|
)
|
|
|
|
const migrationDir = "migrations"
|
|
|
|
var sqlMigrationTemplate = template.Must(template.New("goose.sql-migration").Parse(`-- +goose Up
|
|
|
|
-- +goose Down
|
|
`))
|
|
|
|
func init() {
|
|
goose.SetSequential(true)
|
|
goose.SetLogger(appLog.Global.Get(appLog.DATABASE))
|
|
}
|
|
|
|
func CreateMigration(name string) error {
|
|
return goose.CreateWithTemplate(nil, migrationDir, sqlMigrationTemplate, name, "sql")
|
|
}
|
|
|
|
func RunMigration() {
|
|
connect, err := db.Connect()
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
dbConn, err := connect.DB()
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
if err = goose.SetDialect("postgres"); err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
if err = goose.Up(dbConn, migrationDir); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|