Skip to content
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 @@ -8,13 +8,13 @@
<PackageReadmeFile>Readme.md</PackageReadmeFile>
<Authors>Pandatech</Authors>
<Copyright>MIT</Copyright>
<Version>5.0.0</Version>
<Version>5.1.0</Version>
<PackageId>Pandatech.EFCore.PostgresExtensions</PackageId>
<Title>Pandatech.EFCore.PostgresExtensions</Title>
<PackageTags>Pandatech, library, EntityFrameworkCore, PostgreSQL, For Update, Lock, LockingSyntax, Bulk insert, BinaryCopy</PackageTags>
<Description>The Pandatech.EFCore.PostgresExtensions library enriches Entity Framework Core applications with advanced PostgreSQL functionalities, starting with the ForUpdate locking syntax and BulkInsert function. Designed for seamless integration, this NuGet package aims to enhance the efficiency and capabilities of EF Core models when working with PostgreSQL, with the potential for further PostgreSQL-specific extensions.</Description>
<RepositoryUrl>https://github.com/PandaTechAM/be-lib-efcore-postgres-extensions</RepositoryUrl>
<PackageReleaseNotes>Removed bulk copy totally. Added Natural Sort functionality</PackageReleaseNotes>
<PackageReleaseNotes>Added support to generate unique index on encrypted columns</PackageReleaseNotes>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,40 @@ public static void CreateNaturalSortKeyFunction(this MigrationBuilder migrationB
{
migrationBuilder.Sql(PgFunctionHelpers.GetNaturalSortKeyFunction());
}

public static MigrationBuilder CreateUniqueIndexOnEncryptedColumn(this MigrationBuilder migrationBuilder,
string tableName,
string columnName,
string? condition)
{
var indexName = $"ix_{tableName}_{columnName}";
var whereClause = !string.IsNullOrWhiteSpace(condition) ? $" WHERE {condition}" : string.Empty;

var sql = $@"
CREATE UNIQUE INDEX {indexName}
ON {tableName} (substr({columnName}, 1, 64)){whereClause};";

migrationBuilder.Sql(sql);

return migrationBuilder;
}

public static MigrationBuilder CreateUniqueIndexOnEncryptedColumn(this MigrationBuilder migrationBuilder,
string tableName,
string columnName)
{
return migrationBuilder.CreateUniqueIndexOnEncryptedColumn(tableName, columnName, null);
}

public static MigrationBuilder DropUniqueIndexOnEncryptedColumn(this MigrationBuilder migrationBuilder,
string tableName,
string columnName)
{
var indexName = $"ix_{tableName}_{columnName}";

migrationBuilder.Sql($@"
DROP INDEX {indexName};");

return migrationBuilder;
}
}