1
0
mirror of https://github.com/bitwarden/server synced 2025-12-25 04:33:26 +00:00

[SM-1591] Adding SecretVersion table to server (#6406)

* Adding SecretVersion table to server

* making the names singular not plural for new table

* removing migration

* fixing migration

* Adding indexes for serviceacct and orguserId

* indexes for sqllite

* fixing migrations

* adding indexes to secretVeriosn.sql

* tests

* removing tests

* adding GO
This commit is contained in:
cd-bitwarden
2025-10-16 15:35:14 -04:00
committed by GitHub
parent 449603d180
commit 2965b499e9
16 changed files with 10640 additions and 0 deletions

View File

@@ -63,6 +63,7 @@ public class DatabaseContext : DbContext
public DbSet<Policy> Policies { get; set; }
public DbSet<Provider> Providers { get; set; }
public DbSet<Secret> Secret { get; set; }
public DbSet<SecretVersion> SecretVersion { get; set; }
public DbSet<ServiceAccount> ServiceAccount { get; set; }
public DbSet<Project> Project { get; set; }
public DbSet<ProviderUser> ProviderUsers { get; set; }

View File

@@ -0,0 +1,42 @@
using Bit.Infrastructure.EntityFramework.SecretsManager.Models;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace Bit.Infrastructure.EntityFramework.SecretsManager.Configurations;
public class SecretVersionEntityTypeConfiguration : IEntityTypeConfiguration<SecretVersion>
{
public void Configure(EntityTypeBuilder<SecretVersion> builder)
{
builder.Property(sv => sv.Id)
.ValueGeneratedNever();
builder.HasKey(sv => sv.Id)
.IsClustered();
builder.Property(sv => sv.Value)
.IsRequired();
builder.Property(sv => sv.VersionDate)
.IsRequired();
builder.HasOne(sv => sv.EditorServiceAccount)
.WithMany()
.HasForeignKey(sv => sv.EditorServiceAccountId)
.OnDelete(DeleteBehavior.SetNull);
builder.HasOne(sv => sv.EditorOrganizationUser)
.WithMany()
.HasForeignKey(sv => sv.EditorOrganizationUserId)
.OnDelete(DeleteBehavior.SetNull);
builder.HasIndex(sv => sv.SecretId)
.HasDatabaseName("IX_SecretVersion_SecretId");
builder.HasIndex(sv => sv.EditorServiceAccountId)
.HasDatabaseName("IX_SecretVersion_EditorServiceAccountId");
builder.HasIndex(sv => sv.EditorOrganizationUserId)
.HasDatabaseName("IX_SecretVersion_EditorOrganizationUserId");
}
}

View File

@@ -13,6 +13,7 @@ public class Secret : Core.SecretsManager.Entities.Secret
public virtual ICollection<UserSecretAccessPolicy> UserAccessPolicies { get; set; }
public virtual ICollection<GroupSecretAccessPolicy> GroupAccessPolicies { get; set; }
public virtual ICollection<ServiceAccountSecretAccessPolicy> ServiceAccountAccessPolicies { get; set; }
public virtual ICollection<SecretVersion> SecretVersions { get; set; }
}
public class SecretMapperProfile : Profile

View File

@@ -0,0 +1,24 @@
#nullable enable
using AutoMapper;
namespace Bit.Infrastructure.EntityFramework.SecretsManager.Models;
public class SecretVersion : Core.SecretsManager.Entities.SecretVersion
{
public Secret? Secret { get; set; }
public ServiceAccount? EditorServiceAccount { get; set; }
public Bit.Infrastructure.EntityFramework.Models.OrganizationUser? EditorOrganizationUser { get; set; }
}
public class SecretVersionMapperProfile : Profile
{
public SecretVersionMapperProfile()
{
CreateMap<Core.SecretsManager.Entities.SecretVersion, SecretVersion>()
.PreserveReferences()
.ReverseMap();
}
}