migrating-ravens / RavenMigrations

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

Allow the ability to migrate a subset of documents in a collection efficiently #23

Closed daniel-chambers closed 6 years ago

daniel-chambers commented 9 years ago

We needed to be able to migrate a subset of documents efficiently. The current Alter.Collection will:

I've created a new Alter.CollectionSubset method that is similar to Alter.Collection, but it takes a function that also returns a bool to indicate whether or not the document should be saved back to the database. That way, if the document doesn't need migration, it can be skipped.

In the case where you know there's a small subset of documents that need migration, it is inefficient to enumerate through all documents in the collection. I've created a new Alter.DocumentsViaTempIndex method that allows you to specify a Map index definition, a lucene query string to query it with, and a migrator callback function like Alter.CollectionSubset. The method automatically creates an index, waits for it to not be stale, performs your migration based on the returned documents, then deletes the index when you're done.

This pull request is based on top of changes in pull request #17, so that'd need to be merged first before merging this one.

absynce commented 8 years ago

@daniel-chambers I like this. If the merge conflicts are resolved, this could be merged in...

daniel-chambers commented 8 years ago

Sorry, I thought I might have time this weekend to have a look at this again, but I haven't had it. It's been almost a year since I touched RavenDB, so I'll have to sharpen my tools again.