* TP-55555 | document client and kafka integration * TP-55555 | introduce service concept refactor code * TP-55555 | s3 and kafka producer integrated and tested * TP-55555 | s3 and kafka producer integrated and tested * TP-55555 | fixed kafka for subsequent request * TP-55555 | fixed kafka for subsequent request
31 lines
764 B
Go
31 lines
764 B
Go
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.Log.Error("migrations error", zap.Error(err))
|
|
return err
|
|
}
|
|
log.Log.Info("migrations successful")
|
|
return nil
|
|
}
|