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