It seems like you're using an older browser. Things might not work as expected.

Avensia Storefront comes with a built-in migration system that supports running migrations up or down in sequence. This migration system is built for both internal and external use.

Examples of migration usages:

  • Creating the CMS tree structure so you don't have to do that manually on every installation.
  • Creating database tables.
  • Running one-time configuration that needs to be done in run-time.

The migration runner is located in /Episerver > CMS > Admin > [Avensia Storefront] Tools > Migration.

How migrations work

Migrations can be execute by a signed in administrator in Episerver. To execute a migration you need to click on the “Up” button, this will execute the code in the Up method of your migration. If your code returns a successful response, the migration will be considered “done”. Migrations can only be executed in a sequence where the lowest number of "Order" will be executed first. The button “Up” is only enabled if your migration hasn't been run before and any migration with lower "Order" is already "Done". If you for some reason want to undo the work your migration has done, you can click on the “Down” button. For the “Down” button to be enabled the migration must have been run before and there cannot be any migration with higher order that has the status “Done”.

How to implement a migration

To create a new migration you must create a new class that inherits Avensia.Storefront.Connector.Common.Migration.IMigration.

public class MyNewMigration : IMigration

The interface IMigration requires you to implement two methods; bool Up() and bool Down()and three properties; IdOrder and DisplayName

public class MyNewMigration : IMigration
{
    public bool Up()
    {
        // Code that will be executed when you click on the “Up” button.
        return true; // If your migration doesn't return "true" the status won't be updated
    }

    public bool Down()
    {
        // Code that will be executed when you click on the “Down” button.
        return true; // If your migration doesn't return "true" the status won't be updated
    }

    public Guid Id => new Guid("598A91B7-0065-4A33-98BD-1473CC4188BA");  // The unique ID of this migration
    public int Order => 1200; // What order the migration should be execute in.
    public string DisplayName => "My new migration"; // What text should be displayed in the migration tool
}

In the class Avensia.Storefront.Starter.Infrastructure.ShopDependencyRegistration you must register your new migration so the migration runner can find it.

In the method public void RegisterDependenciesInGlobalContainer(ConfigurationExpression configuration) add the following.

configuration.For<IMigration>().Singleton().Add<MyNewMigration>();

Thats it, your new migration should now show up under [Avensia Storefront] Tools > Migration and can be executed by clicking "Up".