question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to use custom version table meta data for new .net core FluentMigrator

See original GitHub issue

I am migrating a pre .net core FluentMIgrator project to the new .net core version. I had a custom VersionTable that looked like this:

    [VersionTableMetaData]
    public class VersionTable : DefaultVersionTableMetaData
    {
        public override string TableName => "T_SCHEMA_VERSION_INFO";
    }

This results in the following warning/error:

VersionTable.cs(9,5,18,6): error CS0618: 'DefaultVersionTableMetaData.DefaultVersionTableMetaData()' is obsolete: 'Use dependency injection'

I fixed this error by changing my code to this (removed attribute & added constructor):

    public class VersionTable : DefaultVersionTableMetaData
    {
        public VersionTable(IConventionSet conventionSet, IOptions<RunnerOptions> runnerOptions)
            : base(conventionSet, runnerOptions)
        {
            SchemaName = "distribution";
        }

        public override string TableName => "T_SCHEMA_VERSION_INFO";
    }

This compiles correctly. But then, I don’t know what I have to add in my CreateServices function:

            return new ServiceCollection()
                .AddFluentMigratorCore()
                .ConfigureRunner(rb => rb
                    .AddMySql5()
                    .WithVersionTable(new VersionTable(???))

So the WithVersionTable expects an instance of IVersionTableMetaData. Unfortunately, I don’t know what to use for the convensionset and runnerOptions parameters.

Could you please provide some guidance and document them here? I have the feeling that this documentation is out of date.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
mabeadcommented, Oct 10, 2018

Or, IMHO, a more elegant option would be to add a .WithVersionTable<VersionTable>() function. The implementation of this function would be something simple like:

        public static IMigrationRunnerBuilder WithVersionTable<T>(
            this IMigrationRunnerBuilder builder) where T:IVersionTableMetaData
        {
            builder.Services
                .AddScoped<IVersionTableMetaDataAccessor, T>();
            return builder;
        }
0reactions
jzabroskicommented, Feb 21, 2021

What problem are you getting?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Custom metadata for the VersionInfo table
The custom IVersionTableMetaData is filtered by the values in the TypeFilterOptions. This allows different IVersionTableMetaData for every database. A common ...
Read more >
c# - How to determine current version from VersionInfo for ...
I am using Fluent Migrator in .NET 6. I know that Fluent Migrator looks at VersionInfo table to determine which migrations need to...
Read more >
Using fluentmigrator for automated database deployment (in ...
NET for data access, fluentmigrator is your answer to database migration ... In this video, I will walk through creating a database table, ......
Read more >
How can I add information to the VersionInfo Table?
I'd like to add an extra column to the VersionInfo table to support generating ... /fluentmigrator/wiki/Create-custom-metadata-for-the-VersionInfo-table).
Read more >
An effective database migration pattern for many instances ...
I'm using fluent migrator, and after some months or years, the number of migrations could be (and has been in previous projects) in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found