Skip to content

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.template

The path is relative to migrate-mongo.yaml.

Placeholders

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

Example

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();
}

Gotchas

  • If the template lives inside the migrations project, don't give it a .cs extension, or it'll be compiled.
  • create --minimal ignores migrationTemplate and writes the minimal built-in template.
  • init and dotnet new always use the built-in templates.

Clone this wiki locally