{"id":29798213,"url":"https://github.com/jordandchappell/csharp.mongo.migration","last_synced_at":"2025-10-12T21:54:42.647Z","repository":{"id":230862903,"uuid":"780306710","full_name":"JordanDChappell/CSharp.Mongo.Migration","owner":"JordanDChappell","description":"Simple script based MongoDB database migrations written and run using .NET in C#","archived":false,"fork":false,"pushed_at":"2025-10-07T09:42:24.000Z","size":111,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-10-07T11:40:42.507Z","etag":null,"topics":["csharp","database-migrations","dotnet","library","migration","migration-tool","migrations","mongodb","mongodb-database","open-source"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/JordanDChappell.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-04-01T07:28:15.000Z","updated_at":"2025-10-07T09:42:26.000Z","dependencies_parsed_at":"2024-04-13T07:41:20.058Z","dependency_job_id":"45af5229-2af8-4a7f-8257-1a0807bb67c8","html_url":"https://github.com/JordanDChappell/CSharp.Mongo.Migration","commit_stats":null,"previous_names":["jordandchappell/csharp.mongo.migration"],"tags_count":15,"template":false,"template_full_name":null,"purl":"pkg:github/JordanDChappell/CSharp.Mongo.Migration","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JordanDChappell%2FCSharp.Mongo.Migration","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JordanDChappell%2FCSharp.Mongo.Migration/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JordanDChappell%2FCSharp.Mongo.Migration/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JordanDChappell%2FCSharp.Mongo.Migration/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JordanDChappell","download_url":"https://codeload.github.com/JordanDChappell/CSharp.Mongo.Migration/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JordanDChappell%2FCSharp.Mongo.Migration/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279013129,"owners_count":26085232,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-12T02:00:06.719Z","response_time":53,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["csharp","database-migrations","dotnet","library","migration","migration-tool","migrations","mongodb","mongodb-database","open-source"],"created_at":"2025-07-28T07:13:21.928Z","updated_at":"2025-10-12T21:54:42.642Z","avatar_url":"https://github.com/JordanDChappell.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CSharp Mongo Migrations\n\nSimple script based MongoDB database migrations written and run in .NET.\n\n`CSharp.Mongo.Migration` uses the [C# MongoDB Driver](https://www.mongodb.com/docs/drivers/csharp/current/) to update documents in script based single use migrations (rather than on-the-fly).\n\nSee the [Wiki](https://github.com/JordanDChappell/CSharp.Mongo.Migration/wiki) for more information.\n\n## Status\n![ci](https://github.com/JordanDChappell/CSharp.Mongo.Migration/actions/workflows/ci.yml/badge.svg?branch=main)\n![cd](https://github.com/JordanDChappell/CSharp.Mongo.Migration/actions/workflows/cd.yml/badge.svg)\n![pr](https://github.com/JordanDChappell/CSharp.Mongo.Migration/actions/workflows/pr.yml/badge.svg?branch=main)\n\n## Usage\n\n### Installation\n\nNuget: https://www.nuget.org/packages/CSharp.Mongo.Migration\n\nInstall using the Visual Studio package manager or the dotnet CLI:\n\n```\ndotnet add package CSharp.Mongo.Migration\n```\n\n### Running Migrations\n\n1. Create an instance of the `MigrationRunner` class\n\n```csharp\nMigrationRunner runner = new(\"yourDatabaseConnectionString\");\n```\n\n2. Register an `IMigrationLocator` and run the migrations\n\n```csharp\nawait runner\n    .RegisterLocator(new AssemblyMigrationLocator(\"Assembly.With.Your.Migrations.dll\"))\n    .RunAsync();\n```\n\n### Writing Migrations\n\nA migration script should implement the `IMigration` or `IAsyncMigration` interface. The following properties / methods will need to be defined:\n\n- `string Name`\n- `string Version`\n- `void Up(IMongoDatabase)` / `Task UpAsync(IMongoDatabase database)`\n- `void Down(IMongoDatabase)` / `Task DownAsync(IMongoDatabase database)`\n\nAn optional `bool Skip()` method can be defined that can be used to conditionally skip a migration.\n\n`Up` / `UpAsync` will be run when the `MigrationRunner.RunAsync` method is called.\n\n`Down` / `DownAsync` will be called when the `MigrationRunner.RevertAsync(string)` method is called, if you don't expect to revert a migration, simply have this method throw an exception.\n\n#### Explicit Order\n\nIf a migration requires or depends on another migration script, the `IOrderedMigration` interface can be used and it's `DependsOn` property implemented to provide version dependencies between migrations. Migrations need to implement one of the `IMigration` or `IAsyncMigration` interfaces along with the `IOrderedMigration` interface to be loaded and run.\n\n#### Ignoring Migrations\n\nIf a migration is no longer required, you can remove the class from your application, or use the `[IgnoreMigration]` attribute on that class.\n\nFor example:\n\n```\n[IgnoreMigration]\npublic class MyMigration1 : IMigration { }\n```\n\n### Restoring Migrations\n\nTo revert or restore a migration run the `RevertAsync(\"version\")` function on an instance of the `MigrationRunner` class\n\n```csharp\nMigrationRunner runner = new(\"youDatabaseConnectionString\");\nawait runner\n    .RegisterLocator(new AssemblyMigrationLocator(\"Assembly.With.Migration.Version.dll\"))\n    .RevertAsync(\"version\");\n```\n\n### Migration Documents\n\nWhen a migration has been applied a new document will be created in the target database in a collection named `_migrations` by default. These documents are used to track which migrations have been applied and when they were applied.\n\n**Note:** to override the default collection name, use a constructor that includes the `migrationCollectionName` parameter, or set the public `MigrationRunner.MigrationCollectionName` property.\n\n### Logging\n\nThis library provides support for logging using [Microsoft.Extensions.Logging](https://learn.microsoft.com/en-us/dotnet/core/extensions/logging?tabs=command-line).\n\nThe `MigrationRunner` class writes information level logs that help to understand which migrations have been located and when they have successfully completed. In order to configure logging use the `RegisterLogger` function.\n\n## Why Create Another Library?\n\nThere are a number of other libraries for MongoDB designed to be used in C#. This library was written out of necessity to be used in a large development team with fairly sizeable database instances. There are some use cases that this library caters to that others do not:\n\n* Allow migrations to run out of order\n* Provide a version identifier that is not a number or using SemVer\n* Encourage `async` migration scripts\n\nUsing other libraries we found that migration versions could clash when using number or SemVer based identifiers, our team uses GitFlow to achieve the development throughput and organisation that we require and often larger feature branches would clash when selecting version numbers.\n\n## Dependencies\n\nThis library uses the following packages:\n\n- [C# MongoDB Driver](https://www.mongodb.com/docs/drivers/csharp/current/)\n\n### Development Dependencies\n\nWe use the following libraries for testing / development purposes:\n\n- [AutoMoqCore](https://www.nuget.org/packages/AutoMoqCore/)\n- [DefaultDocumentation](https://github.com/Doraku/DefaultDocumentation)\n- [EphemeralMongo7](https://www.nuget.org/packages/EphemeralMongo7)\n- [xunit](https://www.nuget.org/packages/xunit)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjordandchappell%2Fcsharp.mongo.migration","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjordandchappell%2Fcsharp.mongo.migration","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjordandchappell%2Fcsharp.mongo.migration/lists"}