Skip to content

Commit

Permalink
Merge pull request #1643 from tejssidhu/issue1638
Browse files Browse the repository at this point in the history
Fix for issue 1638
  • Loading branch information
borisdj authored Dec 19, 2024
2 parents 1a98654 + 61eaf66 commit 6809edd
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -394,9 +394,11 @@ public static string CreateUniqueConstrain(TableInfo tableInfo)
/// <param name="tableInfo"></param>
public static string DropUniqueIndex(TableInfo tableInfo)
{
var schemaFormated = tableInfo.Schema == null ? "" : $@"""{tableInfo.Schema}"".";
var uniqueIndexName = GetUniqueIndexName(tableInfo);
var fullUniqueIndexNameFormated = $@"{schemaFormated}""{uniqueIndexName}""";

var q = $@"DROP INDEX ""{uniqueIndexName}"";";
var q = $@"DROP INDEX {fullUniqueIndexNameFormated};";
return q;
}

Expand Down Expand Up @@ -429,6 +431,7 @@ public static string GetUniqueIndexName(TableInfo tableInfo)
var uniqueColumnNamesDash = string.Join("_", uniqueColumnNames);
var schemaDash = tableInfo.Schema == null ? "" : $"{tableInfo.Schema}_";
var uniqueIndexName = $"tempUniqueIndex_{schemaDash}{tableName}_{uniqueColumnNamesDash}";
uniqueIndexName = uniqueIndexName.Length > 64 ? uniqueIndexName[..64] : uniqueIndexName;

return uniqueIndexName;
}
Expand Down
23 changes: 23 additions & 0 deletions EFCore.BulkExtensions.Tests/SqlQueryBuilderPostgreSqlTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,27 @@ public void RestructureForBatchWithJoinToOtherTablesTest()

Assert.Equal(expected, batchUpdate);
}

[Fact]
public void DropUniqueIndexNameTest()
{
TableInfo tableInfo = GetTestTableInfo();

string actual = PostgreSqlQueryBuilder.DropUniqueIndex(tableInfo);

string expected = @"DROP INDEX ""dbo"".""tempUniqueIndex_dbo_Item_ItemId"";";
Assert.Equal(expected, actual);
}

[Fact]
public void DropUniqueIndexNameWithLongTableNameTest()
{
TableInfo tableInfo = GetTestTableInfo();
tableInfo.TableName = "Temp1234567891011121314151617181920212223";

string actual = PostgreSqlQueryBuilder.DropUniqueIndex(tableInfo);

string expected = @"DROP INDEX ""dbo"".""tempUniqueIndex_dbo_Temp1234567891011121314151617181920212223_It"";";
Assert.Equal(expected, actual);
}
}

0 comments on commit 6809edd

Please sign in to comment.