private DbMigrator GetDbMigrator(Assembly assembly, string configurationType, DbConnectionInfo targetDatabase = null)
{
var targetAssemblyConfig = (DbMigrationsConfiguration)assembly.CreateInstance(configurationType);
if (targetAssemblyConfig == null)
{
Log.Warning("The assembly at the path {assemblyPath} does not contain " +
"the migration configuration type {configType}. This may be due to a " +
"migration from or to a version where that config type doesn't exist. " +
"A target migration of '0' will be used, which will rollback all migrations.", assembly.CodeBase, configurationType);
}
else
{
if (targetDatabase != null)
{
targetAssemblyConfig.TargetDatabase = targetDatabase;
}
else
{
//Force local db to allow for meta data resolution
//We can probably get rid of this by implementing:
//http://stackoverflow.com/questions/4741499/how-to-configure-providermanifesttoken-for-ef-code-first
targetAssemblyConfig.TargetDatabase = m_ConnectionInfoBuilder.Build(new DatabaseEndpoint()
{
ServerName = @"(localdb)\mssqllocaldb"
}, AuthenticationMode.Integrated);
}
}
return targetAssemblyConfig != null ? new DbMigrator(targetAssemblyConfig) : null;
}