Skip to content

Conversation

bearsh
Copy link

@bearsh bearsh commented Apr 15, 2021

… separator

when DiscoverSQLMigrations() is called, a 'os nativ' fs is assumed, so
convert the path to slash. when opening a file on such a fs, convert to
back from slash to native separator.

#107

… separator

when DiscoverSQLMigrations() is called, a 'os nativ' fs is assumed, so
convert the path to slash. when opening a file on such a fs, convert to
back from slash to native separator.

go-pg#107
@landru29
Copy link

As there's nothing new since 2021, I propose a workaround:

import (
	"net/http"
	"path"
)

type fsMove struct {
	folder     string
	originalFS http.FileSystem
}

func newFSMove(originalFS http.FileSystem, folder string) http.FileSystem {
	return fsMove{
		folder:     folder,
		originalFS: originalFS,
	}
}

func (f fsMove) Open(name string) (http.File, error) {
	return f.originalFS.Open(path.Join(f.folder, name))
}

Then, you can use it with:

collection := migrations.NewCollection()
if err := collection.DiscoverSQLMigrationsFromFilesystem(
    newFSMove(migrationFS, "where/are/located/my/embed/files"),
    "",
); err != nil {
	panic(err)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants