rhythm-backend/internal/db/migration.go
Dmitri f00226a0d6
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 2m23s
logging
2026-04-19 19:09:13 +02:00

34 lines
838 B
Go

package db
import (
"database/sql"
"log"
"git.kanopo.dev/rhythm/rhythm-backend/internal/logger"
"git.kanopo.dev/rhythm/rhythm-backend/migrations"
_ "github.com/jackc/pgx/v5/stdlib"
"github.com/pressly/goose/v3"
"go.uber.org/zap"
)
func RunMigrations(dbURL string, zLog *zap.SugaredLogger) {
db, err := sql.Open("pgx", dbURL)
if err != nil {
log.Fatalf("open db for migrations: %v", err.Error())
}
defer db.Close()
goose.SetLogger(&logger.GooseLogger{SugaredLogger: zLog})
// 2. Pass the exported FS to Goose!
goose.SetBaseFS(migrations.FS)
if err := goose.SetDialect("postgres"); err != nil {
log.Fatalf("set goose dialect: %v", err.Error())
}
// 3. Run the migrations using the current directory "." of the embed.FS
if err := goose.Up(db, "."); err != nil {
log.Fatalf("run goose up: %v", err.Error())
}
}