Skip to content
Open
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 @@ -72,15 +72,13 @@ protected override void OnModelCreating(ModelBuilder builder)

// Going forward use `IEntityTypeConfiguration` in the Configurations folder for managing
// Entity Framework code first database configurations.
var eCipher = builder.Entity<Cipher>();
var eCollection = builder.Entity<Collection>();
var eCollectionCipher = builder.Entity<CollectionCipher>();
var eCollectionUser = builder.Entity<CollectionUser>();
var eCollectionGroup = builder.Entity<CollectionGroup>();
var eDevice = builder.Entity<Device>();
var eEmergencyAccess = builder.Entity<EmergencyAccess>();
var eEvent = builder.Entity<Event>();
var eFolder = builder.Entity<Folder>();
var eGroup = builder.Entity<Group>();
var eGroupUser = builder.Entity<GroupUser>();
var eInstallation = builder.Entity<Installation>();
Expand All @@ -102,11 +100,9 @@ protected override void OnModelCreating(ModelBuilder builder)
var eOrganizationDomain = builder.Entity<OrganizationDomain>();
var aWebAuthnCredential = builder.Entity<WebAuthnCredential>();

eCipher.Property(c => c.Id).ValueGeneratedNever();
eCollection.Property(c => c.Id).ValueGeneratedNever();
eEmergencyAccess.Property(c => c.Id).ValueGeneratedNever();
eEvent.Property(c => c.Id).ValueGeneratedNever();
eFolder.Property(c => c.Id).ValueGeneratedNever();
eGroup.Property(c => c.Id).ValueGeneratedNever();
eInstallation.Property(c => c.Id).ValueGeneratedNever();
eOrganization.Property(c => c.Id).ValueGeneratedNever();
Expand Down Expand Up @@ -152,13 +148,11 @@ protected override void OnModelCreating(ModelBuilder builder)
//
}

eCipher.ToTable(nameof(Cipher));
eCollection.ToTable(nameof(Collection));
eCollectionCipher.ToTable(nameof(CollectionCipher));
eDevice.ToTable(nameof(Device));
eEmergencyAccess.ToTable(nameof(EmergencyAccess));
eEvent.ToTable(nameof(Event));
eFolder.ToTable(nameof(Folder));
eGroup.ToTable(nameof(Group));
eGroupUser.ToTable(nameof(GroupUser));
eInstallation.ToTable(nameof(Installation));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using Bit.Infrastructure.EntityFramework.Vault.Models;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Bit.Infrastructure.EntityFramework.Vault.Configurations;

public class CipherEntityTypeConfiguration : IEntityTypeConfiguration<Cipher>
{
public void Configure(EntityTypeBuilder<Cipher> builder)
{
builder
.Property(c => c.Id)
.ValueGeneratedNever();

NpgsqlIndexBuilderExtensions.IncludeProperties(
builder.HasIndex(c => new { c.UserId, c.OrganizationId })
.IsClustered(false),
c =>
new
{
c.Type,
c.Data,
c.Favorites,
c.Folders,
c.Attachments,
c.CreationDate,
c.RevisionDate,
c.DeletedDate,
});
Comment on lines +15 to +29
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: NpgsqlIndexBuilderExtensions is used, which may not be compatible with other database providers


builder
.HasIndex(c => c.OrganizationId)
.IsClustered(false);

builder
.HasIndex(c => c.DeletedDate)
.IsClustered(false);

builder
.HasIndex(c => c.UserId)
.IsClustered(false);

builder.ToTable(nameof(Cipher));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Bit.Infrastructure.EntityFramework.Vault.Models;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Bit.Infrastructure.EntityFramework.Vault.Configurations;

public class FolderEntityTypeConfiguration : IEntityTypeConfiguration<Folder>
{
public void Configure(EntityTypeBuilder<Folder> builder)
{
builder
.Property(f => f.Id)
.ValueGeneratedNever();

NpgsqlIndexBuilderExtensions.IncludeProperties(
builder.HasIndex(f => f.UserId)
.IsClustered(false),
f =>
new { f.Name, f.CreationDate, f.RevisionDate });
Comment on lines +15 to +19
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: NpgsqlIndexBuilderExtensions is specific to PostgreSQL. This may cause issues with other database providers.


builder.ToTable(nameof(Folder));
}
}
Loading