Repository navigation
Custom Templates
github-actions[bot] edited this page Nov 17, 2026
·
1 revision
To change what create writes (a base class, your team's usings, a header
comment, ...), point migrationTemplate at your own file.
migrationTemplate: templates/migration.cs.templateThe path is relative to migrate-mongo.yaml.
These placeholders are replaced and everything else is copied as-is:
| Placeholder | Example |
|---|---|
{{namespace}} |
MyApp.Migrations.Migrations |
{{id}} |
20261014164028 |
{{className}} |
AddEmailIndexToUsers |
{{name}} |
add-email-index-to-users |
using Kevsoft.MigrateMongo;
using MongoDB.Driver;
namespace {{namespace}};
[Migration("{{id}}", "{{name}}")]
public sealed class {{className}} : IMigration
{
public Task UpAsync(MigrationContext context, CancellationToken cancellationToken) => throw new NotImplementedException();
public Task DownAsync(MigrationContext context, CancellationToken cancellationToken) => throw new NotImplementedException();
}- If the template lives inside the migrations project, don't give it a
.csextension, or it'll be compiled. -
create --minimalignoresmigrationTemplateand writes the minimal built-in template. -
initanddotnet newalways use the built-in templates.
Kevsoft.MigrateMongo ·
NuGet ·
Releases ·
Issues ·
Found a mistake? These pages live in
wiki/ on main; pull requests welcome.
Get started
Migrations
- Writing Migrations
- Transactions
- Recording Results
- Dependency Injection
- Custom Templates
- Adopting an Existing Database
Collections
- Managing Collections
- Indexes
- Search Indexes
- Collection Options
- Validators
- Views
- Undeclared Collections
Deploying
Connecting
Reference
Concepts