Shaddix
Shaddix

Reputation: 6109

RavenDB schema migrations

I want to change my RavenDB "schema" and perform a Migration at startup of ASP.Net MVC web app.

Patching mechanism seems to fit the purpose, and I try to use it like:

store.DatabaseCommands.UpdateByIndex(
    "Raven/DocumentsByEntityName",
    new IndexQuery
    {
        Query = "Tag:LogEntries",
    },
    new ScriptedPatchRequest()
    {
        Script = @"
                    this.IsDeleted = false;
                "
    }
).WaitForCompletion();

The problem is, that Patch will simply throw exception if the index is stale. But I really need to be sure that Migration was performed before continue to run the app. Are there better alternatives than wrapping it in something like:

while (true)
{
    try
    {
        RunPatch();
        break;
    }
    catch (Exception)
    {
    }
}

With Entity Framework or NHibernate (FluentMigrations) it's easy to write a Migration class, assign a Version to it, and then needed Migrations will be executed automatically in proper order.

Is there a similar built-in mechanism for Raven? Or any known best-practices for that?

Upvotes: 4

Views: 1099

Answers (1)

Sean Kearon
Sean Kearon

Reputation: 11427

Here's an answer, albeit 6 years after you asked! There is the RavenMigrations project on GitHub here:

https://github.com/migrating-ravens/RavenMigrations

This is a migration framework for RavenDB, similar to those that you will find for relational databases.

Upvotes: 3

Related Questions