1
0
Fork 0

added a workaround to use a embed.fs filesystem.

Dieser Commit ist enthalten in:
Sebastian Tobie 2021-02-27 11:54:10 +01:00
Ursprung e15e855531
Commit b7b70afba4
2 geänderte Dateien mit 36 neuen und 2 gelöschten Zeilen

Datei anzeigen

@ -2,6 +2,7 @@ package db
import ( import (
"context" "context"
"io/fs"
"sync" "sync"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
@ -102,14 +103,15 @@ func logmigrations(version int32, name string, dir string, sql string) {
} }
// SetupMigrator sets up the migrator to migrate the database. // SetupMigrator sets up the migrator to migrate the database.
func SetupMigrator(prefix string, connection *pgx.Conn, migrations migrate.MigratorFS) (mig *migrate.Migrator, err error) { func SetupMigrator(prefix string, connection *pgx.Conn, migrations fs.FS) (mig *migrate.Migrator, err error) {
migfs := &iofsMigratorFS{fsys: migrations}
mig, err = migrate.NewMigratorEx( mig, err = migrate.NewMigratorEx(
context.TODO(), context.TODO(),
connection, connection,
"version", "version",
&migrate.MigratorOptions{ &migrate.MigratorOptions{
DisableTx: false, DisableTx: false,
MigratorFS: migrations, MigratorFS: migfs,
}, },
) )
if err != nil { if err != nil {

32
middleware/db/workarounds.go Normale Datei
Datei anzeigen

@ -0,0 +1,32 @@
package db
import (
"io/fs"
"os"
)
type iofsMigratorFS struct{ fsys fs.FS }
func (m iofsMigratorFS) ReadDir(dirname string) ([]fs.FileInfo, error) {
de, err := fs.ReadDir(m.fsys, dirname)
if err != nil {
return nil, err
}
var res []os.FileInfo
for _, v := range de {
fi, err := v.Info()
if err != nil {
return nil, err
}
res = append(res, fi)
}
return res, nil
}
func (m iofsMigratorFS) ReadFile(filename string) ([]byte, error) {
return fs.ReadFile(m.fsys, filename)
}
func (m iofsMigratorFS) Glob(pattern string) (matches []string, err error) {
return fs.Glob(m.fsys, pattern)
}