rubenv / rubenv/sql-migrate

Weird Behavior with Migrations From Multiple Directories

Open
#85 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Go
Stars
3.4k
Forks
292
PR merge metrics
No merged PRs in 30d

Description

Scenario: I have one directory with a schema migration. I have a second directory which contains a migration for setting up integration test data.

What happens: The schema migration is run but the test data migration is not. It just ignores it. If I truncate the migrations table between the two migration runs the second will work. It seems like the tool is ignoring the name of migration and just assuming that because 1 migration has been run there must be nothing to do.

AFAIK this bit of code is at fault:

migrate.go:407

	var index = -1
	if current != "" {
		for index < len(migrations)-1 {
			index++
			if migrations[index].Id == current {
				break
			}
		}
	}

It will go though the existing migrations looking for the start point but never find it meaning nothing is applied. I think to solve this in general it would need to be a bit smarter and work based on the list of known migrations. So for example down limited to 2 wouldn't just take the two off the top, it would down the last two of the discovered migrations (even if there are newer ones in the db). It might not even be worthwhile since I guess very few people would want to have multiple directories of migrations.

Either way it could be worth noting in the README there is limitation here.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at migrate.go:407 and trace how the current migration ID is matched against migrations discovered from multiple directories. Reproduce the scenario with separate schema and integration-test-data directories, then verify that the intended migration behavior is covered; if the limitation remains, update the README to document it.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
database
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.