Custom extensions

Reuse schema conventions without hiding provider behavior or changing the migration contract.

Examples use Classic and Fluent tabs. Your choice follows you through the manual.

Share a schema convention

A small helper can express a repeated column policy in both styles. Keep helper behavior stable for historical migrations; changing a helper can change what an old migration does on a fresh database. The example uses static methods to keep its dependencies explicit.

Reusable audit-column helpers

Classic

using System;
using System.Data;
using DotNetProjects.Migrator;
using DotNetProjects.Migrator.Framework;

public static class AuditColumns
{
    public static void Add(ITransformationProvider database, string table)
        => database.AddColumn(table, new Column("CreatedAt", DbType.DateTime)
        {
            IsNullable = false, DefaultValue = RawSql.Insert("CURRENT_TIMESTAMP")
        });
}

Fluent

using System;
using System.Data;
using DotNetProjects.Migrator;
using DotNetProjects.Migrator.Framework;
using DotNetProjects.Migrator.Framework.Fluent;

public static class AuditColumns
{
    public static void Add(MigrationBuilder migration, string table)
        => migration.Create.Column("CreatedAt").OnTable(table).OfType(DbType.DateTime)
            .NotNullable().WithDefaultValue(RawSql.Insert("CURRENT_TIMESTAMP"));
}

Choose one authoring style

Custom activation and locks

RunnerOptions.Activator constructs migrations when a DI container is not appropriate. IMigrationLock supplies a disposable lease for custom deployment coordination. Release must work on success and failure. Configure these at the host boundary rather than in individual migrations.

Provider authors

ITransformationProvider defines execution and metadata operations. A custom provider needs accurate typed constraint definitions or an explicit unsupported error. IMigrationHistory enables read-only planning and effective-scope history selection. IScriptBatchProvider extends script processing.

Keep SQL rendering independent of a live connection. Custom MigrationOperation implementations need deliberate validation, application, SQL rendering and reversal behavior. See the API map and implementation contracts before claiming preview or reversal support.