khalidabuhakmeh/RavenMigrations — pull request #5 by seankearon (2013-10-27 18:42:49+00:00)
Title: Added metadata migration capability to document migrations

Alter.Collection now allows direct access to metadata, as follows:

public class AlterCollectionMigration : Migration
{
public override void Down()
{
Alter.Collection("Person1s", MigratePerson2ToPerson1);
}

public override void Up()
{
Alter.Collection("Person1s", MigratePerson1ToPerson2);
}

private void MigratePerson2ToPerson1(RavenJObject doc, RavenJObject metadata)
{
var first = doc.Value("FirstName");
var last = doc.Value("LastName");

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

metadata[Constants.RavenClrType] = "RavenMigrations.Tests.Person1, RavenMigrations.Tests";
}

private void MigratePerson1ToPerson2(RavenJObject doc, RavenJObject metadata)
{
var name = doc.Value("Name");
if (!string.IsNullOrEmpty(name))
{
doc["FirstName"] = name.Split(' ')[0];
doc["LastName"] = name.Split(' ')[1];
}
doc.Remove("Name");

metadata[Constants.RavenClrType] = "RavenMigrations.Tests.Person2, RavenMigrations.Tests";
}
}