khalidabuhakmeh/RavenMigrations — pull request #3 by seankearon (2013-10-27 17:23:30+00:00)
Title: Updating collection metadata

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("FirstName");
var last = obj.Value("LastName");

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

private void SplitNameToFirstNameAndLastName(RavenJObject obj)
{
var name = obj.Value("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.