Skip to content

docs(source,go-bindata) update go-bindata source readme to include regex overrides for asset names - #1448

Open
erindatkinson wants to merge 2 commits into
golang-migrate:masterfrom
erindatkinson:patch-1
Open

erindatkinson wants to merge 2 commits into
golang-migrate:masterfrom
erindatkinson:patch-1

Conversation

@erindatkinson

Copy link
Copy Markdown

When trying to run on a preconfigured bindata package I had, I ran into the issue that the migrations were not being run when done with code, even when they were valid with the cli runner. This was silently failing due to the continue in the WithInstance call failing on no regex match for otherwise valid migrations.

This change updates the docs to explain better how to enable directoried asset names in lieu of just single filenames. Rather than try to update the default regex, adding the documentation on how to override to your own specific needs seems like a better option.

The example is based off the existing one, but updated based on my local tests, which worked upon compile/running:

Expand: database.go
package database

import (
	"log/slog"
	"regexp"

	"github.com/erindatkinson/go-testing/internal/database/migrations"

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

func Test() {
	source.Regex = regexp.MustCompile(`^[a-zA-Z\-_\/]*([0-9]+)_(.*)\.(down|up)\.(.*)$`)
	s := bindata.Resource(migrations.AssetNames(),
		func(name string) ([]byte, error) {
			return migrations.Asset(name)
		})

	instance, err := bindata.WithInstance(s)
	if err != nil {
		slog.Error("source", "error", err)
		return
	}

	m, err := migrate.NewWithSourceInstance("sqlite3", instance, "sqlite3://data/test.sqlite3")
	if err != nil {
		slog.Error("mDriver", "error", err)
		return
	}

	if err = m.Up(); err != nil {
		slog.Error("up", "error", err)
	}
}

@erindatkinson erindatkinson changed the title [Docs] Update go-bindata source readme to include regex overrides for asset names docs(source:go-bindata) update go-bindata source readme to include regex overrides for asset names Sep 29, 2026
@erindatkinson erindatkinson changed the title docs(source:go-bindata) update go-bindata source readme to include regex overrides for asset names docs(source,go-bindata) update go-bindata source readme to include regex overrides for asset names Sep 29, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant