Skip to content

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

@bearsh

Description

@bearsh

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 {

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions