Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Safety of ToCatchup? #196

Open
yonderblue opened this issue Jun 22, 2021 · 7 comments
Open

Safety of ToCatchup? #196

yonderblue opened this issue Jun 22, 2021 · 7 comments

Comments

@yonderblue
Copy link

In the commit a8bcd23 a number of years ago it was added to fill in the holes of steps that were not run even though the last migration is past already. How is this safe considering migration steps are not independent?

@rubenv
Copy link
Owner

rubenv commented Jun 22, 2021 via email

@yonderblue
Copy link
Author

yonderblue commented Jun 22, 2021

I don't see that, would you mind pointing me to a spot in the code? Looks like PlanMigration() only has Up steps in the tests?

@rubenv
Copy link
Owner

rubenv commented Jun 22, 2021 via email

@yonderblue
Copy link
Author

For the case of calling PlanMigration with Up and 0, I see:

// apply all the missing migrations
	plannedMigrations, _, err := PlanMigration(s.Db, "sqlite3", migrations, Up, 0)
	c.Assert(err, IsNil)
	c.Assert(plannedMigrations, HasLen, 3)
	c.Assert(plannedMigrations[0].Migration.Id, Equals, "2")
	c.Assert(plannedMigrations[0].Queries[0], Equals, up)
	c.Assert(plannedMigrations[1].Migration.Id, Equals, "4")
	c.Assert(plannedMigrations[1].Queries[0], Equals, up)
	c.Assert(plannedMigrations[2].Migration.Id, Equals, "5")
	c.Assert(plannedMigrations[2].Queries[0], Equals, up)

which only outputs the holes going up. I don't see it going down unless you ask it to go down in the other two cases in that test?

@alexdavid
Copy link

IMO this should be an option since running down migrations to the holes isn't always safe (suppose a column is added and has real production data, the down + up migrations will lose that data).

I'm happy to submit a PR to make this functionality optional.

@rubenv
Copy link
Owner

rubenv commented Jul 8, 2021

IMO this should be an option since running down migrations to the holes isn't always safe

This can really only happen if you don't have a deployment process in place. I understand your concern, but normally this will only apply in development (where multiple people may contribute migrations at the same time).

If your production environment is being deployed to from multiple sources, with multiple different versions (as in: not a linear history), well then you've got much bigger problems on your plate.

I might be overlooking something though, so happy to be proven wrong!

@alexdavid
Copy link

Multiple environments does not solve the problem. It can potentially make the problem less likely to show up, but it is still entirely possible for a feature that introduces a migration to sit in PR for longer than a deploy cycle. If it's not impactful enough to raise red flags when migrating on pre-production environments it could blow out real data in production.

The ability to blow up on out of order migrations is a feature to inform the team that a deploy isn't business as usual and should at the very least be manually investigated.

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

No branches or pull requests

3 participants