I am using FluentMigrator to manage my database changes, I execute my migrations like this:
const string connectionString = @"Data Source=localhost, 1433;Initial Catalog=testdb;Integrated Security=SSPI;";
Announcer announcer = new TextWriterAnnouncer(s => System.Diagnostics.Debug.WriteLine(s));
announcer.ShowSql = true;
Assembly assembly = Assembly.GetAssembly(typeof (MigrationMarker));
IRunnerContext migrationContext = new RunnerContext(announcer);
var options = new ProcessorOptions
{
PreviewOnly = false, // set to true to see the SQL
Timeout = 60
};
var factory = new SqlServer2008ProcessorFactory();
IMigrationProcessor processor = factory.Create(connectionString, announcer, options);
var runner = new MigrationRunner(assembly, migrationContext, processor);
runner.MigrateUp(true);
What I can't figure out though, is how to execute a migration for a specific profile?
So given that my migrator has an attribute like this:
[Profile("DevMigration")]
public class DevMigration : FluentMigrator.Migration
{
I have tried a few variations of:
runner.ProfileLoader.FindProfilesIn(assembly, "DevMigrator");
runner.ApplyProfiles();
But I'm not getting any closer, does anyone know how I can execute a profile migration using the runner?
Try setting the profiles on the migration context before being passed to the migration runner like this:
IRunnerContext migrationContext = new RunnerContext(announcer);
migrationContext.Profile = "DevMigrator"
The profile loader method FindProfilesIn
only returns the migrations with the profile. The constructor of the RunnerContext
loads the ProfileLoader
which by default loads the migrations for the specified profile in the context (I think this defaults to null therefore having no profile migrations).
You shouldn't need to manually call the ApplyProfiles
method as this is called in the MigrateUp(bool)
method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With