Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Collection migrations #2

Merged
merged 6 commits into from
Oct 25, 2013
Merged

Conversation

seankearon
Copy link
Contributor

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 added a commit that referenced this pull request Oct 25, 2013
Collection migrations, thanks Sean Kearon!
@khalidabuhakmeh khalidabuhakmeh merged commit 336d47c into migrating-ravens:master Oct 25, 2013
@khalidabuhakmeh
Copy link
Contributor

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

@seankearon
Copy link
Contributor Author

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
Copy link
Contributor

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

What do you mean by that?

@khalidabuhakmeh
Copy link
Contributor

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

@seankearon
Copy link
Contributor Author

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
Copy link
Contributor

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
Copy link
Contributor Author

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.

:)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants