Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 35 additions & 2 deletions source/go_bindata/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

## Usage



### Read bindata with NewWithSourceInstance

```shell
Expand Down Expand Up @@ -31,6 +29,41 @@ func main() {
}
```

### Read bindata with directories in filename

The default [source.Regex](https://github.com/golang-migrate/migrate/blob/master/source/parse.go#L22C1-L23C1) used in the above example assumes that the go-bindata filenames were generated from the same directory that the files exist in, if your go-bindata is in run via Makefile targets, or other automated setups or just outside of the current directory, the default will fail. To enable this, you must overwrite the regex to allow for directories.

```shell
go get -u github.com/jteeuwen/go-bindata/...
go-bindata -pkg migrations ./examples/migrations
```

```go
import (
"regexp"

"github.com/golang-migrate/migrate/v4"
"github.com/golang-migrate/migrate/v4/source"
"github.com/golang-migrate/migrate/v4/source/go_bindata"
"github.com/golang-migrate/migrate/v4/source/go_bindata/examples/migrations"
)

func main() {
// Overwrite the Regex with a non-capturing 0-or-more directories (this doesn't cover directories with numbers in their names)
source.Regex = regexp.MustCompile(`^[a-zA-Z\-_\/]*([0-9]+)_(.*)\.(down|up)\.(.*)$`)

// wrap assets into Resource
s := bindata.Resource(migrations.AssetNames(),
func(name string) ([]byte, error) {
return migrations.Asset(name)
})

d, err := bindata.WithInstance(s)
m, err := migrate.NewWithSourceInstance("go-bindata", d, "database://foobar")
m.Up() // run your migrations and handle the errors above of course
}
```

### Read bindata with URL (todo)

This will restore the assets in a tmp directory and then
Expand Down
Loading