mirror of
https://github.com/hay-kot/homebox.git
synced 2024-12-05 06:55:40 +00:00
e8449b3a73
* fix inaccruate 401 error on SQL db error * init golangci-lint config * linter autofix * testify auto fixes * fix sqlite busy errors * fix naming * more linter errors * fix rest of linter issues
44 lines
823 B
Go
44 lines
823 B
Go
// Package migrations provides a way to embed the migrations into the binary.
|
|
package migrations
|
|
|
|
import (
|
|
"embed"
|
|
"os"
|
|
"path"
|
|
)
|
|
|
|
//go:embed all:migrations
|
|
var Files embed.FS
|
|
|
|
// Write writes the embedded migrations to a temporary directory.
|
|
// It returns an error and a cleanup function. The cleanup function
|
|
// should be called when the migrations are no longer needed.
|
|
func Write(temp string) error {
|
|
err := os.MkdirAll(temp, 0o755)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
fsDir, err := Files.ReadDir("migrations")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
for _, f := range fsDir {
|
|
if f.IsDir() {
|
|
continue
|
|
}
|
|
|
|
b, err := Files.ReadFile(path.Join("migrations", f.Name()))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
err = os.WriteFile(path.Join(temp, f.Name()), b, 0o644)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|