fix: fist integration test #181
All checks were successful
Build Docker Image / Explore-Gitea-Actions (push) Successful in 47s
Build and Push Docker Image / Explore-Gitea-Actions (push) Successful in 52s

This commit was merged in pull request #189.
This commit is contained in:
2024-10-02 23:13:31 +02:00
parent 33380e2124
commit f2a98e5f49
9 changed files with 181 additions and 46 deletions

View File

@@ -2,17 +2,20 @@ package utils
import (
"database/sql"
"log"
"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 MustRunMigrations(db *sql.DB, pathPrefix string) {
func RunMigrations(db *sql.DB, pathPrefix string) error {
driver, err := sqlite3.WithInstance(db, &sqlite3.Config{})
if err != nil {
log.Fatal(err)
slog.Error("Could not create Migration instance: " + err.Error())
return types.ErrInternal
}
m, err := migrate.NewWithDatabaseInstance(
@@ -20,13 +23,17 @@ func MustRunMigrations(db *sql.DB, pathPrefix string) {
"",
driver)
if err != nil {
log.Fatal("Could not create migrations instance: ", err)
slog.Error("Could not create migrations instance: " + err.Error())
return types.ErrInternal
}
err = m.Up()
if err != nil {
if err.Error() != "no change" {
log.Fatal("Could not run migrations: ", err)
if !errors.Is(err, migrate.ErrNoChange) {
slog.Error("Could not run migrations: " + err.Error())
return types.ErrInternal
}
}
return nil
}