Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rebus-org/mongrow
:herb: MongoDB migration library
https://github.com/rebus-org/mongrow
evolutionary-database-design migrate-database migration migration-tool migrations migrator mongo mongodb mongodb-database
Last synced: 3 months ago
JSON representation
:herb: MongoDB migration library
- Host: GitHub
- URL: https://github.com/rebus-org/mongrow
- Owner: rebus-org
- License: other
- Created: 2019-01-18T09:04:51.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2024-08-14T12:15:54.000Z (5 months ago)
- Last Synced: 2024-10-10T05:41:21.038Z (3 months ago)
- Topics: evolutionary-database-design, migrate-database, migration, migration-tool, migrations, migrator, mongo, mongodb, mongodb-database
- Language: C#
- Size: 4.67 MB
- Stars: 12
- Watchers: 5
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
Awesome Lists containing this project
README
# 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:
```csharp
[Step(1)]
public class AddAdminUser : IStep
{
public async Task Execute(IMongoDatabase database)
{
var users = database.GetCollection("users");var adminUser = new
{
_id = Guid.NewGuid().ToString(),
uid = "user1",
claims = new[]
{
new {type = ClaimTypes.Email, value = "[email protected]"},
new {type = ClaimTypes.Role, value = "admin"},
}
};await users.InsertOneAsync(adminUser.ToBsonDocument());
}
}
```and then you execute it like this:
```csharp
var migrator = new Migrator(
connectionString: "mongodb://mongohost01/MyDatabase",
steps: GetSteps.FromAssemblyOf()
);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.