Moving to property groups

As I mentioned in the previous post I’ve recently “moved” to using property groups. Since the site was already live I already had a bunch of properties that were to be replaced with the group ones. If we simplify reality for a bit we can imagine that the page in it’s current state had a bunch of properties in this vein: PlanningProperty1 etc. Property group properties are defined using both the name of the property group on the page (called the hierarchy) as well as the actual property name. Since my property group was called Review the new name of the properties on the page would be Review-PlanningProperty1.

Migration

So the situation I was in was basically this: On my site I had a property called PlanningProperty1. Next time I build the site the corresponding property group property (called Review-PlanningProperty1) would be added to the page. But since the PlanningProperty1 already had data associated with it I couldn’t remove it since I needed to somehow shuffle that data to the new property. Luckily for me Joel added something called Migration to PageTypeBuilder 2. So to update the site to use property groups I did the following

Add a migration script

This migration script runs before PTB and here I change the name of the current properties to the new I know they are going to have when using property groups for all the relevant pages

public class Migration1 : Migration
{
    public override void Execute()
    {
        PageType("ArticlePage")
            .PageDefinition("PlanningProperty1")
            .Rename("Review-PlanningProperty1");
    }
}

PageTypeBuilder

When PTB tries to sync the properties it will see that the Review-PlanningProperty1 already exists and will happily “ignore” it. So in essence I have moved to using property groups without loosing any of the data of the old properties without actually doing any work.

Profit!

And There Was Much Rejoicing!

  • Roman

    Hi,

    Do you know – can the migrations be used to migrate from PropertyGroup in PageTypeBuilder (in EPiServer 6) to BlockContent (in EPiServer 7)?

    Thanks

    • http://www.popkram.com Stefan Forsberg

      Hi Roman,
      as far as I know there’s no easy way to migrate between PropertyGroups and BlockContent using Migrations as the underlying storage of the data differs quite substantially.