Migratordotnet : How to check if a migration is pending?

296 views Asked by At

I want stop my Build process through MSBuild, if there is pending migrations.

But I don't want to trigger the Migrate target while building my project.

So, How can I check only pending migrations with Migratordotnet ?
I just want to use it as a flag to stop my Build process.. !!

Thanks in advance !

2

There are 2 answers

7
Sumo On BEST ANSWER

Check this other question which shows some code to allow you to check if there are pending migrations. It could be quite possible to have a target set up in MSBuild to run this code and exit from the target if it returns one or more migrations available.

Here's some basic code for a console app that pulls together the code of the other question. It simply writes a message to the console window if migrations are available or not. You'll need to expand it into what your needs are, but it should work. TestMigration1 should be replaced by one of your migration classes in the assembly where your migrations are. You'll obviously need to make a reference to that project from your console app.

internal class Program {
    private static void Main(string[] args) {
        Assembly asm = Assembly.GetAssembly(typeof (TestMigration1));
        const string myConnectionString =
            "Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;";
        ITransformationProvider provider = ProviderFactory.Create("SqlServer", myConnectionString);
        var loader = new MigrationLoader(provider, asm, false);
        List<long> availableMigrations = loader.GetAvailableMigrations();

        Console.WriteLine(availableMigrations.Count > 0 ? "Migrations available" : "No migrations");
    }
}
1
Yugal Jindle On

I think that it is not supported by Migratordotnet !

They only provide 1 Target for MSBuild, that aims at executing the migrations.. so there is no other way in which you could interact with it to check the migrations.