Migrate: first <go-bindata>: file does not exist

Created on 4 Sep 2018  路  6Comments  路  Source: golang-migrate/migrate

Migration using go-bindata fails

Steps to Reproduce

func init() {
    s := bindata.Resource(AssetNames(), func(name string) ([]byte, error) {
        return Asset(name)
    })
    d, _ := bindata.WithInstance(s)
    m, err := migrate.NewWithSourceInstance("go-bindata", d, databaseURL)
    if err != nil {
        logger.Fatalf("can't read migration files: %v", err)
    }
    if err := m.Up(); err != nil {
        logger.Errorf("while migrating up: %v", err)
    }
}

m.Up() produces the following log:

while migrating up: first <go-bindata>: file does not exist

Migrate Version

from go.mod:

github.com/golang-migrate/migrate v3.4.0+incompatible

Loaded Source Drivers
go-bindata

Loaded Database Drivers
postgres

Most helpful comment

Maybe you can use the 'prefix' flag to remove the paths from the generated files.

I.e., something like this:

go-bindata -prefix "database/migrations/" -pkg migrations -o migrations/migrations.go resources/migrations/...

All 6 comments

What are your asset/file names? Do they match the regex in migrate/source/parse.go?

Dumping bindata.Resource, it looks like this:

[]string{
    "../database/migrations/20180227115526_genesis.down.sql",
    "../database/migrations/20180227115526_genesis.up.sql",
    "../database/migrations/20180903113905_do_something.down.sql",
    "../database/migrations/20180903113905_do_something.up.sql",
}

Try renaming your migrations and removing the path prefix such that ../database/migrations/20180227115526_genesis.down.sql becomes 20180227115526_genesis.down.sql

The regex doesn't match because of the ^ qualifier. Your other option is to change the regex.

I'm actually not controlling this. It is the response from bindata.Resource.Names

Maybe you can use the 'prefix' flag to remove the paths from the generated files.

I.e., something like this:

go-bindata -prefix "database/migrations/" -pkg migrations -o migrations/migrations.go resources/migrations/...

@adrianpk thank you for the tip. it fixed my problem

Was this page helpful?
0 / 5 - 0 ratings