Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 429
Shaddix Avatar asked Nov 03 '25 06:11

Shaddix


1 Answers

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.

like image 157
Sean Kearon Avatar answered Nov 04 '25 20:11

Sean Kearon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!