Using FluentMigrator, is there way to find out if the MigrateUp() function will indeed migrate something or whether it's already up to date?
There is no easy way to tell using the public api whether the MigrateUp
method will do something or not.
However, there are multiple "other" ways around this that depend on the internals of FluentMigrator:
Derive from the MigrationRunner
, override the ApplyMigrationUp
method, which gets called every time a migration gets applied, and track/log the applied migrations
Create a custom IAnnouncer
implementation, configure FluentMigrator to use it through the IRunnerContext
and in your announcer Say
method check that the message
parameter contains the text "migrated"
which means a migration step has been applied.
MigrateUp
, if you can get a reference on a MigrationRunner
you can: MigrationRunner runner = ... // get a reference to the runner
if (runner.MigrationLoader.LoadMigrations() // get all the migrations
.Any(pair => !runner.VersionLoader
.VersionInfo.HasAppliedMigration(pair.Key)))
// check which migrations have been applied
{
// there are pending migrations, do your logic here
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With