rubenv / sql-migrate

SQL schema migration tool for Go.
MIT License
3.23k stars 280 forks source link

"file does not exist" with statik http.FileSystem #167

Closed lukasmalkmus closed 4 years ago

lukasmalkmus commented 4 years ago

I had a good experience with go-bindata and sql-migrate. Recently I switched to https://github.com/rakyll/statik for a number of reasons. To get statik and sql-migrate to work I did the following (note that I use latest master to get the name-spacing feature):

migrationFS, err := fs.NewWithNamespace("migrations")
if err != nil {
    return fmt.Errorf("create migrations file system: %w", err)
}

migrations := &migrate.HttpFileSystemMigrationSource{
    FileSystem: migrationFS,
}

// ...

But migrating fails with Error while opening 000_my_migration.sql: file does not exist.

I double checked and the file is there. So I tried to open it:

f, err := migrationFS.Open("000_my_migration.sql")
if err != nil {
    return err
}
defer f.Close()

And it failed to!

To get this working, I had to prefix the filename with a /;

f, err := migrationFS.Open("/000_my_migration.sql")
if err != nil {
    return err
}
defer f.Close()

I wonder if the issue is on statik side or sql-migrate. A quick upstream fix would be to just prefix the info.Name() in findMigrations() with a /. But I can't tell if this will affect others.

jufemaiz commented 4 years ago

I think I've found the root source of the issue as I'm seeing a similar issue using pkger as an HttpFileSystemMigrationSource.