Running migrations from multiple assemblies, at once?

420 views
Skip to first unread message

Jeff Dege

unread,
Jan 8, 2015, 12:21:12 PM1/8/15
to fluentmigrato...@googlegroups.com
I have a number of assemblies containing migrations. I have written my own migration runner application, that constructs a MigrationRunner() for each assembly:

var migrationContext = new RunnerContext(announcer);

var migrationOptions = new MigrationOptions
{
    PreviewOnly = this.options.outputSql,
        Timeout = this.options.timeout
};

var factory = new FluentMigrator.Runner.Processors.SqlServer.SqlServer2012ProcessorFactory();
var processor = factory.Create(this.options.connectionString, announcer, migrationOptions);
var runner = new MigrationRunner(this.assembly, migrationContext, processor);

runner.MigrateUp(true);
And this is working fine, unless I set my outputSql option.

My implementation team needs to be able to validate the SQL, before they use the tool to update the database. So, when I set my outputSql option, I set PreviewOnly in my MigrationOptions, and I use an announcer that writes the SQL to a file.

My problem, when I run migrations for the first time on a new database, is that FluentMigrator starts by running migrations that create and populate the VersionInfo table. Because we're running PreviewOnly and ShowSql, we display the SQL without updating the database.

And because we're running three different MigrationRunners, independently, for each of the three assemblies, and none of them are actually changing the database, the SQL to create and populate the VersionInfo table is included three times.

It seems to me that it would make more sense to allow a MigrationRunner object to be constructed with an array of assemblies, instead of only with one.

There's a larger issue here - migrations are run in order, but only within a single assembly. If I'm running migrations from multiple assemblies, the newer migrations in the first assembly are run before the older migrations in the second. In my case, that's not an issue - the migrations are in separate assemblies because they access different groups of tables that don't have dependencies between them, but I can see how that might cause problems.

Is there a way to construct a MigrationRunner to run migrations from multiple assemblies at once?

da...@sabrecreations.com

unread,
Sep 11, 2015, 1:37:14 AM9/11/15
to FluentMigrator Google Group
I had a similar problem where I needed to run migrations from a few different assemblies in a single queue.

Check out my answer to a post on stackoverflow where I've pasted code that I wrote where you can pass in multiple assemblies and it will combine and migrate for you.

http://stackoverflow.com/questions/25239992/using-multiple-fluentmigrator-assemblies-on-same-database/28575440#28575440

Dave
Reply all
Reply to author
Forward
0 new messages