Init commit repo setup
This commit is contained in:
30
db/migrations.go
Normal file
30
db/migrations.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package db
|
||||
|
||||
import (
|
||||
"cybertron/configs"
|
||||
"cybertron/pkg/log"
|
||||
|
||||
"github.com/golang-migrate/migrate/v4"
|
||||
_ "github.com/golang-migrate/migrate/v4/database/postgres"
|
||||
_ "github.com/golang-migrate/migrate/v4/source/file"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
const dbMigrationsPath = "./db/migrations"
|
||||
|
||||
func RunDatabaseMigrations() error {
|
||||
var err error
|
||||
postgresConfig := configs.GetPostgresMigConfig()
|
||||
appMigrate, err := migrate.New("file://"+dbMigrationsPath, postgresConfig.GetPostgresUrl())
|
||||
if err != nil {
|
||||
log.Log.GetLog().Error("migrations error", zap.Error(err))
|
||||
panic(err)
|
||||
}
|
||||
err = appMigrate.Up()
|
||||
if err != nil && err != migrate.ErrNoChange {
|
||||
log.Error("migrations error", zap.Error(err))
|
||||
return err
|
||||
}
|
||||
log.Info("migrations successful")
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user