Skip to content

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

@lukasmalkmus

Description

@lukasmalkmus

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions