fix: moved embed.FS to own package, so the api binary has no sql files embedded

This commit is contained in:
2026-08-25 11:05:23 +02:00
parent f031f7c15a
commit 2732038a1f
3 changed files with 10 additions and 6 deletions
+2 -1
View File
@@ -11,6 +11,7 @@ import (
"github.com/joho/godotenv" "github.com/joho/godotenv"
"github.com/robindittmar/dttmr-api/internal/config" "github.com/robindittmar/dttmr-api/internal/config"
"github.com/robindittmar/dttmr-api/internal/database" "github.com/robindittmar/dttmr-api/internal/database"
"github.com/robindittmar/dttmr-api/internal/database/migrations"
"github.com/robindittmar/dttmr-api/internal/domain" "github.com/robindittmar/dttmr-api/internal/domain"
"github.com/robindittmar/dttmr-api/internal/repository" "github.com/robindittmar/dttmr-api/internal/repository"
) )
@@ -51,7 +52,7 @@ func main() {
} }
}() }()
if err := database.RunMigrations(db); err != nil { if err := database.RunMigrations(db, migrations.MigrationFS); err != nil {
slog.Error("failed to run migrations", slog.Any("error", err)) slog.Error("failed to run migrations", slog.Any("error", err))
os.Exit(1) os.Exit(1)
} }
+2 -5
View File
@@ -2,9 +2,9 @@ package database
import ( import (
"database/sql" "database/sql"
"embed"
"errors" "errors"
"fmt" "fmt"
"io/fs"
"log/slog" "log/slog"
"github.com/golang-migrate/migrate/v4" "github.com/golang-migrate/migrate/v4"
@@ -12,10 +12,7 @@ import (
"github.com/golang-migrate/migrate/v4/source/iofs" "github.com/golang-migrate/migrate/v4/source/iofs"
) )
//go:embed migrations/*.sql func RunMigrations(db *sql.DB, migrationFS fs.FS) error {
var migrationFS embed.FS
func RunMigrations(db *sql.DB) error {
sourceDriver, err := iofs.New(migrationFS, "migrations") sourceDriver, err := iofs.New(migrationFS, "migrations")
if err != nil { if err != nil {
return fmt.Errorf("failed to load embedded migrations: %w", err) return fmt.Errorf("failed to load embedded migrations: %w", err)
+6
View File
@@ -0,0 +1,6 @@
package migrations
import "embed"
//go:embed *.sql
var MigrationFS embed.FS