Deployment Slots and App Initialization Module in Azure Web Apps

Written by ppolyzos

Software engineer based in beautiful Luxembourg


  1. aitor

    What happen with the migrations when I swap the staging and production slots? Do the run for the production slot when the swap is made? I would like to know which is the best approach for it.

    1. ppolyzos

      Migrations is something that you can control during swap between deployment slots. You may have an application setting which is different between deployment slots and based on its value you can execute Code First Migrations or not.

      Let’s assume you have a setting variable called `MigrateDbToLatestVersion` which is `true` for staging slot and `false` for production slot.
      (Different settings per slot are achieved by checking Slot Setting)

      Then you may decide to run migrations manually from the Application_start method or Global.asax based on the value of that setting.

      if (bool.Parse(ConfigurationManager.AppSettings["MigrateDbToLatestVersion"]))
          var configuration = new DbMigrationsConfiguration();
          var migrator = new DbMigrator(configuration);

      The code above is just to get you an idea of how to manually run the migrations manually. You Learn more about DbMigrator class here

Leave a Comment

Your email address will not be published. Required fields are marked *