Infrastructure Index (such as Unique Index on VersionInfo table) is not using IConventionSet
See original GitHub issueI 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:
- Created 4 years ago
- Reactions:4
- Comments:7 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Is this a .NET Core project where you are using
AddFluentMigratorCore()
?If so, you need to register the
IConventionSet
after making theAddFluentMigratorCore()
call inStartup.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), ifAddFluentMigratorCore()
registers something to handleIConventionSet
after you register it… the FM registration will trump your registration. The workaround is to register yourIConventionSet
after the FM registration.Source:
https://github.com/fluentmigrator/fluentmigrator/blob/27eb0110ff14b4d32aed7d316ee5caf4dda20716/src/FluentMigrator.Runner/FluentMigratorServiceCollectionExtensions.cs#L101-L102
Yes, I pulled TryAddScoped out of the MS documentation while doing some other work.