[英]How to run migration on only specific database name when using fluentMigrator
[英]How do I run a profile migration using FluentMigrator?
我使用FluentMigrator来管理我的数据库更改,我执行我的迁移,如下所示:
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);
我无法弄清楚的是,如何为特定的配置文件执行迁移?
因此,鉴于我的迁移器具有如下属性:
[Profile("DevMigration")]
public class DevMigration : FluentMigrator.Migration
{
我尝试了几种变体:
runner.ProfileLoader.FindProfilesIn(assembly, "DevMigrator");
runner.ApplyProfiles();
但是我没有接近,有没有人知道如何使用跑步者执行配置文件迁移?
尝试在迁移上下文中设置配置文件,然后将其传递给迁移运行器,如下所示:
IRunnerContext migrationContext = new RunnerContext(announcer);
migrationContext.Profile = "DevMigrator"
概要文件加载器方法FindProfilesIn
仅返回具有概要文件的迁移。 RunnerContext
的构造RunnerContext
加载ProfileLoader
,默认情况下会在上下文中加载指定配置文件的迁移(我认为这默认为null,因此没有配置文件迁移)。
您不需要手动调用ApplyProfiles
方法,因为在MigrateUp(bool)
方法中调用了该方法。
对于那些阅读它并且使用进程内迁移器的人来说,就像在这里的文档中所示。 在这种情况下指定配置文件名称的方法是在ServiceCollection上添加另一个Configure调用,如下所示:
.Configure<RunnerOptions>(cfg =>
{
cfg.Profile = "DevMigration";
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.