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

Change index type from "btree" to "hash" for text columns #824

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Backbone.Modules.Devices.Infrastructure.Database.Postgres.Migrations
{
/// <inheritdoc />
public partial class HashIndexesForIds : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropIndex(
name: "IX_Identities_ClientId",
schema: "Devices",
table: "Identities");

migrationBuilder.DropIndex(
name: "IX_Identities_TierId",
schema: "Devices",
table: "Identities");

migrationBuilder.CreateIndex(
name: "IX_Identities_ClientId",
schema: "Devices",
table: "Identities",
column: "ClientId")
.Annotation("Npgsql:IndexMethod", "hash");

migrationBuilder.CreateIndex(
name: "IX_Identities_TierId",
schema: "Devices",
table: "Identities",
column: "TierId")
.Annotation("Npgsql:IndexMethod", "hash");
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropIndex(
name: "IX_Identities_ClientId",
schema: "Devices",
table: "Identities");

migrationBuilder.DropIndex(
name: "IX_Identities_TierId",
schema: "Devices",
table: "Identities");

migrationBuilder.CreateIndex(
name: "IX_Identities_ClientId",
schema: "Devices",
table: "Identities",
column: "ClientId");

migrationBuilder.CreateIndex(
name: "IX_Identities_TierId",
schema: "Devices",
table: "Identities",
column: "TierId");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)
#pragma warning disable 612, 618
modelBuilder
.HasDefaultSchema("Devices")
.HasAnnotation("ProductVersion", "8.0.6")
.HasAnnotation("ProductVersion", "8.0.8")
.HasAnnotation("Relational:MaxIdentifierLength", 63);

NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
Expand Down Expand Up @@ -273,8 +273,12 @@ protected override void BuildModel(ModelBuilder modelBuilder)

b.HasIndex("ClientId");

NpgsqlIndexBuilderExtensions.HasMethod(b.HasIndex("ClientId"), "hash");

b.HasIndex("TierId");

NpgsqlIndexBuilderExtensions.HasMethod(b.HasIndex("TierId"), "hash");

b.ToTable("Identities", "Devices");
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ public override void Configure(EntityTypeBuilder<Identity> builder)
builder.Property(x => x.ClientId).HasMaxLength(200);
builder.Property(x => x.CreatedAt);
builder.Property(x => x.PublicKey);
builder.HasIndex(x => x.ClientId);
builder.HasIndex(x => x.TierId);
builder.HasIndex(x => x.ClientId).HasMethod("hash");
builder.HasIndex(x => x.TierId).HasMethod("hash");

builder.HasMany(x => x.DeletionProcesses).WithOne().OnDelete(DeleteBehavior.Cascade);
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Backbone.Modules.Messages.Infrastructure.Database.Postgres.Migrations
{
/// <inheritdoc />
public partial class HashIndexForMessageCreatedByField : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropIndex(
name: "IX_Messages_CreatedBy",
schema: "Messages",
table: "Messages");

migrationBuilder.CreateIndex(
name: "IX_Messages_CreatedBy",
schema: "Messages",
table: "Messages",
column: "CreatedBy")
.Annotation("Npgsql:IndexMethod", "hash");
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropIndex(
name: "IX_Messages_CreatedBy",
schema: "Messages",
table: "Messages");

migrationBuilder.CreateIndex(
name: "IX_Messages_CreatedBy",
schema: "Messages",
table: "Messages",
column: "CreatedBy");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)
#pragma warning disable 612, 618
modelBuilder
.HasDefaultSchema("Messages")
.HasAnnotation("ProductVersion", "8.0.6")
.HasAnnotation("ProductVersion", "8.0.8")
.HasAnnotation("Relational:MaxIdentifierLength", 63);

NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
Expand Down Expand Up @@ -76,6 +76,8 @@ protected override void BuildModel(ModelBuilder modelBuilder)

b.HasIndex("CreatedBy");

NpgsqlIndexBuilderExtensions.HasMethod(b.HasIndex("CreatedBy"), "hash");

b.ToTable("Messages", "Messages");
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Backbone.BuildingBlocks.Infrastructure.Persistence.Database.EntityTypeConfigurations;
using Backbone.Modules.Messages.Domain.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Backbone.Modules.Messages.Infrastructure.Persistence.Database.EntityConfigurations;
Expand All @@ -10,7 +11,7 @@ public override void Configure(EntityTypeBuilder<Message> builder)
{
base.Configure(builder);

builder.HasIndex(m => m.CreatedBy);
builder.HasIndex(m => m.CreatedBy).HasMethod("hash");

builder.Property(m => m.Body).IsRequired(false);
builder.Property(x => x.CreatedByDevice);
Expand Down
Loading