Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DiscoverSQLMigrationsFromFilesystem() does not (always) work on windows #107

Open
bearsh opened this issue Apr 8, 2021 · 1 comment
Open

Comments

@bearsh
Copy link

bearsh commented Apr 8, 2021

I embed my sql files with the new go:embed:

//go:embed *.sql
var EmbedFs embed.FS
var HttpFs = http.FS(EmbedFs)

then I call migrations.DefaultCollection.DiscoverSQLMigrationsFromFilesystem(migration.HttpFs, "/") to discover the sql files from the embedded filesystem. this works on linux but not on windows.

the following path makes it also work on windows as the underlying fs only uses forward slashed:

diff --git a/collection.go b/collection.go
index 29c8d99..7811b63 100644
--- a/collection.go
+++ b/collection.go
@@ -219,7 +219,7 @@ func (c *Collection) DiscoverSQLMigrationsFromFilesystem(fs http.FileSystem, dir
                }
 
                m := newMigration(version)
-               filePath := filepath.Join(dir, fileName)
+               filePath := path.Join(dir, fileName)
 
                if strings.HasSuffix(fileName, ".up.sql") {
                        if m.Up != nil {
@tie
Copy link

tie commented Apr 12, 2021

See also #101 (comment) (edit: this bit was actually fixed in 816afdb)

bearsh added a commit to bearsh/migrations that referenced this issue 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.

go-pg#107
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

No branches or pull requests

2 participants