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.

Infrastructure Index (such as Unique Index on VersionInfo table) is not using IConventionSet

See original GitHub issue

I have customized my FluentMigrator project using IConventionSet but it doesn’t seems to be considered when creating the infrastructure object (e.g. VersionInfo table’s indexes).

Example

I have the following class correctly configured in my project:

public class ProjectConstraintNameConvention : IConstraintConvention
{
    // Rest of code was omitted

    private static string GetConstraintName(ConstraintDefinition expression)
    {
        var sb = new StringBuilder();
        sb.Append("MYProject_");
        sb.Append(expression.IsPrimaryKeyConstraint ? "PK_" : "UC_");


        sb.Append(expression.TableName);
        foreach (var column in expression.Columns)
        {
            sb.Append('_').Append(column);
        }

        return sb.ToString();
    }
}

Running “Up” database, the following SQL is create:

CREATE UNIQUE INDEX UC_Version ON VersionInfo (Version ASC);

Instead of:

CREATE UNIQUE INDEX MYProject_UC_VersionInfo_Version ON VersionInfo (Version ASC);

I’m using version FluentMigrator/3.2.1

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:4
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
tgharoldcommented, Apr 8, 2020

Is this a .NET Core project where you are using AddFluentMigratorCore()?

If so, you need to register the IConventionSet after making the AddFluentMigratorCore() call in Startup.ConfigureServices(). See this sample for an example.

The reason for this (I think) is a line inside of AddFluentMigratorCore(). Because the IServicesCollection is LIFO (last in first out), if AddFluentMigratorCore() registers something to handle IConventionSet after you register it… the FM registration will trump your registration. The workaround is to register your IConventionSet after the FM registration.

Source:

https://github.com/fluentmigrator/fluentmigrator/blob/27eb0110ff14b4d32aed7d316ee5caf4dda20716/src/FluentMigrator.Runner/FluentMigratorServiceCollectionExtensions.cs#L101-L102

0reactions
tgharoldcommented, Apr 10, 2020

Yes, I pulled TryAddScoped out of the MS documentation while doing some other work.

Generally, this method is used by library authors to avoid registering two copies of an instance in the container.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Migration exception - could not create unique index
I want to set id_number as unique. I am using fluent migrator and using the following code structure. public override void Down() {...
Read more >
SQL Server specific extensions
Create a primary key with a 'clustered' index; Create a unique constraint ... Table expression to be able to specify them as clustered...
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