added a workaround to use a embed.fs filesystem.
Dieser Commit ist enthalten in:
Ursprung
e15e855531
Commit
b7b70afba4
|
@ -2,6 +2,7 @@ package db
|
|||
|
||||
import (
|
||||
"context"
|
||||
"io/fs"
|
||||
"sync"
|
||||
|
||||
"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.
|
||||
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(
|
||||
context.TODO(),
|
||||
connection,
|
||||
"version",
|
||||
&migrate.MigratorOptions{
|
||||
DisableTx: false,
|
||||
MigratorFS: migrations,
|
||||
MigratorFS: migfs,
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
|
|
|
@ -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)
|
||||
}
|
Laden…
In neuem Issue referenzieren