migrating-ravens / RavenMigrations

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

Better API syntax for Alter #4

Closed seankearon closed 11 years ago

seankearon commented 11 years ago

Thinking on the syntax in the commits I've just made to my fork, I think the API could be significantly improved (by borrowing from Ayende's API - imitation being the sincerest form of flattery!).

I had proposed this to allow modifying metadata and documents from a collection:

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

The following would be better to use and more consistent with Raven:

public override void Up()
{
    Alter.Collection("People", SplitNameToFirstNameAndLastName);
}

private void SplitNameToFirstNameAndLastName(RavenJObject doc, RavenJObject metadata)
{
    var first = doc.Value<string>("FirstName");
    var last = doc.Value<string>("LastName");

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

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

So, you have easy access to the metadata and to the entity in one method. Similar to here:

http://ayende.com/blog/66563/ravendb-migrations-rolling-updates

What do you think?

seankearon commented 11 years ago

Have updated my fork. You now have a pull request! :)

khalidabuhakmeh commented 11 years ago

Deployed to NuGet under RavenMigrations. Also started the Readme :)