summaryrefslogtreecommitdiff
path: root/internal/database/migrations/init.go
blob: 754a097c89574c1eefbf46b1fb407ee18b6044ac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package migrations

import (
	"log/slog"

	migrate "github.com/rubenv/sql-migrate"
)

//go:generate go-bindata -o ./migrations.bindata.go -pkg migrations -ignore=\\*.go ./...

func GetMigrationSource() *migrate.AssetMigrationSource {
	return &migrate.AssetMigrationSource{
		Asset:    Asset,
		AssetDir: AssetDir,
		Dir:      ".",
	}
}

func RunMigrations(db migrate.Execer, driver string) (int, error) {
	source := GetMigrationSource()
	n, err := migrate.Exec(db, driver, source, migrate.Up)
	if err != nil {
		slog.Error("failed to run migrations", "error", err)
		return 0, err
	}
	slog.Info("applied database migrations", "count", n)
	return n, nil
}