diff --git a/src/modules/Elsa.Secrets.Persistence.EFCore.Oracle/Configurations/Secrets.cs b/src/modules/Elsa.Secrets.Persistence.EFCore.Oracle/Configurations/Secrets.cs index 4b9fc89d8..c715fc483 100644 --- a/src/modules/Elsa.Secrets.Persistence.EFCore.Oracle/Configurations/Secrets.cs +++ b/src/modules/Elsa.Secrets.Persistence.EFCore.Oracle/Configurations/Secrets.cs @@ -1,4 +1,5 @@ using Elsa.Secrets.Models; +using Elsa.Secrets.Persistence.EFCore; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; @@ -8,7 +9,7 @@ public class SecretsConfiguration : IEntityTypeConfiguration { public void Configure(EntityTypeBuilder builder) { - builder.Property("SerializedTags").HasColumnName("Tags").HasColumnType("NCLOB").IsRequired(); - builder.Property("SerializedVersions").HasColumnName("Versions").HasColumnType("NCLOB").IsRequired(); + builder.Property(SecretShadowPropertyNames.SerializedTags).HasColumnName("Tags").HasColumnType("NCLOB").IsRequired(); + builder.Property(SecretShadowPropertyNames.SerializedVersions).HasColumnName("Versions").HasColumnType("NCLOB").IsRequired(); } } diff --git a/src/modules/Elsa.Secrets.Persistence.EFCore.Sqlite/Migrations/Secrets/20260531141623_Initial.cs b/src/modules/Elsa.Secrets.Persistence.EFCore.Sqlite/Migrations/Secrets/20260531141623_Initial.cs index 7a95d5e3f..9625c00a3 100644 --- a/src/modules/Elsa.Secrets.Persistence.EFCore.Sqlite/Migrations/Secrets/20260531141623_Initial.cs +++ b/src/modules/Elsa.Secrets.Persistence.EFCore.Sqlite/Migrations/Secrets/20260531141623_Initial.cs @@ -1,4 +1,6 @@ -using Microsoft.EntityFrameworkCore.Migrations; +using System; +using Elsa.Persistence.EFCore; +using Microsoft.EntityFrameworkCore.Migrations; #nullable disable @@ -7,11 +9,11 @@ namespace Elsa.Secrets.Persistence.EFCore.Sqlite.Migrations.Secrets /// public partial class Initial : Migration { - private readonly Elsa.Persistence.EFCore.IElsaDbContextSchema _schema; + private readonly IElsaDbContextSchema _schema; - public Initial(Elsa.Persistence.EFCore.IElsaDbContextSchema schema) + public Initial(IElsaDbContextSchema schema) { - _schema = schema; + _schema = schema ?? throw new ArgumentNullException(nameof(schema)); } /// diff --git a/src/modules/Elsa.Secrets.Persistence.EFCore/Repositories/EFCoreSecretRepository.cs b/src/modules/Elsa.Secrets.Persistence.EFCore/Repositories/EFCoreSecretRepository.cs index bf6fdaac8..c5ec513d9 100644 --- a/src/modules/Elsa.Secrets.Persistence.EFCore/Repositories/EFCoreSecretRepository.cs +++ b/src/modules/Elsa.Secrets.Persistence.EFCore/Repositories/EFCoreSecretRepository.cs @@ -108,12 +108,12 @@ public class EFCoreSecretRepository(Store store) : private static Task FindByNameAsync(SecretsElsaDbContext dbContext, string name, CancellationToken cancellationToken) { var normalizedName = NormalizeName(name); - return dbContext.Secrets.FirstOrDefaultAsync(x => EF.Property(x, SecretConfiguration.NormalizedNamePropertyName) == normalizedName, cancellationToken); + return dbContext.Secrets.FirstOrDefaultAsync(x => EF.Property(x, SecretShadowPropertyNames.NormalizedName) == normalizedName, cancellationToken); } private static Task ExistsByNormalizedNameAsync(SecretsElsaDbContext dbContext, string normalizedName, CancellationToken cancellationToken) { - return dbContext.Secrets.AnyAsync(x => EF.Property(x, SecretConfiguration.NormalizedNamePropertyName) == normalizedName, cancellationToken); + return dbContext.Secrets.AnyAsync(x => EF.Property(x, SecretShadowPropertyNames.NormalizedName) == normalizedName, cancellationToken); } private async Task SaveChangesAsync(SecretsElsaDbContext dbContext, string name, CancellationToken cancellationToken) @@ -155,7 +155,7 @@ public class EFCoreSecretRepository(Store store) : private static void SetNormalizedName(SecretsElsaDbContext dbContext, Secret secret) { - dbContext.Entry(secret).Property(SecretConfiguration.NormalizedNamePropertyName).CurrentValue = NormalizeName(secret.Name); + dbContext.Entry(secret).Property(SecretShadowPropertyNames.NormalizedName).CurrentValue = NormalizeName(secret.Name); } private static string NormalizeName(string name) => name.Trim().ToLowerInvariant(); diff --git a/src/modules/Elsa.Secrets.Persistence.EFCore/SecretConfiguration.cs b/src/modules/Elsa.Secrets.Persistence.EFCore/SecretConfiguration.cs index 46ea12dea..ab3319d4e 100644 --- a/src/modules/Elsa.Secrets.Persistence.EFCore/SecretConfiguration.cs +++ b/src/modules/Elsa.Secrets.Persistence.EFCore/SecretConfiguration.cs @@ -6,24 +6,22 @@ namespace Elsa.Secrets.Persistence.EFCore; internal class SecretConfiguration : IEntityTypeConfiguration { - public const string NormalizedNamePropertyName = "NormalizedName"; - public void Configure(EntityTypeBuilder builder) { builder.HasKey(x => x.Id); builder.Ignore(x => x.Tags); builder.Ignore(x => x.Versions); builder.Ignore(x => x.LatestActiveVersion); - builder.Property(SecretSerialization.SerializedTagsPropertyName).HasColumnName("Tags").IsRequired(); - builder.Property(SecretSerialization.SerializedVersionsPropertyName).HasColumnName("Versions").IsRequired(); + builder.Property(SecretShadowPropertyNames.SerializedTags).HasColumnName("Tags").IsRequired(); + builder.Property(SecretShadowPropertyNames.SerializedVersions).HasColumnName("Versions").IsRequired(); builder.Property(x => x.Name).HasMaxLength(200).IsRequired(); - builder.Property(NormalizedNamePropertyName).HasMaxLength(200).IsRequired(); + builder.Property(SecretShadowPropertyNames.NormalizedName).HasMaxLength(200).IsRequired(); builder.Property(x => x.DisplayName).HasMaxLength(200).IsRequired(); builder.Property(x => x.TypeName).HasMaxLength(100).IsRequired(); builder.Property(x => x.StoreName).HasMaxLength(100).IsRequired(); builder.Property(x => x.Scope).HasMaxLength(200); builder.Property(x => x.Status).HasConversion().HasMaxLength(32).IsRequired(); - builder.HasIndex(NormalizedNamePropertyName).HasDatabaseName($"IX_{nameof(Secret)}_{NormalizedNamePropertyName}").IsUnique(); + builder.HasIndex(SecretShadowPropertyNames.NormalizedName).HasDatabaseName($"IX_{nameof(Secret)}_{SecretShadowPropertyNames.NormalizedName}").IsUnique(); builder.HasIndex(x => x.TypeName).HasDatabaseName($"IX_{nameof(Secret)}_{nameof(Secret.TypeName)}"); builder.HasIndex(x => x.StoreName).HasDatabaseName($"IX_{nameof(Secret)}_{nameof(Secret.StoreName)}"); builder.HasIndex(x => x.Scope).HasDatabaseName($"IX_{nameof(Secret)}_{nameof(Secret.Scope)}"); diff --git a/src/modules/Elsa.Secrets.Persistence.EFCore/SecretSerialization.cs b/src/modules/Elsa.Secrets.Persistence.EFCore/SecretSerialization.cs index f608fc3cd..e9a84d5b0 100644 --- a/src/modules/Elsa.Secrets.Persistence.EFCore/SecretSerialization.cs +++ b/src/modules/Elsa.Secrets.Persistence.EFCore/SecretSerialization.cs @@ -7,9 +7,6 @@ namespace Elsa.Secrets.Persistence.EFCore; internal static class SecretSerialization { - public const string SerializedTagsPropertyName = "SerializedTags"; - public const string SerializedVersionsPropertyName = "SerializedVersions"; - private static readonly JsonSerializerOptions JsonOptions = new(JsonSerializerDefaults.Web) { Converters = { new JsonStringEnumConverter() } @@ -17,8 +14,8 @@ internal static class SecretSerialization public static void StoreSerializedProperties(DbContext dbContext, Secret secret) { - dbContext.Entry(secret).Property(SerializedTagsPropertyName).CurrentValue = JsonSerializer.Serialize(secret.Tags.Order(StringComparer.OrdinalIgnoreCase), JsonOptions); - dbContext.Entry(secret).Property(SerializedVersionsPropertyName).CurrentValue = JsonSerializer.Serialize(secret.Versions, JsonOptions); + dbContext.Entry(secret).Property(SecretShadowPropertyNames.SerializedTags).CurrentValue = JsonSerializer.Serialize(secret.Tags.Order(StringComparer.OrdinalIgnoreCase), JsonOptions); + dbContext.Entry(secret).Property(SecretShadowPropertyNames.SerializedVersions).CurrentValue = JsonSerializer.Serialize(secret.Versions, JsonOptions); } public static void LoadSerializedProperties(DbContext dbContext, Secret? secret) @@ -26,8 +23,8 @@ internal static class SecretSerialization if (secret == null) return; - var tagsJson = dbContext.Entry(secret).Property(SerializedTagsPropertyName).CurrentValue; - var versionsJson = dbContext.Entry(secret).Property(SerializedVersionsPropertyName).CurrentValue; + var tagsJson = dbContext.Entry(secret).Property(SecretShadowPropertyNames.SerializedTags).CurrentValue; + var versionsJson = dbContext.Entry(secret).Property(SecretShadowPropertyNames.SerializedVersions).CurrentValue; var tags = Deserialize(tagsJson, static () => new List()); var versions = Deserialize(versionsJson, static () => new List()); secret.Tags = tags.ToHashSet(StringComparer.OrdinalIgnoreCase); diff --git a/src/modules/Elsa.Secrets.Persistence.EFCore/SecretShadowPropertyNames.cs b/src/modules/Elsa.Secrets.Persistence.EFCore/SecretShadowPropertyNames.cs new file mode 100644 index 000000000..ea488f0b6 --- /dev/null +++ b/src/modules/Elsa.Secrets.Persistence.EFCore/SecretShadowPropertyNames.cs @@ -0,0 +1,8 @@ +namespace Elsa.Secrets.Persistence.EFCore; + +public static class SecretShadowPropertyNames +{ + public const string NormalizedName = "NormalizedName"; + public const string SerializedTags = "SerializedTags"; + public const string SerializedVersions = "SerializedVersions"; +}