Force rerunning a previous migration with FluentMigrator
Asked Answered
C

2

6

How can I force a 3 month old migration to re-run when I've got 60 or 70 migrations in between and I don't want to/can't do a full rollback?

Apparently supplying the --version parameter of the value that I want it to re-run doesn't work, and neither does just deleting the value from the VersionInfo table (both having been done together also doesn't seem to have any benefit).

Is there a way to have FluentMigrator re-run a single migration from a few months ago? Am I pebkacking the problem?

Command answered 4/12, 2013 at 17:34 Comment(0)
W
0

I'm not sure (try this with careful in in a non production environment), but you can cheat to fluentmigrator altering the versionInfo table.

  1. First, use migrate --listmigrations to get all the available migrations in your assembly
  2. Add to versionInfo those migrations that you want to NOT execuete

  3. Finally, ensure that the migrations you want to execute ARE NOT in the versionInfo table.

Of course, it would be a good idea to do an export or backup of the versionInfo table prior to any change.

Whitcomb answered 15/11, 2015 at 19:28 Comment(0)
P
-1

For future readers,

FluentMigrator will look at the latest migration AppliedOn date and then continue from there, so if your migration is a few months old it won't re-run the migration even if you remove that entry from the versioninfo table.

What you can do to cheat is to add the migration again, but this time add with defensive coding. i.e, if the changes that you wanted to apply are already applied then don't try to do that again. I don't know how your migration look like but here's an example of what i mean by defensive coding:

IF COL_LENGTH('FollowOnProduct', 'ProductType') IS NULL
BEGIN
    ALTER TABLE FollowOnProduct
        ADD ProductType VARCHAR(64) NULL 
END

this will not alter table and try to add the column if ProductType is already there.

Disclaimer: this is a hack, test your migrations on dev/test before running them on uat/production, in the perfect world we shouldn't have to do these things, but we're not living in the perfect world.

Punctuate answered 3/10, 2018 at 12:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.