RendleLabs.EntityFrameworkCore.MigrateHelper 2.1.1.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package RendleLabs.EntityFrameworkCore.MigrateHelper --version 2.1.1.1
NuGet\Install-Package RendleLabs.EntityFrameworkCore.MigrateHelper -Version 2.1.1.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="RendleLabs.EntityFrameworkCore.MigrateHelper" Version="2.1.1.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add RendleLabs.EntityFrameworkCore.MigrateHelper --version 2.1.1.1
#r "nuget: RendleLabs.EntityFrameworkCore.MigrateHelper, 2.1.1.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install RendleLabs.EntityFrameworkCore.MigrateHelper as a Cake Addin
#addin nuget:?package=RendleLabs.EntityFrameworkCore.MigrateHelper&version=2.1.1.1

// Install RendleLabs.EntityFrameworkCore.MigrateHelper as a Cake Tool
#tool nuget:?package=RendleLabs.EntityFrameworkCore.MigrateHelper&version=2.1.1.1

MigrateHelper

Migration helper for creating console apps to run migrations in EF core

Installation

NuGet: RendleLabs.EntityFrameworkCore.MigrateHelper

dotnet add package RendleLabs.EntityFrameworkCore.MigrateHelper

Usage

To use MigrateHelper, create a Console application and make sure it contains a single implementation of IDesignTimeDbContactFactory<T> that creates your DB context.

Something like this:

public class DesignTimeFooContextFactory : IDesignTimeDbContextFactory<FooContext>
{
    public const string LocalPostgres = "Host=localhost;Database=mighelp;Username=mig;Password=secretsquirrel";
    public static readonly string MigrationAssemblyName =
        typeof(DesignTimeFooContextFactory).Assembly.GetName().Name;

    public FooContext CreateDbContext(string[] args)
    {
        var builder = new DbContextOptionsBuilder<FooContext>()
            .UseNpgsql(args.FirstOrDefault() ?? LocalPostgres, b => b.MigrationsAssembly(MigrationAssemblyName));
        return new FooContext(builder.Options);
    }
}

Then, in your Program.cs file, call the MigrationHelper like this:

class Program
{
    static async Task Main(string[] args)
    {
        var loggerFactory = new LoggerFactory();
        loggerFactory.AddConsole();
        await new MigrationHelper(loggerFactory).TryMigrate(args);
    }
}

You can obviously add any Loggers you like to get output.

If you want to run some addtional code after the migration, you can add a callback like this:

    await new MigrationHelper(loggerFactory).TryMigrate<FooContext>(args, async context =>
    {
        context.Foos.Add(new Foo {Name = "Test"});
        await context.SaveChangesAsync();
    });

This code will only be run if the migration itself runs successfully. If the migration has already been run, this code will not be called.

You can now build and run your console app, passing the connection string as a command line argument. This makes it easy to run migrations in Docker or Kubernetes using a Secret as the argument.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.1.3.1 950 9/26/2018
2.1.3 703 9/24/2018
2.1.1.1 784 8/17/2018
2.1.1 816 7/30/2018
2.1.0-rc1 716 5/9/2018
2.1.0-preview1-141720 864 3/14/2018
2.1.0-preview1-031543 736 3/13/2018
1.0.1 1,049 11/18/2017
1.0.0 922 9/20/2017

First release