您如何判断您的迁移是否与migratordotnet保持同步?

时间:2009-05-21 17:31:37

标签: .net sql-server migration migratordotnet

我正在使用migratordotnet来管理我的数据库迁移。我是running them on application setup like this,但我还想检查应用程序启动时迁移是否是最新的,并提供迁移到最新版本的选项。如何判断是否需要应用可用的迁移?我看到我可以获得像这样应用的迁移

var asm = Assembly.GetAssembly(typeof(Migration_0001));
var migrator = new Migrator.Migrator("SqlServer", setupInfo.DatabaseConnectionString, asm);
var applied = migrator.AppliedMigrations;

我喜欢这样做:

var available = migrator.AvailableMigrations; //this property does not exist.

1 个答案:

答案 0 :(得分:2)

我找到了方法。查看migratordotnet源代码有帮助。

var provider = ProviderFactory.Create("SqlServer", myConnectionString);
var loader = new MigrationLoader(provider, asm, false);
var availableMigrations = loader.GetAvailableMigrations();