Skip to content

Latest commit

 

History

History
47 lines (35 loc) · 1.34 KB

README.md

File metadata and controls

47 lines (35 loc) · 1.34 KB

Rapidata.MongoDB.Migrations

A modern, thread-safe MongoDB migration engine for C#

NuGet License

Features

  • 🔒 Thread-safe: Can be run by multiple services simultaneously
  • 🔄 Guaranteed single execution for each migration
  • 📚 Support for multiple database migrations
  • ⚙️ Flexible configuration options
  • 🚀 Easy integration with ASP.NET Core

Usage

Basic Usage

To get started, define the migrations in an assembly.

// Define a migration
public class TestMigration : IMigration
{
    public DateOnly Date => new(2024, 10, 10);
    public short Version => 1;
    public string Name => "Test Migration";

    public async Task Migrate(IMongoDatabase database, CancellationToken cancellationToken)
    {
        await database.CreateCollectionAsync(nameof(TestMigration), options: null, cancellationToken);
    }
}

Then, register the migrations in the host and define at least one database to migrate.

// Register dependencies on the host
host.AddMongoDbMigrations(builder => builder.WithDatabase("default").WithMigrationsInAssemblyOfType<TestMigration>);
// Run the migrations
await host.MigrateMongoDb();