npgsql / EntityFramework6.Npgsql

Entity Framework 6 provider for PostgreSQL
PostgreSQL License
66 stars 54 forks source link

Npgsql.EntityFramework produces wrong index name #13

Open roji opened 8 years ago

roji commented 8 years ago

From @azhozhin on March 17, 2015 8:31

in Npgsql.EntityFramework\NpgsqlMigrationSqlGenerator.cs code responsible for index name:

private void Convert(CreateIndexOperation createIndexOperation)
{
...
sql.Append(GetTableNameFromFullTableName(createIndexOperation.Table) + "_" + createIndexOperation.Name);
...
}

produces weird names such as Product_IX_ProductName instead of IX_ProductName

for migration:

CreateTable(
   "public.Products",
   c => new
   {
      Guid = c.Guid(nullable: false),
      ProductName = c.String(nullable: false, maxLength: 255),
   })
   .PrimaryKey(t => t.Guid)
   .Index(t => t.ProductName);

Copied from original issue: npgsql/npgsql#538

roji commented 8 years ago

From @adraut on March 18, 2015 0:47

@azhozhin What is wrong with the index name? It is being generated inline with PostgreSQL's default index naming.

roji commented 8 years ago

From @azhozhin on March 18, 2015 5:17

@adraut I want to control by myself naming convention here using IndexAttributeConvention and ForeignKeyIndexConvention but not be forced by Npgsql.EntityFramework.

There is SqlServerMigrationSqlGenerator implementation:

protected virtual void Generate(CreateIndexOperation createIndexOperation)
    {
      Check.NotNull<CreateIndexOperation>(createIndexOperation, "createIndexOperation");
      using (IndentedTextWriter writer = SqlServerMigrationSqlGenerator.Writer())
      {
        writer.Write("CREATE ");
...
        writer.Write("INDEX ");
        writer.Write(this.Quote(createIndexOperation.Name));
        writer.Write(" ON ");
...
      }
    }

As a result I want index name like IX_[Table]_[Column], using one of mentioned above conventions I can archive it.