Skip to content

Standard libraries for dependency injection, configuration, logging

Compare
Choose a tag to compare
@fubar-coder fubar-coder released this 07 May 21:16

The new documentation is online on https://fluentmigrator.github.io.

Upgrade Guide

https://fluentmigrator.github.io/articles/guides/upgrades/guide-2.0-to-3.0.html

What changed?

Breaking changes

  • #850: Set minimum .NET Framework version to 4.6.1. Older versions aren't supported anymore.
  • ProcessorOptions.Timeout is now of type System.TimeSpan?
  • MigrationRunner.MaintenanceLoader is now read-only
  • MigrationRunner.CaughtExceptions returns now a IReadOnlyList
  • dotnet-fm is now a global tool and requires at least the .NET Core tooling 2.1-preview2

Added

Fixed

  • #767: Append NULL constraint for custom types for PostgreSQL and SQL Server

Deprecated

  • IAssemblyCollection and all its implementations
  • IAnnouncer and all its implementations
  • IMigrationRunnerConventions.GetMigrationInfo
  • IProfileLoader.ApplyProfiles()
  • IProfileLoader.FindProfilesIn
  • IMigrationProcessorOptions
  • IMigrationProcessorFactory and all its implementations
  • IRunnerContext and RunnerContext, replaced by several dedicated options classes:
    • RunnerOptions are the new RunnerContext (minus some properties extracted into separate option classes)
    • ProcessorOptions for global processor-specific options
    • GeneratorOptions to allow setting the compatibility mode
    • TypeFilterOptions for filtering migrations by namespace
    • AnnouncerOptions to enable showing SQL statements and the elapsed time
    • SelectingProcessorAccessorOptions allows selection of a processor by its identifier
    • SelectingGeneratorAccessorOptions allows selection of a generator by its identifier
    • AppConfigConnectionStringAccessorOptions to allow leading the connection strings from the *.config xml file (deprecated, only for transition to Microsoft.Extensions.Configuration)
  • CompatabilityMode (is now ComatibilityMode)
  • ApplicationContext in various interfaces/classes
  • ManifestResourceNameWithAssembly replaced by ValueTuple
  • MigrationGeneratorFactory
  • MigrationProcessorFactoryProvider
  • ITypeMap.GetTypeMap(DbType, int, int)
  • IDbFactory: Only the implementations will remain
  • Several non-DI constructors

Additional information

Connection string handling

The library assumes that in ProcessorOptions.ConnectionString is either a connection string or
a connection string identifier. This are the steps to load the real connection string.

  • Queries all IConnectionStringReader implementations
    • When a connection string is returned by one of the readers, then this
      connection string will be used
    • When no connection string is returned, try reading from the next IConnectionStringReader
  • When no reader returned a connection string, then return ProcessorOptions.ConnectionString

The connection string stored in ProcessorOptions.ConnectionString might be overridden
by registering the IConnectionStringReader instance PassThroughConnectionStringReader
as scoped service.

When no connection string could be found, the SelectingProcessorAccessor returns
a ConnectionlessProcessor instead of the previously selected processor.

Instantiating a migration runner

// Initialize the services
var serviceProvider = new ServiceCollection()
    .AddLogging(lb => lb.AddFluentMigratorConsole())
    .AddFluentMigratorCore()
    .ConfigureRunner(
        builder => builder
            .AddSQLite()
            .WithGlobalConnectionString(connectionString)
            .WithMigrationsIn(typeof(AddGTDTables).Assembly))
    .BuildServiceProvider();

// Instantiate the runner
var runner = serviceProvider.GetRequiredService<IMigrationRunner>();

// Run the migrations
runner.MigrateUp();

This adds the FluentMigrator services to the service collection and
configures the runner to use SQLite with the given connection string,
announcer and migration assembly.

Now you can instantiate the runner using the built service provider and use
its functions.