How do you tell if your migrations are up to date with migratordotnet?

感情迁移 提交于 2019-12-08 07:10:27

问题


I'm using migratordotnet to manage my database migrations. I'm running them on application setup like this, but I would also like to check on application startup that the migrations are up to date, and provide the option to migrate to latest. How do I tell if there are available migrations that need to be applied? I see that I can get the migrations that were applied like this

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

I like to do something like this:

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

回答1:


I found the way. Looking at migratordotnet source code helps.

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


来源:https://stackoverflow.com/questions/894120/how-do-you-tell-if-your-migrations-are-up-to-date-with-migratordotnet

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!