8

In a multitenant RavenDB application (one database per tenant, and one 'overview' database with general tenant data), what would be the index creation strategy? (asp.net mvc)

In a simple (not multitenant) application, you can create the indexes in global.asax.

  • Theoretically you could query for each tenant, and create the indexes for every tenant, in global.asax. But I guess that would be a huge performace hit when the amount of tenants go up...
  • Creating the indexes on tenant creation is not possible, as existing tenants should be able to get new indexes on updates.

So what would be the best practice as for how and when to create these indexes?

Tom Deleu
  • 1,177
  • 1
  • 15
  • 29

1 Answers1

10

You can use this method on application startup, no worries about perf.

public static void CreateIndexesForDatabases(Assembly assemblyToScanForIndexingTasks, IDocumentStore documentStore, string[] databases)
{
    var catalog = new CompositionContainer(new AssemblyCatalog(assemblyToScanForIndexingTasks));
    foreach (var database in databases)
    {
        IndexCreation.CreateIndexes(catalog, documentStore.DatabaseCommands.ForDatabase(database), documentStore.Conventions);
    }
}

just don't forget to include Raven.Client.Extensions

Daniel Lang
  • 6,819
  • 4
  • 28
  • 54