| | | 1 | | using AsiBackbone.EntityFrameworkCore.Persistence; |
| | | 2 | | using Microsoft.EntityFrameworkCore; |
| | | 3 | | using Microsoft.EntityFrameworkCore.Metadata.Builders; |
| | | 4 | | |
| | | 5 | | namespace AsiBackbone.EntityFrameworkCore.Configurations; |
| | | 6 | | |
| | | 7 | | /// <summary> |
| | | 8 | | /// Configures the Entity Framework Core persistence mapping for <see cref="AuditLedgerRecordEntity" />. |
| | | 9 | | /// </summary> |
| | | 10 | | public sealed class AuditLedgerRecordEntityConfiguration |
| | | 11 | | : IEntityTypeConfiguration<AuditLedgerRecordEntity> |
| | | 12 | | { |
| | | 13 | | private const int IdentifierMaxLength = 128; |
| | | 14 | | private const int SchemaVersionMaxLength = 64; |
| | | 15 | | private const int DisplayNameMaxLength = 256; |
| | | 16 | | private const int OperationNameMaxLength = 256; |
| | | 17 | | private const int OutcomeMaxLength = 128; |
| | | 18 | | private const int ActorTypeMaxLength = 64; |
| | | 19 | | private const int CorrelationMaxLength = 128; |
| | | 20 | | private const int PolicyVersionMaxLength = 128; |
| | | 21 | | private const int PolicyScopeMaxLength = 256; |
| | | 22 | | private const int StatusMaxLength = 128; |
| | | 23 | | private const int ProviderMaxLength = 128; |
| | | 24 | | private const int StageMaxLength = 128; |
| | | 25 | | private const int HashMaxLength = 512; |
| | | 26 | | private const int SignatureKeyIdMaxLength = 128; |
| | | 27 | | private const int SignatureKeyVersionMaxLength = 128; |
| | | 28 | | private const int SignatureAlgorithmMaxLength = 128; |
| | | 29 | | private const int SignatureProviderMaxLength = 128; |
| | | 30 | | private const int SignatureValueMaxLength = 16384; |
| | | 31 | | private const int SerializedJsonMaxLength = 65536; |
| | | 32 | | private const int ConcurrencyStampMaxLength = 64; |
| | | 33 | | |
| | | 34 | | /// <inheritdoc /> |
| | | 35 | | public void Configure(EntityTypeBuilder<AuditLedgerRecordEntity> builder) |
| | | 36 | | { |
| | 19 | 37 | | ArgumentNullException.ThrowIfNull(builder); |
| | | 38 | | |
| | 19 | 39 | | _ = builder.ToTable("AsiBackboneAuditLedgerRecords"); |
| | | 40 | | |
| | 19 | 41 | | _ = builder.HasKey(record => record.Id); |
| | | 42 | | |
| | 19 | 43 | | _ = builder.Property(record => record.Id) |
| | 19 | 44 | | .ValueGeneratedNever(); |
| | | 45 | | |
| | 19 | 46 | | _ = builder.Property(record => record.ConcurrencyStamp) |
| | 19 | 47 | | .IsRequired() |
| | 19 | 48 | | .HasMaxLength(ConcurrencyStampMaxLength) |
| | 19 | 49 | | .IsConcurrencyToken(); |
| | | 50 | | |
| | 19 | 51 | | _ = builder.Property(record => record.RecordId) |
| | 19 | 52 | | .IsRequired() |
| | 19 | 53 | | .HasMaxLength(IdentifierMaxLength); |
| | | 54 | | |
| | 19 | 55 | | _ = builder.Property(record => record.SchemaVersion) |
| | 19 | 56 | | .IsRequired() |
| | 19 | 57 | | .HasMaxLength(SchemaVersionMaxLength); |
| | | 58 | | |
| | 19 | 59 | | _ = builder.Property(record => record.EventId) |
| | 19 | 60 | | .IsRequired() |
| | 19 | 61 | | .HasMaxLength(IdentifierMaxLength); |
| | | 62 | | |
| | 19 | 63 | | _ = builder.Property(record => record.DecisionReceiptId) |
| | 19 | 64 | | .HasMaxLength(IdentifierMaxLength); |
| | | 65 | | |
| | 19 | 66 | | _ = builder.Property(record => record.OccurredUtc) |
| | 19 | 67 | | .IsRequired(); |
| | | 68 | | |
| | 19 | 69 | | _ = builder.Property(record => record.RecordedUtc) |
| | 19 | 70 | | .IsRequired(); |
| | | 71 | | |
| | 19 | 72 | | _ = builder.Property(record => record.ActorId) |
| | 19 | 73 | | .IsRequired() |
| | 19 | 74 | | .HasMaxLength(IdentifierMaxLength); |
| | | 75 | | |
| | 19 | 76 | | _ = builder.Property(record => record.ActorType) |
| | 19 | 77 | | .HasConversion<string>() |
| | 19 | 78 | | .IsRequired() |
| | 19 | 79 | | .HasMaxLength(ActorTypeMaxLength); |
| | | 80 | | |
| | 19 | 81 | | _ = builder.Property(record => record.ActorDisplayName) |
| | 19 | 82 | | .HasMaxLength(DisplayNameMaxLength); |
| | | 83 | | |
| | 19 | 84 | | _ = builder.Property(record => record.OperationName) |
| | 19 | 85 | | .IsRequired() |
| | 19 | 86 | | .HasMaxLength(OperationNameMaxLength); |
| | | 87 | | |
| | 19 | 88 | | _ = builder.Property(record => record.Outcome) |
| | 19 | 89 | | .IsRequired() |
| | 19 | 90 | | .HasMaxLength(OutcomeMaxLength); |
| | | 91 | | |
| | 19 | 92 | | _ = builder.Property(record => record.ReasonCodesJson) |
| | 19 | 93 | | .IsRequired() |
| | 19 | 94 | | .HasMaxLength(SerializedJsonMaxLength); |
| | | 95 | | |
| | 19 | 96 | | _ = builder.Property(record => record.CorrelationId) |
| | 19 | 97 | | .HasMaxLength(CorrelationMaxLength); |
| | | 98 | | |
| | 19 | 99 | | _ = builder.Property(record => record.TraceId) |
| | 19 | 100 | | .HasMaxLength(CorrelationMaxLength); |
| | | 101 | | |
| | 19 | 102 | | _ = builder.Property(record => record.SpanId) |
| | 19 | 103 | | .HasMaxLength(CorrelationMaxLength); |
| | | 104 | | |
| | 19 | 105 | | _ = builder.Property(record => record.ParentSpanId) |
| | 19 | 106 | | .HasMaxLength(CorrelationMaxLength); |
| | | 107 | | |
| | 19 | 108 | | _ = builder.Property(record => record.ConstraintSetHash) |
| | 19 | 109 | | .HasMaxLength(HashMaxLength); |
| | | 110 | | |
| | 19 | 111 | | _ = builder.Property(record => record.PolicyScope) |
| | 19 | 112 | | .HasMaxLength(PolicyScopeMaxLength); |
| | | 113 | | |
| | 19 | 114 | | _ = builder.Property(record => record.TenantHash) |
| | 19 | 115 | | .HasMaxLength(HashMaxLength); |
| | | 116 | | |
| | 19 | 117 | | _ = builder.Property(record => record.OrganizationHash) |
| | 19 | 118 | | .HasMaxLength(HashMaxLength); |
| | | 119 | | |
| | 19 | 120 | | _ = builder.Property(record => record.EmitterStatus) |
| | 19 | 121 | | .HasMaxLength(StatusMaxLength); |
| | | 122 | | |
| | 19 | 123 | | _ = builder.Property(record => record.EmitterProvider) |
| | 19 | 124 | | .HasMaxLength(ProviderMaxLength); |
| | | 125 | | |
| | 19 | 126 | | _ = builder.Property(record => record.GatewayExecutionId) |
| | 19 | 127 | | .HasMaxLength(IdentifierMaxLength); |
| | | 128 | | |
| | 19 | 129 | | _ = builder.Property(record => record.DecisionStage) |
| | 19 | 130 | | .HasMaxLength(StageMaxLength); |
| | | 131 | | |
| | 19 | 132 | | _ = builder.Property(record => record.PolicyVersion) |
| | 19 | 133 | | .HasMaxLength(PolicyVersionMaxLength); |
| | | 134 | | |
| | 19 | 135 | | _ = builder.Property(record => record.PolicyHash) |
| | 19 | 136 | | .HasMaxLength(HashMaxLength); |
| | | 137 | | |
| | 19 | 138 | | _ = builder.Property(record => record.HandshakeId) |
| | 19 | 139 | | .HasMaxLength(IdentifierMaxLength); |
| | | 140 | | |
| | 19 | 141 | | _ = builder.Property(record => record.AcknowledgmentId) |
| | 19 | 142 | | .HasMaxLength(IdentifierMaxLength); |
| | | 143 | | |
| | 19 | 144 | | _ = builder.Property(record => record.CapabilityTokenId) |
| | 19 | 145 | | .HasMaxLength(IdentifierMaxLength); |
| | | 146 | | |
| | 19 | 147 | | _ = builder.Property(record => record.PreviousRecordHash) |
| | 19 | 148 | | .HasMaxLength(HashMaxLength); |
| | | 149 | | |
| | 19 | 150 | | _ = builder.Property(record => record.RecordHash) |
| | 19 | 151 | | .HasMaxLength(HashMaxLength); |
| | | 152 | | |
| | 19 | 153 | | _ = builder.Property(record => record.SigningHash) |
| | 19 | 154 | | .HasMaxLength(HashMaxLength); |
| | | 155 | | |
| | 19 | 156 | | _ = builder.Property(record => record.SignatureKeyId) |
| | 19 | 157 | | .HasMaxLength(SignatureKeyIdMaxLength); |
| | | 158 | | |
| | 19 | 159 | | _ = builder.Property(record => record.SignatureKeyVersion) |
| | 19 | 160 | | .HasMaxLength(SignatureKeyVersionMaxLength); |
| | | 161 | | |
| | 19 | 162 | | _ = builder.Property(record => record.SignatureAlgorithm) |
| | 19 | 163 | | .HasMaxLength(SignatureAlgorithmMaxLength); |
| | | 164 | | |
| | 19 | 165 | | _ = builder.Property(record => record.SignatureValue) |
| | 19 | 166 | | .HasMaxLength(SignatureValueMaxLength); |
| | | 167 | | |
| | 19 | 168 | | _ = builder.Property(record => record.SignatureProvider) |
| | 19 | 169 | | .HasMaxLength(SignatureProviderMaxLength); |
| | | 170 | | |
| | 19 | 171 | | _ = builder.Property(record => record.SignedUtc); |
| | | 172 | | |
| | 19 | 173 | | _ = builder.Property(record => record.MetadataJson) |
| | 19 | 174 | | .IsRequired() |
| | 19 | 175 | | .HasMaxLength(SerializedJsonMaxLength); |
| | | 176 | | |
| | 19 | 177 | | _ = builder.HasIndex(record => record.RecordId) |
| | 19 | 178 | | .IsUnique(); |
| | | 179 | | |
| | 19 | 180 | | _ = builder.HasIndex(record => new |
| | 19 | 181 | | { |
| | 19 | 182 | | record.RecordedUtc, |
| | 19 | 183 | | record.RecordId |
| | 19 | 184 | | }); |
| | | 185 | | |
| | 19 | 186 | | _ = builder.HasIndex(record => new |
| | 19 | 187 | | { |
| | 19 | 188 | | record.ActorId, |
| | 19 | 189 | | record.RecordedUtc, |
| | 19 | 190 | | record.RecordId |
| | 19 | 191 | | }); |
| | | 192 | | |
| | 19 | 193 | | _ = builder.HasIndex(record => new |
| | 19 | 194 | | { |
| | 19 | 195 | | record.CorrelationId, |
| | 19 | 196 | | record.RecordedUtc, |
| | 19 | 197 | | record.RecordId |
| | 19 | 198 | | }); |
| | | 199 | | |
| | 19 | 200 | | _ = builder.HasIndex(record => new |
| | 19 | 201 | | { |
| | 19 | 202 | | record.TraceId, |
| | 19 | 203 | | record.RecordedUtc, |
| | 19 | 204 | | record.RecordId |
| | 19 | 205 | | }); |
| | | 206 | | |
| | 19 | 207 | | _ = builder.HasIndex(record => record.PreviousRecordHash); |
| | 19 | 208 | | } |
| | | 209 | | } |