migrating-ravens / RavenMigrations

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

Collection migrations #2

Closed seankearon closed 10 years ago

seankearon commented 10 years ago

Added the ability to migrate a collection document-by-document as the JObject level. Makes it easier to approach structural changes to the documents.

[Migration(1, "CollectionDocumentMigration")]
public class CollectionDocumentMigration : Migration
{
    public override void Down()
    {
        Alter.Collection("People", JoinFirstNameAndLastNameIntoName);
    }

    public override void Up()
    {
        Alter.Collection("People", 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");
    }
}
khalidabuhakmeh commented 10 years ago

Would you like me to push this on to NuGet at some point, or are we going to add more features?

seankearon commented 10 years ago

I really do think this is ready for Nuget - it was ready on your first drop! The only area I'm wondering about is having backup/recovery in there. I have a biased view as I generally use Raven embedded on the desktop and the migration runs remotely. That said, you just don't have to migrate as much with Raven.

So, yeah - publish this sucker!!! :)

khalidabuhakmeh commented 10 years ago

The only area I'm wondering about is having backup/recovery in there.

What do you mean by that?

khalidabuhakmeh commented 10 years ago

Oh, before we release to NuGet I think I need to write the ReadMe, any change you want to help there?

seankearon commented 10 years ago

Backup/recovery - I was wondering if making Smuggler available at time of migration is worth doing. Something like:

Runner.BackupTo("c:\backups").Run(store);

Not sure about recovery - don't think that could be automated really!

Documentation - I'd be happy to help out, but my availability is pretty sporadic to say the least! I'm certainly happy to document the parts I've added and help fleshing out any topics you want to point me at.

khalidabuhakmeh commented 10 years ago

backup

Hmm... I don't know if running a backup during a migration makes sense. Since you'd probably want a backup to happen on an interval, not just once ever right?

documentation

I'll get is started when I find the time, then I'll push to NuGet.

Thanks

Thanks for helping out and using this, I appreciate it and love working with other devs.

seankearon commented 10 years ago

You're welcome - glad to be able to help. I really like the migrations and will be using them, so I'll hope to give some more things back as and when I can.

As for backup - I always like to take a backup before I make any changes. My Raven app is on desktops, so anything can go wrong (and does!). It's always good to have a full backup at the time. I'll spin something up and let you have a look to see what you think.

:)