This is a .NET Core console application that manages database migrations using FluentMigrator. It supports generating new migration stubs, applying migrations (globally or per-database), and rolling back changes (per-database only) across multiple databases.
/Migrations/
/<DatabaseName>/
YYYYMMDDHHMMSS_<databasename>_<MigrationName>.cs
Program.cs
appsettings.json
appsettings.Development.json
The tool detects the current environment using:
DOTNET_ENVIRONMENT- or
ASPNETCORE_ENVIRONMENT
Defaults to: Production.
Based on the environment, it loads:
appsettings.json(required)appsettings.{Environment}.json(optional)- Environment variables
{
"FluentMigrator": {
"Databases": {
"ExampleDb": {
"Provider": "Postgres",
"ConnectionString": "Host=localhost;Port=5432;Database=example;Username=user;Password=pass"
}
}
}
}Each key under Databases represents a logical database name and must match the folder name under Migrations/.
Run with:
dotnet run -- [command] [args...]Creates a new migration file in Migrations/<DatabaseName>/.
Example:
dotnet run -- create Billing AddInvoicesTableCreates:
Migrations/Billing/20250421094530_billing_AddInvoicesTable.cs
Applies all pending migrations for all configured databases.
dotnet run -- migrateApplies all pending migrations for a specific database.
dotnet run -- migrate ExampleDbRolls back only to exactly .
dotnet run -- rollback ExampleDb 20250420083000Rolls back only the most recent migration for the database.
dotnet run -- rollback-prev ExampleDbRoll back only all the way to version 0 (reset schema).
dotnet run -- rollback-all ExampleDbOnly PostgreSQL is currently supported.
- .NET 6+
- FluentMigrator.Runner
- Microsoft.Extensions.Configuration
- Microsoft.Extensions.DependencyInjection
- Microsoft.Extensions.Logging
- Missing connection string: shows a detailed exception.
- Missing database folder: alerts if
Migrations/<DatabaseName>does not exist. - Unsupported provider: throws a
NotSupportedException. - Incorrect usage of
create: prints usage guide.
MIT License – Feel free to use and modify.