Giter Site home page Giter Site logo

Comments (3)

TheSquidCombatant avatar TheSquidCombatant commented on September 26, 2024

Obviously, the observed difference in the name of the primary key occurs due to the fact that, when creating primary key via creating a table, the DefaultPrimaryKeyNameConvention class is used to generate the name, and when creating a standalone primary key, the DefaultConstraintNameConvention class is used to generate the name.

I agree that it would be correct for the name for the primary key to be generated the same in all cases. I have created a pull request with the appropriate fix, please check #1803.

I won’t reassure you and I’ll say right away that I’m not a maintainer. For now, I suggest keeping in mind that the default primary key name is not guaranteed. And each time explicitly set the name of the primary key.

from fluentmigrator.

jzabroski avatar jzabroski commented on September 26, 2024

This would be a breaking change, but seems reasonable. For now you can implement a different naming convention as a workaround.

from fluentmigrator.

jzabroski avatar jzabroski commented on September 26, 2024

The root cause here is that we're using CreateConstraintExpression.

/// <inheritdoc />
public ICreateConstraintOnTableSyntax PrimaryKey()
{
var expression = new CreateConstraintExpression(ConstraintType.PrimaryKey);
_context.Expressions.Add(expression);
return new CreateConstraintExpressionBuilder(expression);
}
/// <inheritdoc />
public ICreateConstraintOnTableSyntax PrimaryKey(string primaryKeyName)
{
var expression = new CreateConstraintExpression(ConstraintType.PrimaryKey);
expression.Constraint.ConstraintName = primaryKeyName;
_context.Expressions.Add(expression);
return new CreateConstraintExpressionBuilder(expression);
}

It gets generated here:

public override string Generate(CreateConstraintExpression expression)
{
var constraintType = (expression.Constraint.IsPrimaryKeyConstraint) ? "PRIMARY KEY" : "UNIQUE";
var columns = new string[expression.Constraint.Columns.Count];
for (var i = 0; i < expression.Constraint.Columns.Count; i++)
{
columns[i] = Quoter.QuoteColumnName(expression.Constraint.Columns.ElementAt(i));
}
return string.Format(CreateConstraint, Quoter.QuoteTableName(expression.Constraint.TableName, expression.Constraint.SchemaName),
Quoter.QuoteConstraintName(expression.Constraint.ConstraintName),
constraintType,
string.Join(", ", columns));
}

Which in turn delegates ultimately to ColumnBase.GetPrimaryKeyConstraintName:

protected virtual string GetPrimaryKeyConstraintName(IEnumerable<ColumnDefinition> primaryKeyColumns, string tableName)
{
var primaryKeyName = primaryKeyColumns.Select(x => x.PrimaryKeyName).FirstOrDefault();
if (string.IsNullOrEmpty(primaryKeyName))
{
return string.Empty;
}
return string.Format("CONSTRAINT {0} ", Quoter.QuoteIndexName(primaryKeyName));
}

  1. ColumnBase would need a dependency on IConventionSet to get the primary key name convention
  2. public class DefaultPrimaryKeyNameConvention : IColumnsConvention
    should have an explicit IPrimaryKeyNameConvention interface, although probably not strictly required, it does help with discoverability.

from fluentmigrator.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.