I am using Fluent Migrator in .NET 6.
I know that Fluent Migrator looks at VersionInfo table to determine which migrations need to be applied when we migrate down or up.
For example, we can do runner.MigrateUp()
without any param and Fluent Migrator will automatically determine which, if any, migrations we need to apply after looking at the VersionInfo table in the DB.
My question is, how do we get the current version in C# code so that we can determine whether to migrate up or down to an User-inputted version number?
In other words, I want to do something like this:
if (userInputVersion > currentVersion)
{
runner.MigrationUp(userInputVersion)
}
else
{
runner.MigrationDown(userInputVersion)
}
Is there a way to find this 'currentVersion' in C# code via Fluent Migrator methods, without making a raw query to the database table itself?
Try using IVersionLoader
for this goal (should be available via DI as in the In-Process example):
IVersionLoader versionLoader = ...; // should be available via DI
var latest = versionLoader.VersionInfo.Latest();