mirror of
https://github.com/sysadminsmedia/homebox.git
synced 2025-12-21 13:23:14 +01:00
* fix: Remove log.Fatal in favor of returning errors This change is useful for including error tracking, which needs the application to not terminate immediately, and instead give the tracer time to capture and flush errors. * Fix CodeRabbit issues --------- Co-authored-by: Matthew Kilgore <matthew@kilgore.dev>
35 lines
975 B
Go
35 lines
975 B
Go
// Package migrations
|
|
package migrations
|
|
|
|
import (
|
|
"embed"
|
|
"fmt"
|
|
|
|
"github.com/rs/zerolog/log"
|
|
)
|
|
|
|
//go:embed all:postgres
|
|
var postgresFiles embed.FS
|
|
|
|
//go:embed all:sqlite3
|
|
var sqliteFiles embed.FS
|
|
|
|
// Migrations returns the embedded file system containing the SQL migration files
|
|
// for the specified SQL dialect. It uses the "embed" package to include the
|
|
// migration files in the binary at build time. The function takes a string
|
|
// parameter "dialect" which specifies the SQL dialect to use. It returns an
|
|
// embedded file system containing the migration files for the specified dialect.
|
|
func Migrations(dialect string) (embed.FS, error) {
|
|
switch dialect {
|
|
case "postgres":
|
|
return postgresFiles, nil
|
|
case "sqlite3":
|
|
return sqliteFiles, nil
|
|
default:
|
|
log.Error().Str("dialect", dialect).Msg("unknown sql dialect")
|
|
return embed.FS{}, fmt.Errorf("unknown sql dialect: %s", dialect)
|
|
}
|
|
// This should never get hit, but just in case
|
|
return sqliteFiles, nil
|
|
}
|