Search Results for

    Show / Hide Table of Contents

    Migration runners

    We have three migration runners you can choose from.

    Please use the in-process runner if possible.

    In-Process

    This is an example of using the in-process migration runner:

    using System;
    using System.Linq;
    
    using FluentMigrator.Runner;
    using FluentMigrator.Runner.Initialization;
    
    using Microsoft.Extensions.DependencyInjection;
    
    namespace test
    {
        class Program
        {
            static void Main(string[] args)
            {
                using (var serviceProvider = CreateServices())
                using (var scope = serviceProvider.CreateScope())
                {
                    // Put the database update into a scope to ensure
                    // that all resources will be disposed.
                    UpdateDatabase(scope.ServiceProvider);
                }
             }
    
            /// <summary>
            /// Configure the dependency injection services
            /// </summary>
            private static ServiceProvider CreateServices()
            {
                return new ServiceCollection()
                    // Add common FluentMigrator services
                    .AddFluentMigratorCore()
                    .ConfigureRunner(rb => rb
                        // Add SQLite support to FluentMigrator
                        .AddSQLite()
                        // Set the connection string
                        .WithGlobalConnectionString("Data Source=test.db")
                        // Define the assembly containing the migrations, maintenance migrations and other customizations
                        .ScanIn(typeof(AddLogTable).Assembly).For.All())
                    // Enable logging to console in the FluentMigrator way
                    .AddLogging(lb => lb.AddFluentMigratorConsole())
                    // Build the service provider
                    .BuildServiceProvider(false);
            }
    
            /// <summary>
            /// Update the database
            /// </summary>
            private static void UpdateDatabase(IServiceProvider serviceProvider)
            {
                // Instantiate the runner
                var runner = serviceProvider.GetRequiredService<IMigrationRunner>();
    
                // Execute the migrations
                runner.MigrateUp();
            }
        }
    }
    

    Migrate.exe (FluentMigrator.Console package)

    This is a console tool that works also with the .NET Framework outside of the .NET Core ecosystem.

    • Visual Studio: Install with the package manager console
    • NuGet: Install with the nuget.exe tool

    Install the package with:

    Install-Package FluentMigrator.Console
    

    Install the package with:

    nuget install FluentMigrator.Console -ExcludeVersion
    

    Now, you can find the tool in the path FluentMigrator[package-version]/tools/<target-framework>/[optional-platform/]Migrate.exe.

    Note

    The package-version is only part of the path when the tool was installed using the Visual Studio package manager console.

    Important

    Choose the correct target-framework. Otherwise, the tool might not be able to load your assembly.

    target-framework platform optional-platform exists? path
    net40 x86 yes tools/net40/x86/Migrate.exe
    net40 x64 yes tools/net40/x64/Migrate.exe
    net40 AnyCPU no tools/net40/Migrate.exe
    net45 x86 yes tools/net45/x86/Migrate.exe
    net45 x64 yes tools/net45/x64/Migrate.exe
    net45 AnyCPU no tools/net45/Migrate.exe
    net452 x86 yes tools/net452/x86/Migrate.exe
    net452 x64 yes tools/net452/x64/Migrate.exe
    net452 AnyCPU yes tools/net452/any/Migrate.exe
    Important

    On non-Windows platforms, you have to install/use mono.

    dotnet fm (FluentMigrator.DotNet.Cli tool)

    Important

    You need at least the .NET Core 2.1 preview 2 SDK for this tool.

    Install the dotnet-fm tool:

    dotnet tool install -g FluentMigrator.DotNet.Cli
    

    Execute the migration:

    dotnet fm migrate -p sqlite -c "Data Source=test.db" -a ".\bin\Debug\netcoreapp2.1\test.dll"
    
    Tip

    You probably have to replace netcoreapp2.1 with the correct target framework. You can find it in the csproj file, XML element TargetFramework.

    • Edit this page
    In this article
    Back to top
    Copyright © 2018 Fluent Migrator Project
    Generated by DocFX
    Creative Commons License
    FluentMigrator Documentation by FluentMigrator Project is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.