add service
All checks were successful
Deploy Smart Search Backend Test / deploy (push) Successful in 2m55s
All checks were successful
Deploy Smart Search Backend Test / deploy (push) Successful in 2m55s
This commit is contained in:
@@ -7,13 +7,14 @@ import (
|
||||
|
||||
_ "github.com/jackc/pgx/v5/stdlib"
|
||||
"github.com/pressly/goose/v3"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
func RunMigrations(databaseURL string) error {
|
||||
return RunMigrationsFromPath(databaseURL, "migrations")
|
||||
func RunMigrations(databaseURL string, logger *zap.Logger) error {
|
||||
return RunMigrationsFromPath(databaseURL, "migrations", logger)
|
||||
}
|
||||
|
||||
func RunMigrationsFromPath(databaseURL, migrationsDir string) error {
|
||||
func RunMigrationsFromPath(databaseURL, migrationsDir string, logger *zap.Logger) error {
|
||||
db, err := sql.Open("pgx", databaseURL)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to open database connection for migrations: %w", err)
|
||||
@@ -28,6 +29,8 @@ func RunMigrationsFromPath(databaseURL, migrationsDir string) error {
|
||||
return fmt.Errorf("failed to set goose dialect: %w", err)
|
||||
}
|
||||
|
||||
goose.SetLogger(&gooseLogger{logger: logger})
|
||||
|
||||
absPath, err := filepath.Abs(migrationsDir)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to resolve migrations path: %w", err)
|
||||
@@ -39,3 +42,15 @@ func RunMigrationsFromPath(databaseURL, migrationsDir string) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type gooseLogger struct {
|
||||
logger *zap.Logger
|
||||
}
|
||||
|
||||
func (l *gooseLogger) Fatalf(format string, v ...interface{}) {
|
||||
l.logger.Fatal(fmt.Sprintf(format, v...))
|
||||
}
|
||||
|
||||
func (l *gooseLogger) Printf(format string, v ...interface{}) {
|
||||
l.logger.Info(fmt.Sprintf(format, v...))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user