Audit fixes

This commit is contained in:
jdl
2026-06-14 20:13:08 +02:00
parent 0d382fa2d0
commit 2ef44dbc31

View File

@@ -5,8 +5,7 @@ import (
"embed"
"errors"
"fmt"
"path/filepath"
"sort"
"path"
)
const initMigrationTableQuery = `
@@ -34,17 +33,13 @@ func Migrate(db *sql.DB, migrationFS embed.FS) error {
return fmt.Errorf("unexpected non-directory in migration FS: %s", dirs[0].Name())
}
// ReadDir returns files in sorted order.
dirName := dirs[0].Name()
files, err := migrationFS.ReadDir(dirName)
if err != nil {
return err
}
// Sort sql files by name.
sort.Slice(files, func(i, j int) bool {
return files[i].Name() < files[j].Name()
})
for _, dirEnt := range files {
if !dirEnt.Type().IsRegular() {
return fmt.Errorf("unexpected non-regular file in migration fs: %s", dirEnt.Name())
@@ -64,7 +59,7 @@ func Migrate(db *sql.DB, migrationFS embed.FS) error {
continue
}
migration, err := migrationFS.ReadFile(filepath.Join(dirName, name))
migration, err := migrationFS.ReadFile(path.Join(dirName, name))
if err != nil {
return err
}