1
0
mirror of https://github.com/bitwarden/server.git synced 2025-07-14 06:07:36 -05:00

[BEEEP][SM-1062] Add missing table indexes to EF config (#3628)

* Add missing EF indexes

* Add EF migrations

* move configs

* regenerate migrations
This commit is contained in:
Thomas Avery
2024-01-10 12:03:16 -06:00
committed by GitHub
parent 956efbdb39
commit 3392ede534
18 changed files with 7823 additions and 44 deletions

View File

@ -0,0 +1,26 @@
using Bit.Infrastructure.EntityFramework.Models;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace Bit.Infrastructure.EntityFramework.Configurations;
public class DeviceEntityTypeConfiguration : IEntityTypeConfiguration<Device>
{
public void Configure(EntityTypeBuilder<Device> builder)
{
builder
.HasIndex(d => d.UserId)
.IsClustered(false);
builder
.HasIndex(d => new { d.UserId, d.Identifier })
.IsUnique()
.IsClustered(false);
builder
.HasIndex(d => d.Identifier)
.IsClustered(false);
builder.ToTable(nameof(Device));
}
}

View File

@ -0,0 +1,21 @@
using Bit.Infrastructure.EntityFramework.Models;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace Bit.Infrastructure.EntityFramework.Configurations;
public class EventEntityTypeConfiguration : IEntityTypeConfiguration<Event>
{
public void Configure(EntityTypeBuilder<Event> builder)
{
builder
.Property(e => e.Id)
.ValueGeneratedNever();
builder
.HasIndex(e => new { e.Date, e.OrganizationId, e.ActingUserId, e.CipherId })
.IsClustered(false);
builder.ToTable(nameof(Event));
}
}

View File

@ -0,0 +1,21 @@
using Bit.Infrastructure.EntityFramework.Models;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace Bit.Infrastructure.EntityFramework.Configurations;
public class OrganizationSponsorshipEntityTypeConfiguration : IEntityTypeConfiguration<OrganizationSponsorship>
{
public void Configure(EntityTypeBuilder<OrganizationSponsorship> builder)
{
builder
.Property(o => o.Id)
.ValueGeneratedNever();
builder
.HasIndex(o => o.SponsoringOrganizationUserId)
.IsClustered(false);
builder.ToTable(nameof(OrganizationSponsorship));
}
}

View File

@ -0,0 +1,29 @@
using Bit.Infrastructure.EntityFramework.Models;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace Bit.Infrastructure.EntityFramework.Configurations;
public class OrganizationUserEntityTypeConfiguration : IEntityTypeConfiguration<OrganizationUser>
{
public void Configure(EntityTypeBuilder<OrganizationUser> builder)
{
builder
.Property(ou => ou.Id)
.ValueGeneratedNever();
NpgsqlIndexBuilderExtensions.IncludeProperties(
builder.HasIndex(ou => new { ou.UserId, ou.OrganizationId, ou.Status }).IsClustered(false),
ou => ou.AccessAll);
builder
.HasIndex(ou => ou.OrganizationId)
.IsClustered(false);
builder
.HasIndex(ou => ou.UserId)
.IsClustered(false);
builder.ToTable(nameof(OrganizationUser));
}
}

View File

@ -0,0 +1,25 @@
using Bit.Infrastructure.EntityFramework.Models;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace Bit.Infrastructure.EntityFramework.Configurations;
public class TransactionEntityTypeConfiguration : IEntityTypeConfiguration<Transaction>
{
public void Configure(EntityTypeBuilder<Transaction> builder)
{
builder
.Property(t => t.Id)
.ValueGeneratedNever();
builder
.HasIndex(t => t.UserId)
.IsClustered(false);
builder
.HasIndex(t => new { t.UserId, t.OrganizationId, t.CreationDate })
.IsClustered(false);
builder.ToTable(nameof(Transaction));
}
}

View File

@ -0,0 +1,26 @@
using Bit.Infrastructure.EntityFramework.Models;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace Bit.Infrastructure.EntityFramework.Configurations;
public class UserEntityTypeConfiguration : IEntityTypeConfiguration<User>
{
public void Configure(EntityTypeBuilder<User> builder)
{
builder
.Property(u => u.Id)
.ValueGeneratedNever();
builder
.HasIndex(u => u.Email)
.IsUnique()
.IsClustered(false);
builder
.HasIndex(u => new { u.Premium, u.PremiumExpirationDate, u.RenewalReminderDate })
.IsClustered(false);
builder.ToTable(nameof(User));
}
}