RavenMigrations 3.0.0
See the version list below for details.
Install-Package RavenMigrations -Version 3.0.0
dotnet add package RavenMigrations --version 3.0.0
<PackageReference Include="RavenMigrations" Version="3.0.0" />
paket add RavenMigrations --version 3.0.0
#r "nuget: RavenMigrations, 3.0.0"
// Install RavenMigrations as a Cake Addin
#addin nuget:?package=RavenMigrations&version=3.0.0
// Install RavenMigrations as a Cake Tool
#tool nuget:?package=RavenMigrations&version=3.0.0
Raven Migrations
Quick Start
PM > Install-Package RavenDB.Migrations
Introduction
Raven Migrations is a migration framework for RavenDB to help with common tasks you might have to do over time to your database. The framework API is heavily influenced by Fluent Migrator.
Philosophy
We believe any changes to your domain should be visible in your code and reflected as such. Changing things "on the fly", can lead to issues, where as migrations can be tested and throughly vetted before being exposed into your production environment. With RavenDB testing migrations is super simple since RavenDB supports in memory databases (our test suite is in memory).
This is important, once a migration is in your production environment, NEVER EVER modify it in your code. Treat a migration like a historical record of changes.
Concepts
Every migration has several elements you need to be aware of. Additionally, there are over arching concepts that will help you structure your project to take advantage of this library.
A Migration
A migration looks like the following:
// #1 - specify the migration number
[Migration(1)]
public class First_Migration : Migration // #2 inherit from Migration
{
// #3 Do the migration
public override void Up()
{
using (var session = DocumentStore.OpenSession())
{
session.Store(new TestDocument
{
Id = "TestDocuments/1",
Name = "Khalid Abuhakmeh"
});
session.SaveChanges();
}
}
// #4 optional: undo the migration
public override void Down()
{
using (var session = DocumentStore.OpenSession())
{
session.Delete("TestDocuments/1");
session.SaveChanges();
}
}
}
To run the migrations, you can use Microsoft's Dependency Injection:
public void ConfigureServices(IServiceCollection services)
{
// Add the MigrationRunner into the dependency injection container.
services.AddRavenDbMigrations();
// ...
// Get the migration runner and execute pending migrations.
var migrationRunner = services.BuildServiceProvider().GetRequiredService<MigrationRunner>();
migrationRunner.Run();
}
Not using ASP.NET Core? You can create the runner manually:
// Skip dependency injection and run the migrations.
// Create migration options, using all Migration objects found in the current assembly.
var options = new MigrationOptions();
options.Assemblies.Add(Assembly.GetExecutingAssembly());
// Create a new migration runner. docStore is your RavenDB IDocumentStore. Logger is an ILogger<MigrationRunner>.
var migrationRunner = new MigrationRunner(docStore, options, logger);
migrationRunner.Run();
Full documentation and sample project available on the GitHub repo.
Product | Versions |
---|---|
.NET | net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows |
.NET Core | netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1 |
-
.NETCoreApp 2.1
- Microsoft.Extensions.Configuration (>= 2.1.0)
- Microsoft.Extensions.DependencyInjection (>= 2.1.0)
- Microsoft.Extensions.Logging (>= 2.1.0)
- RavenDB.Client (>= 4.0.5)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
5.0.1 | 2,182 | 3/21/2022 |
5.0.0 | 24,257 | 7/26/2020 |
4.3.0 | 6,589 | 5/4/2020 |
4.1.7 | 25,773 | 1/21/2019 |
4.1.6 | 518 | 1/18/2019 |
4.1.4 | 516 | 1/4/2019 |
4.1.3 | 485 | 1/3/2019 |
4.1.2 | 548 | 11/27/2018 |
4.1.1 | 841 | 10/23/2018 |
4.1.0 | 565 | 10/9/2018 |
4.0.0 | 594 | 9/17/2018 |
3.0.0 | 650 | 7/19/2018 |
2.1.0 | 14,250 | 6/20/2016 |
2.0.0 | 2,265 | 1/22/2016 |
1.2.0 | 7,573 | 5/20/2015 |
1.1.0 | 786 | 5/18/2015 |
1.0.1 | 1,605 | 7/10/2014 |
1.0.0 | 1,000 | 10/28/2013 |
Upgrade to Raven 4, .NET Core 2.1.