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

Run Missing Migrations #25

Open
speeddm opened this issue Aug 17, 2017 · 8 comments
Open

Run Missing Migrations #25

speeddm opened this issue Aug 17, 2017 · 8 comments

Comments

@speeddm
Copy link

speeddm commented Aug 17, 2017

Is it possible / would it be possible to allow Simple.Migrations to, when migrating to the latest version, run any migration it has not yet run. This would be useful in our scenario where we are developing as a team on various branches with our own local databases and using a timestamp to populate the version on each migration.

So if a migration gets merged into the master branch but a user has already run the migrator on their database then the migrations contained in the branch that got merged in are not run. I understand that this runs migrations out of order, but can be very useful in a team environment and when it comes time to run the migration in any deployed environment then the order is always going to be preserved.

@canton7
Copy link
Owner

canton7 commented Aug 17, 2017

Sounds reasonable.

I can see this working in a number of different ways:

  1. Apply all missing migrations before the current migration
  2. Un-apply all migrations since the first missing migration, then re-apply everything
  3. Either of the above, but going to a specific migration in the future (or the latest migration).

@canton7
Copy link
Owner

canton7 commented Aug 20, 2017

Thinking about this, I think it makes sense to add a "skipped migration behaviour" parameter to the commands which migrate up or down, which can take the values "throw an exception", "apply out of order", or "rewind to the first missing migration and reapply all since". The ConsoleRunner will accept a flag to set the behaviour, and you can set the default programmatically. I think that's enough to cover your use-case which being fairly generic..

@canton7
Copy link
Owner

canton7 commented Aug 20, 2017

Actually, the complication is that I don't currently keep track of the set of migrations which have been applied. The version table forms a history of which migration was applied when, so I guess I can walk that, but I don't currently require that the DatabaseProviders use the version table in that way.

@canton7
Copy link
Owner

canton7 commented Aug 21, 2017

Of course, it would be possible to introduce another table which tracks the currently-applied migrations, but:

  1. I have to cope with people who are running Simple.Migrations and don't have this table. That's possible, but I think it's going to be pretty tricky. If I get it wrong, things might start failing in production for people.
  2. I'm cluttering up the user's schema with additional tables at this point

It's almost as if I need to track the version of the table used by Simple.Migrations as well as the current migration...

@canton7
Copy link
Owner

canton7 commented Aug 21, 2017

Playing devil's advocate, is there a reason why migrating down to 0 and back to the latest version won't work for you?

@canton7 canton7 closed this as completed Aug 21, 2017
@canton7 canton7 reopened this Aug 21, 2017
@speeddm
Copy link
Author

speeddm commented Aug 27, 2017

We don't tend to use the down section when writing migrations. And with the branches I can still foresee issues - when you pull in a branch that contains other migrations wont the migrator try and apply the down migration on migrations that have never had actually been applied.

Generally how we operate (and this may not be the way all teams do or indeed should) is that we simply run the migration to get our local DB to the latest point (including any migrations that have come in from other branches) and if we do require a certain version of the DB for debugging etc then we would look at using a backup (obviously not ideal).

Isn't there enough information in the VersionInfo table to work out which migrations have already been applied?

@canton7
Copy link
Owner

canton7 commented Aug 28, 2017 via email

@gregbrant2
Copy link

I realise this is an old ticket but I'm about 99.9999% in the same use case as @speeddm.

A thought regarding the connundrum of does the provider support the VersionInfo table. Could you introduce a property into the provider base type bool SupportsVersionTable {get;set;} = false; and so the provider author has to opt-in setting it true in their constructor, and hopefully reading the docs and understanding why they've set it true, and implementing the appropriate functionality. Then, if SkippedMigrationBehaviour is set to ApplyOutOfOrder" or anything else that relies on SupportsVersionTable, you could pre-flight check that SupportsVersionTable == true and throw if it's not supported.

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