28 lines
542 B
Go
28 lines
542 B
Go
package db
|
|
|
|
import (
|
|
"context"
|
|
"log"
|
|
|
|
"code.lila.network/adoralaura/go-urlsh/migrations"
|
|
"github.com/uptrace/bun"
|
|
"github.com/uptrace/bun/migrate"
|
|
)
|
|
|
|
func doMigrations(db *bun.DB) error {
|
|
ctx := context.Background()
|
|
migrator := migrate.NewMigrator(db, migrations.Migrations)
|
|
|
|
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
|
|
}
|