goose icon indicating copy to clipboard operation
goose copied to clipboard

filter out registered migrations when run against a directory without them

Open prabhu-tyke opened this issue 1 year ago • 1 comments

When running a migration against a particular directory without go migrations, getting the registered migrations too. How to filter those out? https://github.com/pressly/goose/pull/588, I see this pr addresses this but not able to make it work.

My directory structure:

migrations: ----ad-hoc: --------1000_1000.go ----0001_1.sql ----0002_2.sql

in my main.go have imported the ad-hoc package, in .go file have done goose.AddMigrationNoTxContext(). I run my binary against ./migrations where there are only sql files. Is there a way around this?

seeing this:

	var sources []source
	for _, fullpath := range goFiles {
		v, err := NumericComponent(fullpath)
		if err != nil {
			continue // Skip any files that don't have version prefix.
		}
		if strings.HasSuffix(fullpath, "_test.go") {
			continue // Skip Go test files.
		}
		if versionFilter(v, current, target) {
			sources = append(sources, source{
				fullpath: fullpath,
				version:  v,
			})
		}
	}
	var (
		migrations Migrations
	)
	if len(sources) > 0 {
		for _, s := range sources {
			migration, ok := registeredGoMigrations[s.version]
			if ok {
				migrations = append(migrations, migration)
			} 

prabhu-tyke avatar Dec 10 '24 10:12 prabhu-tyke

@prabhu-tyke have you found a workaround?

I did using goose.ResetGlobalMigrations() and goose.SetGlobalMigrations([]goose.Migration) but it's far from ideal

4xposed avatar May 09 '25 15:05 4xposed