Mongrow 0.0.12

dotnet add package Mongrow --version 0.0.12                
NuGet\Install-Package Mongrow -Version 0.0.12                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Mongrow" Version="0.0.12" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Mongrow --version 0.0.12                
#r "nuget: Mongrow, 0.0.12"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Mongrow as a Cake Addin
#addin nuget:?package=Mongrow&version=0.0.12

// Install Mongrow as a Cake Tool
#tool nuget:?package=Mongrow&version=0.0.12                

Mongrow

It's a MongoDB migration helper.

With this, you can write classes that implement steps to migrate a MongoDB database.

What do steps look like?

Like this:

[Step(1)]
public class AddAdminUser : IStep
{
    public async Task Execute(IMongoDatabase database)
    {
        var users = database.GetCollection<BsonDocument>("users");

        var adminUser = new
        {
            _id = Guid.NewGuid().ToString(),
            uid = "user1",
            claims = new[]
            {
                new {type = ClaimTypes.Email, value = "admin@whatever.com"},
                new {type = ClaimTypes.Role, value = "admin"},
            }
        };

        await users.InsertOneAsync(adminUser.ToBsonDocument());
    }
}

and then you execute it like this:

var migrator = new Migrator(
    connectionString: "mongodb://mongohost01/MyDatabase",
    steps: GetSteps.FromAssemblyOf<AddAdminUser>()
);

migrator.Execute();

How to make robust steps

While steps are just C# code, and you can do anything you want in there to the passed-in IMongoDatabase, you are encouraged to write steps that do not change along with the rest of your code.

This means that you most likely want to use BsonDocument, magic strings, and anonymous types throughout.

Wouldn't want a rename of one of your C# classes to mess up how all of your existing migrations work.

Parallel execution

A distributed lock is used to coordinate execution, so Mongrow will never execute migrations concurrently.

How to number the steps

Steps are identified by a number and a "branch specification". The branch specification allows for co-existence of steps with the same number, thus escaping a global lock on the number sequence when working with multiple branches.

The branch specification defaults to master. You are encouraged to structure your steps like this:

| 1 - master |                 |
| 2 - master |                 |
| 3 - master | 3 - some-branch |
|            | 4 - some-branch |
| 5 - master |                 |

and so forth.

PLEASE NOTE: You are not allowed to INSERT a step into the sequence, so if step number n with any branch specification has been executed, you will get an exception if you add a migration with number < n for that branch specification.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
.NET Framework net472 is compatible.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
0.0.12 238 10/23/2024
0.0.11 8,439 8/14/2024
0.0.10 123 8/14/2024
0.0.9 116 8/14/2024
0.0.8 131,703 12/17/2019
0.0.7 531 12/17/2019
0.0.6 558 11/14/2019
0.0.5 4,577 6/14/2019
0.0.4 622 6/14/2019
0.0.3 596 6/13/2019
0.0.2 692 1/18/2019
0.0.1 716 1/18/2019