go-urlsh/internal/db/migrations.go

29 lines
542 B
Go
Raw Normal View History

2024-05-04 17:06:01 +02:00
package db
import (
"context"
"log"
"code.lila.network/adoralaura/go-urlsh/migrations"
"github.com/uptrace/bun"
2024-05-04 17:06:01 +02:00
"github.com/uptrace/bun/migrate"
)
func doMigrations(db *bun.DB) error {
2024-05-04 17:06:01 +02:00
ctx := context.Background()
migrator := migrate.NewMigrator(db, migrations.Migrations)
2024-05-04 17:06:01 +02:00
migrator.Init(ctx)
group, err := migrator.Migrate(ctx)
if err != nil {
return err
}
if group.IsZero() {
log.Printf("[DB] No new migrations to run (database is up to date)\n")
return nil
}
log.Printf("[DB] Migrated to %s\n", group)
return nil
}