Skip to content

DotNetDeveloperDan/FluentRun

Repository files navigation

FluentMigrator Console Migration Tool

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.


📁 Project Structure

/Migrations/
  /<DatabaseName>/
    YYYYMMDDHHMMSS_<databasename>_<MigrationName>.cs
Program.cs
appsettings.json
appsettings.Development.json

⚙️ Environment Configuration

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

🛠️ Configuration Format (appsettings.json)

{
  "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/.


📜 Commands

Run with:

dotnet run -- [command] [args...]

create <DatabaseName> <MigrationName>

Creates a new migration file in Migrations/<DatabaseName>/.

Example:

dotnet run -- create Billing AddInvoicesTable

Creates:

Migrations/Billing/20250421094530_billing_AddInvoicesTable.cs

migrate [<DatabaseName>]

Applies all pending migrations for all configured databases.

dotnet run -- migrate

Applies all pending migrations for a specific database.

dotnet run -- migrate ExampleDb

rollback <DatabaseName> <TargetVersion>

Rolls back only to exactly .

dotnet run -- rollback ExampleDb 20250420083000

rollback-prev <DatabaseName>

Rolls back only the most recent migration for the database.

dotnet run -- rollback-prev ExampleDb

rollback-all <DatabaseName>

Roll back only all the way to version 0 (reset schema).

dotnet run -- rollback-all ExampleDb

🔌 Supported Providers

Only PostgreSQL is currently supported.


📦 Dependencies


🐞 Error Handling

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

📄 License

MIT License – Feel free to use and modify.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages