migrating-ravens / RavenMigrations

A small migrations framework to help you manage your RavenDB Instance.
MIT License
53 stars 24 forks source link

Updating collection metadata #3

Closed seankearon closed 11 years ago

seankearon commented 11 years ago

Kahlid

I've added some capability to update collection metadata. This allows moving a class to another namespace and/or assembly. Also added a utility to wait for indexing in migrations.

Looks like this in use:

public class AlterCollectionMigration : Migration
{
    public override void Down()
    {
        Alter.Metadata.RavenClrType("Person1s", "RavenMigrations.Tests.Person1, RavenMigrations.Tests");
        WaitForIndexing();
        Alter.Collection("Person1s", JoinFirstNameAndLastNameIntoName);
    }

    public override void Up()
    {
        Alter.Metadata.RavenClrType("Person1s", "RavenMigrations.Tests.Person2, RavenMigrations.Tests");
        WaitForIndexing();
        Alter.Collection("Person1s", SplitNameToFirstNameAndLastName);
    }

    private void JoinFirstNameAndLastNameIntoName(RavenJObject obj)
    {
        var first = obj.Value<string>("FirstName");
        var last = obj.Value<string>("LastName");

        obj["Name"] = first + " " + last;
        obj.Remove("FirstName");
        obj.Remove("LastName");
    }

    private void SplitNameToFirstNameAndLastName(RavenJObject obj)
    {
        var name = obj.Value<string>("Name");
        if (!string.IsNullOrEmpty(name))
        {
            obj["FirstName"] = name.Split(' ')[0];
            obj["LastName"] = name.Split(' ')[1];
        }
        obj.Remove("Name");
    }
}

I'd be happy to document this too. Let me know when you've got a sketch of how you want the documentation to look.

BTW: I'm going to be out of contact for a couple of days. Back on Wednesday.

seankearon commented 11 years ago

Cancel this for now - see: https://github.com/khalidabuhakmeh/RavenMigrations/issues/4