Lone Badger Tech

Library and providers

Use the engine from .NET code, or add another database.

Use the engine in an application

The CLI is a thin layer over a .NET library. An application can migrate its own database at startup with the same plan, hashes and journal:

C#
using Badger.SqlMigrate.Core.Configuration;
using Badger.SqlMigrate.Core.Engine;
using Badger.SqlMigrate.Core.Project;
using Badger.SqlMigrate.Core.Providers;
using Badger.SqlMigrate.Providers.SqlServer;

var provider = new SqlServerProvider();
var environment = new DeploymentEnvironment
{
    Name = "prod",
    ConnectionString = configuration.GetConnectionString("App"),
    Ordering = OrderingPolicy.Strict,
};
var project = MigrationProject.Load(Path.Combine(AppContext.BaseDirectory, "db"), provider.Id, environment.Name);

await using var session = await provider.OpenSessionAsync(environment, SessionContext.Empty, cancellationToken);
var engine = new MigrationEngine(project, provider, environment, session, Actor.Current("my-app"));
var result = await engine.DeployAsync(new DeployOptions(), cancellationToken);

Pass a SessionContext with an IAccessTokenProvider for Entra ID (the CLI uses EntraTokenProvider from Badger.SqlMigrate.Connectivity). Register custom Always Encrypted key stores with SqlServerProvider.RegisterKeyStoreProvider.

Architecture

Badger.SqlMigrate.Cli  ──►  Badger.SqlMigrate.Core  ◄──  Badger.SqlMigrate.Providers.SqlServer
                                    ▲
Badger.SqlMigrate.Connectivity ─────┘   Entra ID tokens, SSH tunnels, secrets (vendor-neutral)

The core holds the plan, hashing, the preprocessor and the engine, and references no database driver; a test fails the build if the engine, connectivity or CLI reference a vendor driver directly.

Adding a database

A provider implements IDatabaseProvider: sessions, batch splitting, linting, journal tables, a deploy lock, a schema fingerprint, and optionally environment resources. It must pass the shared conformance test suite. The engine, plan, certification, variables, Entra ID tokens and SSH tunnels work unchanged; the PostgreSQL provider was added this way without touching any of them. Writing a provider walks through it, and CONTRIBUTING.md covers sending it upstream. MySQL and SQLite are natural next providers.

Source

github.com/lonebadger-tech/badger-sql-migrate · MIT license. Contributions welcome.