| | | 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="AsiBackboneAuditLedgerRecordEntity" />. |
| | | 9 | | /// </summary> |
| | | 10 | | public sealed class AsiBackboneAuditLedgerRecordEntityConfiguration |
| | | 11 | | : IEntityTypeConfiguration<AsiBackboneAuditLedgerRecordEntity> |
| | | 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 ConcurrencyStampMaxLength = 64; |
| | | 31 | | |
| | | 32 | | /// <inheritdoc /> |
| | | 33 | | public void Configure(EntityTypeBuilder<AsiBackboneAuditLedgerRecordEntity> builder) |
| | | 34 | | { |
| | 36 | 35 | | ArgumentNullException.ThrowIfNull(builder); |
| | | 36 | | |
| | 36 | 37 | | _ = builder.ToTable("AsiBackboneAuditLedgerRecords"); |
| | | 38 | | |
| | 36 | 39 | | _ = builder.HasKey(record => record.Id); |
| | | 40 | | |
| | 36 | 41 | | _ = builder.Property(record => record.Id) |
| | 36 | 42 | | .ValueGeneratedNever(); |
| | | 43 | | |
| | 36 | 44 | | _ = builder.Property(record => record.ConcurrencyStamp) |
| | 36 | 45 | | .IsRequired() |
| | 36 | 46 | | .HasMaxLength(ConcurrencyStampMaxLength) |
| | 36 | 47 | | .IsConcurrencyToken(); |
| | | 48 | | |
| | 36 | 49 | | _ = builder.Property(record => record.RecordId) |
| | 36 | 50 | | .IsRequired() |
| | 36 | 51 | | .HasMaxLength(IdentifierMaxLength); |
| | | 52 | | |
| | 36 | 53 | | _ = builder.Property(record => record.SchemaVersion) |
| | 36 | 54 | | .IsRequired() |
| | 36 | 55 | | .HasMaxLength(SchemaVersionMaxLength); |
| | | 56 | | |
| | 36 | 57 | | _ = builder.Property(record => record.EventId) |
| | 36 | 58 | | .IsRequired() |
| | 36 | 59 | | .HasMaxLength(IdentifierMaxLength); |
| | | 60 | | |
| | 36 | 61 | | _ = builder.Property(record => record.AuditResidueId) |
| | 36 | 62 | | .HasMaxLength(IdentifierMaxLength); |
| | | 63 | | |
| | 36 | 64 | | _ = builder.Property(record => record.OccurredUtc) |
| | 36 | 65 | | .IsRequired(); |
| | | 66 | | |
| | 36 | 67 | | _ = builder.Property(record => record.RecordedUtc) |
| | 36 | 68 | | .IsRequired(); |
| | | 69 | | |
| | 36 | 70 | | _ = builder.Property(record => record.ActorId) |
| | 36 | 71 | | .IsRequired() |
| | 36 | 72 | | .HasMaxLength(IdentifierMaxLength); |
| | | 73 | | |
| | 36 | 74 | | _ = builder.Property(record => record.ActorType) |
| | 36 | 75 | | .HasConversion<string>() |
| | 36 | 76 | | .IsRequired() |
| | 36 | 77 | | .HasMaxLength(ActorTypeMaxLength); |
| | | 78 | | |
| | 36 | 79 | | _ = builder.Property(record => record.ActorDisplayName) |
| | 36 | 80 | | .HasMaxLength(DisplayNameMaxLength); |
| | | 81 | | |
| | 36 | 82 | | _ = builder.Property(record => record.OperationName) |
| | 36 | 83 | | .IsRequired() |
| | 36 | 84 | | .HasMaxLength(OperationNameMaxLength); |
| | | 85 | | |
| | 36 | 86 | | _ = builder.Property(record => record.Outcome) |
| | 36 | 87 | | .IsRequired() |
| | 36 | 88 | | .HasMaxLength(OutcomeMaxLength); |
| | | 89 | | |
| | 36 | 90 | | _ = builder.Property(record => record.ReasonCodesJson) |
| | 36 | 91 | | .IsRequired(); |
| | | 92 | | |
| | 36 | 93 | | _ = builder.Property(record => record.CorrelationId) |
| | 36 | 94 | | .HasMaxLength(CorrelationMaxLength); |
| | | 95 | | |
| | 36 | 96 | | _ = builder.Property(record => record.TraceId) |
| | 36 | 97 | | .HasMaxLength(CorrelationMaxLength); |
| | | 98 | | |
| | 36 | 99 | | _ = builder.Property(record => record.SpanId) |
| | 36 | 100 | | .HasMaxLength(CorrelationMaxLength); |
| | | 101 | | |
| | 36 | 102 | | _ = builder.Property(record => record.ParentSpanId) |
| | 36 | 103 | | .HasMaxLength(CorrelationMaxLength); |
| | | 104 | | |
| | 36 | 105 | | _ = builder.Property(record => record.ConstraintSetHash) |
| | 36 | 106 | | .HasMaxLength(HashMaxLength); |
| | | 107 | | |
| | 36 | 108 | | _ = builder.Property(record => record.PolicyScope) |
| | 36 | 109 | | .HasMaxLength(PolicyScopeMaxLength); |
| | | 110 | | |
| | 36 | 111 | | _ = builder.Property(record => record.TenantHash) |
| | 36 | 112 | | .HasMaxLength(HashMaxLength); |
| | | 113 | | |
| | 36 | 114 | | _ = builder.Property(record => record.OrganizationHash) |
| | 36 | 115 | | .HasMaxLength(HashMaxLength); |
| | | 116 | | |
| | 36 | 117 | | _ = builder.Property(record => record.EmitterStatus) |
| | 36 | 118 | | .HasMaxLength(StatusMaxLength); |
| | | 119 | | |
| | 36 | 120 | | _ = builder.Property(record => record.EmitterProvider) |
| | 36 | 121 | | .HasMaxLength(ProviderMaxLength); |
| | | 122 | | |
| | 36 | 123 | | _ = builder.Property(record => record.GatewayExecutionId) |
| | 36 | 124 | | .HasMaxLength(IdentifierMaxLength); |
| | | 125 | | |
| | 36 | 126 | | _ = builder.Property(record => record.DecisionStage) |
| | 36 | 127 | | .HasMaxLength(StageMaxLength); |
| | | 128 | | |
| | 36 | 129 | | _ = builder.Property(record => record.PolicyVersion) |
| | 36 | 130 | | .HasMaxLength(PolicyVersionMaxLength); |
| | | 131 | | |
| | 36 | 132 | | _ = builder.Property(record => record.PolicyHash) |
| | 36 | 133 | | .HasMaxLength(HashMaxLength); |
| | | 134 | | |
| | 36 | 135 | | _ = builder.Property(record => record.HandshakeId) |
| | 36 | 136 | | .HasMaxLength(IdentifierMaxLength); |
| | | 137 | | |
| | 36 | 138 | | _ = builder.Property(record => record.AcknowledgmentId) |
| | 36 | 139 | | .HasMaxLength(IdentifierMaxLength); |
| | | 140 | | |
| | 36 | 141 | | _ = builder.Property(record => record.CapabilityTokenId) |
| | 36 | 142 | | .HasMaxLength(IdentifierMaxLength); |
| | | 143 | | |
| | 36 | 144 | | _ = builder.Property(record => record.PreviousRecordHash) |
| | 36 | 145 | | .HasMaxLength(HashMaxLength); |
| | | 146 | | |
| | 36 | 147 | | _ = builder.Property(record => record.RecordHash) |
| | 36 | 148 | | .HasMaxLength(HashMaxLength); |
| | | 149 | | |
| | 36 | 150 | | _ = builder.Property(record => record.SigningHash) |
| | 36 | 151 | | .HasMaxLength(HashMaxLength); |
| | | 152 | | |
| | 36 | 153 | | _ = builder.Property(record => record.SignatureKeyId) |
| | 36 | 154 | | .HasMaxLength(SignatureKeyIdMaxLength); |
| | | 155 | | |
| | 36 | 156 | | _ = builder.Property(record => record.SignatureKeyVersion) |
| | 36 | 157 | | .HasMaxLength(SignatureKeyVersionMaxLength); |
| | | 158 | | |
| | 36 | 159 | | _ = builder.Property(record => record.SignatureAlgorithm) |
| | 36 | 160 | | .HasMaxLength(SignatureAlgorithmMaxLength); |
| | | 161 | | |
| | 36 | 162 | | _ = builder.Property(record => record.SignatureValue); |
| | | 163 | | |
| | 36 | 164 | | _ = builder.Property(record => record.SignatureProvider) |
| | 36 | 165 | | .HasMaxLength(SignatureProviderMaxLength); |
| | | 166 | | |
| | 36 | 167 | | _ = builder.Property(record => record.SignedUtc); |
| | | 168 | | |
| | 36 | 169 | | _ = builder.Property(record => record.MetadataJson) |
| | 36 | 170 | | .IsRequired(); |
| | | 171 | | |
| | 36 | 172 | | _ = builder.HasIndex(record => record.RecordId) |
| | 36 | 173 | | .IsUnique(); |
| | | 174 | | |
| | 36 | 175 | | _ = builder.HasIndex(record => record.SchemaVersion); |
| | | 176 | | |
| | 36 | 177 | | _ = builder.HasIndex(record => record.EventId); |
| | | 178 | | |
| | 36 | 179 | | _ = builder.HasIndex(record => record.AuditResidueId); |
| | | 180 | | |
| | 36 | 181 | | _ = builder.HasIndex(record => record.OccurredUtc); |
| | | 182 | | |
| | 36 | 183 | | _ = builder.HasIndex(record => record.RecordedUtc); |
| | | 184 | | |
| | 36 | 185 | | _ = builder.HasIndex(record => record.ActorId); |
| | | 186 | | |
| | 36 | 187 | | _ = builder.HasIndex(record => record.ActorType); |
| | | 188 | | |
| | 36 | 189 | | _ = builder.HasIndex(record => record.OperationName); |
| | | 190 | | |
| | 36 | 191 | | _ = builder.HasIndex(record => record.Outcome); |
| | | 192 | | |
| | 36 | 193 | | _ = builder.HasIndex(record => record.CorrelationId); |
| | | 194 | | |
| | 36 | 195 | | _ = builder.HasIndex(record => record.TraceId); |
| | | 196 | | |
| | 36 | 197 | | _ = builder.HasIndex(record => record.SpanId); |
| | | 198 | | |
| | 36 | 199 | | _ = builder.HasIndex(record => record.PolicyVersion); |
| | | 200 | | |
| | 36 | 201 | | _ = builder.HasIndex(record => record.PolicyHash); |
| | | 202 | | |
| | 36 | 203 | | _ = builder.HasIndex(record => record.PolicyScope); |
| | | 204 | | |
| | 36 | 205 | | _ = builder.HasIndex(record => record.TenantHash); |
| | | 206 | | |
| | 36 | 207 | | _ = builder.HasIndex(record => record.OrganizationHash); |
| | | 208 | | |
| | 36 | 209 | | _ = builder.HasIndex(record => record.EmitterStatus); |
| | | 210 | | |
| | 36 | 211 | | _ = builder.HasIndex(record => record.EmitterProvider); |
| | | 212 | | |
| | 36 | 213 | | _ = builder.HasIndex(record => record.OutboxSequence); |
| | | 214 | | |
| | 36 | 215 | | _ = builder.HasIndex(record => record.GatewayExecutionId); |
| | | 216 | | |
| | 36 | 217 | | _ = builder.HasIndex(record => record.DecisionStage); |
| | | 218 | | |
| | 36 | 219 | | _ = builder.HasIndex(record => record.HandshakeId); |
| | | 220 | | |
| | 36 | 221 | | _ = builder.HasIndex(record => record.AcknowledgmentId); |
| | | 222 | | |
| | 36 | 223 | | _ = builder.HasIndex(record => record.CapabilityTokenId); |
| | | 224 | | |
| | 36 | 225 | | _ = builder.HasIndex(record => record.RecordHash); |
| | | 226 | | |
| | 36 | 227 | | _ = builder.HasIndex(record => record.SigningHash); |
| | | 228 | | |
| | 36 | 229 | | _ = builder.HasIndex(record => record.SignatureKeyId); |
| | | 230 | | |
| | 36 | 231 | | _ = builder.HasIndex(record => record.SignatureKeyVersion); |
| | | 232 | | |
| | 36 | 233 | | _ = builder.HasIndex(record => record.SignatureProvider); |
| | | 234 | | |
| | 36 | 235 | | _ = builder.HasIndex(record => record.SignedUtc); |
| | | 236 | | |
| | 36 | 237 | | _ = builder.HasIndex(record => new |
| | 36 | 238 | | { |
| | 36 | 239 | | record.ActorId, |
| | 36 | 240 | | record.RecordedUtc |
| | 36 | 241 | | }); |
| | | 242 | | |
| | 36 | 243 | | _ = builder.HasIndex(record => new |
| | 36 | 244 | | { |
| | 36 | 245 | | record.CorrelationId, |
| | 36 | 246 | | record.RecordedUtc |
| | 36 | 247 | | }); |
| | 36 | 248 | | } |
| | | 249 | | } |