Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for issue 1638 #1643

Merged
merged 1 commit into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}