Home > Uncategorized > Upgrading to RavenDb 3.0 from 2.5

Upgrading to RavenDb 3.0 from 2.5

Haven’t blogged in a long time but thought I’d quickly share my experience upgrading Rowing in Motion Analytics from RavenDb to RavenDb 3.0.

The upgrade was not as painless as anticipated and we hit quite a few surprises along the way.

Web Api Upgrade Mess

By far the biggest problem we had is that the RavenDb Server migrated to using Asp.Net Web API in 3.0 and this massively clashes with projects using WebApi themselves.

This only affected our unit and acceptance tests which use an in-memory embedded instance of RavenDb, but still it forced us to upgrade to Web Api 2.2 throughout our full solution. We only discovered this when upgrading the RavenDb Nuget Packages and got presented with the notice linked above. At least we got that notice but it would’ve been nice of the RavenDb team to document this in the release notes of 3.0.

Since we were still using WebApi v1, the upgrade required considerable work (e.g. Authentication is now moved into the HttpRequestContext and no longer done via Thread.CurrentPrincipal). DotNetOpenAuth doesn’t work with WebApi 2.2 either, only the current 5.0 alpha 3 release does…

Once upgrade to Web Api 2.2, you will also need to ensure the RavenDb controllers will not be routed to by providing a custom IAssembliesResolver that excludes the RavenDb assemblies, e.g.:


config.Services.Replace( typeof( IAssembliesResolver ), new ThisAssemblyOnlyResolver() );

class ThisAssemblyOnlyResolver : IAssembliesResolver
{
public ICollection GetAssemblies()
{
return new List() { typeof( WebApiConfiguration ).Assembly };
}
}

Api Changes

There’s been a couple of API changes to the RavenDb.Client that were relatively easy to adapt to:

  • .AsProjection() was removed, replaced by .ProjectFromIndexFieldsInto()
  • .LuceneQuery() was removed, replaced by .DocumentQuery()
  • Session.Advanced.Defer() behaves differently and will now throw if multiple deferred operations on a document are pending on a session (e.g. a delete followed by a store)
  • Formatting of document Ids in exception messages has changed to all lowercase, even when the document id itself has a MixedCase prefix. We need this in a few places to handle concurrency exceptions (I know relying on exception strings is a bad idea, but it’s currently the only way Raven will tell you about the source of a conflict which has a meaning in our domain)

Subtly Breaking Changes

There has also been at least onesubtle change that may break your existing code. It appears RavenDb has changed the ObjectCreationHandling policy of the Newtonsoft.Json library it internally uses for serializing/deserializing documents to “Auto”. If you have objects with collection properties (IEnumerable<T> is already enough) you may suddenly find that a deserialized object simply appends the deserialized property instead of replacing it.

You can work around this by doing:

store.Conventions.CustomizeJsonSerializer = x =>
{
x.ObjectCreationHandling = Raven.Imports.Newtonsoft.Json.ObjectCreationHandling.Replace;
};

Deployment Changes

The RavenDb.Embedded NuGet package is no longer necessary and can be removed safely.

Advertisements
Categories: Uncategorized
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: