This repository has been archived on 2025-08-09. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
web-app-template/utils/db.go
Tim Wundenberg 0ebe02619a
All checks were successful
Build Docker Image / Explore-Gitea-Actions (push) Successful in 51s
fix: fist integration test
2024-10-02 23:13:31 +02:00

40 lines
864 B
Go

package utils
import (
"database/sql"
"errors"
"log/slog"
"me-fit/types"
"github.com/golang-migrate/migrate/v4"
"github.com/golang-migrate/migrate/v4/database/sqlite3"
_ "github.com/golang-migrate/migrate/v4/source/file"
)
func RunMigrations(db *sql.DB, pathPrefix string) error {
driver, err := sqlite3.WithInstance(db, &sqlite3.Config{})
if err != nil {
slog.Error("Could not create Migration instance: " + err.Error())
return types.ErrInternal
}
m, err := migrate.NewWithDatabaseInstance(
"file://"+pathPrefix+"migration/",
"",
driver)
if err != nil {
slog.Error("Could not create migrations instance: " + err.Error())
return types.ErrInternal
}
err = m.Up()
if err != nil {
if !errors.Is(err, migrate.ErrNoChange) {
slog.Error("Could not run migrations: " + err.Error())
return types.ErrInternal
}
}
return nil
}