Standard libraries for dependency injection, configuration, logging
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 typeSystem.TimeSpan?
MigrationRunner.MaintenanceLoader
is now read-onlyMigrationRunner.CaughtExceptions
returns now aIReadOnlyList
dotnet-fm
is now a global tool and requires at least the .NET Core tooling 2.1-preview2
Added
- #851: Enable the usage of Microsoft.Extensions.DependencyInjection
- #852: Replace custom configuration mechanisms by using Microsoft.Extensions.Options
- #853: Replace the announcer with Microsoft.Extensions.Logging
- Support for loading connection strings using a provided
IConfiguration
service (Microsoft.Extensions.Configuration) - #822:
IMigrationExpressionValidator
for custom migration expression validation - #809: Ability to add a schema owner during schema creation for SQL Server
Fixed
- #767: Append
NULL
constraint for custom types for PostgreSQL and SQL Server
Deprecated
IAssemblyCollection
and all its implementationsIAnnouncer
and all its implementationsIMigrationRunnerConventions.GetMigrationInfo
IProfileLoader.ApplyProfiles()
IProfileLoader.FindProfilesIn
IMigrationProcessorOptions
IMigrationProcessorFactory
and all its implementationsIRunnerContext
andRunnerContext
, replaced by several dedicated options classes:RunnerOptions
are the newRunnerContext
(minus some properties extracted into separate option classes)ProcessorOptions
for global processor-specific optionsGeneratorOptions
to allow setting the compatibility modeTypeFilterOptions
for filtering migrations by namespaceAnnouncerOptions
to enable showing SQL statements and the elapsed timeSelectingProcessorAccessorOptions
allows selection of a processor by its identifierSelectingGeneratorAccessorOptions
allows selection of a generator by its identifierAppConfigConnectionStringAccessorOptions
to allow leading the connection strings from the *.config xml file (deprecated, only for transition toMicrosoft.Extensions.Configuration
)
CompatabilityMode
(is nowComatibilityMode
)ApplicationContext
in various interfaces/classesManifestResourceNameWithAssembly
replaced byValueTuple
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 a connection string is returned by one of the readers, then this
- 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.