| | | 1 | | using AsiBackbone.EntityFrameworkCore.Persistence; |
| | | 2 | | using Microsoft.EntityFrameworkCore; |
| | | 3 | | using Microsoft.EntityFrameworkCore.Metadata.Builders; |
| | | 4 | | using Microsoft.EntityFrameworkCore.Storage.ValueConversion; |
| | | 5 | | |
| | | 6 | | namespace AsiBackbone.EntityFrameworkCore.Configurations; |
| | | 7 | | |
| | | 8 | | /// <summary> |
| | | 9 | | /// Configures the Entity Framework Core persistence mapping for <see cref="AsiBackboneGovernanceOutboxEntryEntity" />. |
| | | 10 | | /// </summary> |
| | | 11 | | public sealed class AsiBackboneGovernanceOutboxEntryEntityConfiguration |
| | | 12 | | : IEntityTypeConfiguration<AsiBackboneGovernanceOutboxEntryEntity> |
| | | 13 | | { |
| | | 14 | | private const int IdentifierMaxLength = 128; |
| | | 15 | | private const int SchemaVersionMaxLength = 64; |
| | | 16 | | private const int StatusMaxLength = 128; |
| | | 17 | | private const int ProviderMaxLength = 128; |
| | | 18 | | private const int ErrorCodeMaxLength = 128; |
| | | 19 | | private const int ProviderErrorCodeMaxLength = 128; |
| | | 20 | | private const int StageMaxLength = 128; |
| | | 21 | | private const int OperationNameMaxLength = 256; |
| | | 22 | | private const int OutcomeMaxLength = 128; |
| | | 23 | | private const int PolicyVersionMaxLength = 128; |
| | | 24 | | private const int HashMaxLength = 512; |
| | | 25 | | private const int ContentTypeMaxLength = 256; |
| | | 26 | | private const int PayloadTypeMaxLength = 128; |
| | | 27 | | private const int ConcurrencyStampMaxLength = 64; |
| | | 28 | | |
| | 2 | 29 | | private static readonly ValueConverter<DateTimeOffset, long> DateTimeOffsetToUtcTicksConverter = new( |
| | 2 | 30 | | value => value.ToUniversalTime().Ticks, |
| | 2 | 31 | | value => new DateTimeOffset(value, TimeSpan.Zero)); |
| | | 32 | | |
| | 2 | 33 | | private static readonly ValueConverter<DateTimeOffset?, long?> NullableDateTimeOffsetToUtcTicksConverter = new( |
| | 2 | 34 | | value => value.HasValue ? value.Value.ToUniversalTime().Ticks : null, |
| | 2 | 35 | | value => value.HasValue ? new DateTimeOffset(value.Value, TimeSpan.Zero) : null); |
| | | 36 | | |
| | | 37 | | /// <inheritdoc /> |
| | | 38 | | public void Configure(EntityTypeBuilder<AsiBackboneGovernanceOutboxEntryEntity> builder) |
| | | 39 | | { |
| | 36 | 40 | | ArgumentNullException.ThrowIfNull(builder); |
| | | 41 | | |
| | 36 | 42 | | _ = builder.ToTable("AsiBackboneGovernanceOutboxEntries"); |
| | | 43 | | |
| | 36 | 44 | | _ = builder.HasKey(outboxEntry => outboxEntry.Id); |
| | | 45 | | |
| | 36 | 46 | | _ = builder.Property(outboxEntry => outboxEntry.Id) |
| | 36 | 47 | | .ValueGeneratedNever(); |
| | | 48 | | |
| | 36 | 49 | | _ = builder.Property(outboxEntry => outboxEntry.ConcurrencyStamp) |
| | 36 | 50 | | .IsRequired() |
| | 36 | 51 | | .HasMaxLength(ConcurrencyStampMaxLength) |
| | 36 | 52 | | .IsConcurrencyToken(); |
| | | 53 | | |
| | 36 | 54 | | _ = builder.Property(outboxEntry => outboxEntry.OutboxEntryId) |
| | 36 | 55 | | .IsRequired() |
| | 36 | 56 | | .HasMaxLength(IdentifierMaxLength); |
| | | 57 | | |
| | 36 | 58 | | _ = builder.Property(outboxEntry => outboxEntry.Status) |
| | 36 | 59 | | .HasConversion<string>() |
| | 36 | 60 | | .IsRequired() |
| | 36 | 61 | | .HasMaxLength(StatusMaxLength); |
| | | 62 | | |
| | 36 | 63 | | _ = builder.Property(outboxEntry => outboxEntry.CreatedUtc) |
| | 36 | 64 | | .HasConversion(DateTimeOffsetToUtcTicksConverter) |
| | 36 | 65 | | .IsRequired(); |
| | | 66 | | |
| | 36 | 67 | | _ = builder.Property(outboxEntry => outboxEntry.UpdatedUtc) |
| | 36 | 68 | | .HasConversion(DateTimeOffsetToUtcTicksConverter) |
| | 36 | 69 | | .IsRequired(); |
| | | 70 | | |
| | 36 | 71 | | _ = builder.Property(outboxEntry => outboxEntry.DeliveredUtc) |
| | 36 | 72 | | .HasConversion(NullableDateTimeOffsetToUtcTicksConverter); |
| | | 73 | | |
| | 36 | 74 | | _ = builder.Property(outboxEntry => outboxEntry.NextRetryUtc) |
| | 36 | 75 | | .HasConversion(NullableDateTimeOffsetToUtcTicksConverter); |
| | | 76 | | |
| | 36 | 77 | | _ = builder.Property(outboxEntry => outboxEntry.RetryCount) |
| | 36 | 78 | | .IsRequired(); |
| | | 79 | | |
| | 36 | 80 | | _ = builder.Property(outboxEntry => outboxEntry.MaxRetryCount) |
| | 36 | 81 | | .IsRequired(); |
| | | 82 | | |
| | 36 | 83 | | _ = builder.Property(outboxEntry => outboxEntry.ProviderName) |
| | 36 | 84 | | .HasMaxLength(ProviderMaxLength); |
| | | 85 | | |
| | 36 | 86 | | _ = builder.Property(outboxEntry => outboxEntry.ProviderRecordId) |
| | 36 | 87 | | .HasMaxLength(IdentifierMaxLength); |
| | | 88 | | |
| | 36 | 89 | | _ = builder.Property(outboxEntry => outboxEntry.LastErrorCode) |
| | 36 | 90 | | .HasMaxLength(ErrorCodeMaxLength); |
| | | 91 | | |
| | 36 | 92 | | _ = builder.Property(outboxEntry => outboxEntry.LastErrorProviderName) |
| | 36 | 93 | | .HasMaxLength(ProviderMaxLength); |
| | | 94 | | |
| | 36 | 95 | | _ = builder.Property(outboxEntry => outboxEntry.LastErrorProviderErrorCode) |
| | 36 | 96 | | .HasMaxLength(ProviderErrorCodeMaxLength); |
| | | 97 | | |
| | 36 | 98 | | _ = builder.Property(outboxEntry => outboxEntry.MetadataJson) |
| | 36 | 99 | | .IsRequired(); |
| | | 100 | | |
| | 36 | 101 | | _ = builder.Property(outboxEntry => outboxEntry.ClaimOwner) |
| | 36 | 102 | | .HasMaxLength(IdentifierMaxLength); |
| | | 103 | | |
| | 36 | 104 | | _ = builder.Property(outboxEntry => outboxEntry.ClaimToken) |
| | 36 | 105 | | .HasMaxLength(IdentifierMaxLength); |
| | | 106 | | |
| | 36 | 107 | | _ = builder.Property(outboxEntry => outboxEntry.ClaimedUtc) |
| | 36 | 108 | | .HasConversion(NullableDateTimeOffsetToUtcTicksConverter); |
| | | 109 | | |
| | 36 | 110 | | _ = builder.Property(outboxEntry => outboxEntry.ClaimExpiresUtc) |
| | 36 | 111 | | .HasConversion(NullableDateTimeOffsetToUtcTicksConverter); |
| | | 112 | | |
| | 36 | 113 | | _ = builder.Property(outboxEntry => outboxEntry.ClaimAttemptCount) |
| | 36 | 114 | | .IsRequired(); |
| | | 115 | | |
| | 36 | 116 | | _ = builder.Property(outboxEntry => outboxEntry.EnvelopeId) |
| | 36 | 117 | | .IsRequired() |
| | 36 | 118 | | .HasMaxLength(IdentifierMaxLength); |
| | | 119 | | |
| | 36 | 120 | | _ = builder.Property(outboxEntry => outboxEntry.EnvelopeSchemaVersion) |
| | 36 | 121 | | .IsRequired() |
| | 36 | 122 | | .HasMaxLength(SchemaVersionMaxLength); |
| | | 123 | | |
| | 36 | 124 | | _ = builder.Property(outboxEntry => outboxEntry.EnvelopeEventType) |
| | 36 | 125 | | .HasConversion<string>() |
| | 36 | 126 | | .IsRequired() |
| | 36 | 127 | | .HasMaxLength(StatusMaxLength); |
| | | 128 | | |
| | 36 | 129 | | _ = builder.Property(outboxEntry => outboxEntry.EnvelopeEventId) |
| | 36 | 130 | | .HasMaxLength(IdentifierMaxLength); |
| | | 131 | | |
| | 36 | 132 | | _ = builder.Property(outboxEntry => outboxEntry.EnvelopeOccurredUtc) |
| | 36 | 133 | | .HasConversion(DateTimeOffsetToUtcTicksConverter) |
| | 36 | 134 | | .IsRequired(); |
| | | 135 | | |
| | 36 | 136 | | _ = builder.Property(outboxEntry => outboxEntry.EnvelopeCreatedUtc) |
| | 36 | 137 | | .HasConversion(DateTimeOffsetToUtcTicksConverter) |
| | 36 | 138 | | .IsRequired(); |
| | | 139 | | |
| | 36 | 140 | | _ = builder.Property(outboxEntry => outboxEntry.EnvelopeCorrelationId) |
| | 36 | 141 | | .HasMaxLength(IdentifierMaxLength); |
| | | 142 | | |
| | 36 | 143 | | _ = builder.Property(outboxEntry => outboxEntry.EnvelopeAuditResidueId) |
| | 36 | 144 | | .HasMaxLength(IdentifierMaxLength); |
| | | 145 | | |
| | 36 | 146 | | _ = builder.Property(outboxEntry => outboxEntry.EnvelopeLifecycleStage) |
| | 36 | 147 | | .HasConversion<string>() |
| | 36 | 148 | | .HasMaxLength(StageMaxLength); |
| | | 149 | | |
| | 36 | 150 | | _ = builder.Property(outboxEntry => outboxEntry.EnvelopePolicyVersion) |
| | 36 | 151 | | .HasMaxLength(PolicyVersionMaxLength); |
| | | 152 | | |
| | 36 | 153 | | _ = builder.Property(outboxEntry => outboxEntry.EnvelopePolicyHash) |
| | 36 | 154 | | .HasMaxLength(HashMaxLength); |
| | | 155 | | |
| | 36 | 156 | | _ = builder.Property(outboxEntry => outboxEntry.EnvelopeTraceId) |
| | 36 | 157 | | .HasMaxLength(IdentifierMaxLength); |
| | | 158 | | |
| | 36 | 159 | | _ = builder.Property(outboxEntry => outboxEntry.EnvelopeSpanId) |
| | 36 | 160 | | .HasMaxLength(IdentifierMaxLength); |
| | | 161 | | |
| | 36 | 162 | | _ = builder.Property(outboxEntry => outboxEntry.EnvelopeParentSpanId) |
| | 36 | 163 | | .HasMaxLength(IdentifierMaxLength); |
| | | 164 | | |
| | 36 | 165 | | _ = builder.Property(outboxEntry => outboxEntry.EnvelopeOperationName) |
| | 36 | 166 | | .HasMaxLength(OperationNameMaxLength); |
| | | 167 | | |
| | 36 | 168 | | _ = builder.Property(outboxEntry => outboxEntry.EnvelopeOutcome) |
| | 36 | 169 | | .HasMaxLength(OutcomeMaxLength); |
| | | 170 | | |
| | 36 | 171 | | _ = builder.Property(outboxEntry => outboxEntry.EnvelopeActorId) |
| | 36 | 172 | | .HasMaxLength(IdentifierMaxLength); |
| | | 173 | | |
| | 36 | 174 | | _ = builder.Property(outboxEntry => outboxEntry.EnvelopeEmitterStatus) |
| | 36 | 175 | | .HasMaxLength(StatusMaxLength); |
| | | 176 | | |
| | 36 | 177 | | _ = builder.Property(outboxEntry => outboxEntry.EnvelopeEmitterProvider) |
| | 36 | 178 | | .HasMaxLength(ProviderMaxLength); |
| | | 179 | | |
| | 36 | 180 | | _ = builder.Property(outboxEntry => outboxEntry.EnvelopeGatewayExecutionId) |
| | 36 | 181 | | .HasMaxLength(IdentifierMaxLength); |
| | | 182 | | |
| | 36 | 183 | | _ = builder.Property(outboxEntry => outboxEntry.EnvelopeDecisionStage) |
| | 36 | 184 | | .HasMaxLength(StageMaxLength); |
| | | 185 | | |
| | 36 | 186 | | _ = builder.Property(outboxEntry => outboxEntry.EnvelopeMetadataJson) |
| | 36 | 187 | | .IsRequired(); |
| | | 188 | | |
| | 36 | 189 | | _ = builder.Property(outboxEntry => outboxEntry.EnvelopePayloadType) |
| | 36 | 190 | | .HasMaxLength(PayloadTypeMaxLength); |
| | | 191 | | |
| | 36 | 192 | | _ = builder.Property(outboxEntry => outboxEntry.EnvelopePayloadSchemaVersion) |
| | 36 | 193 | | .HasMaxLength(SchemaVersionMaxLength); |
| | | 194 | | |
| | 36 | 195 | | _ = builder.Property(outboxEntry => outboxEntry.EnvelopePayloadContentType) |
| | 36 | 196 | | .HasMaxLength(ContentTypeMaxLength); |
| | | 197 | | |
| | 36 | 198 | | _ = builder.Property(outboxEntry => outboxEntry.EnvelopePayloadContentHash) |
| | 36 | 199 | | .HasMaxLength(HashMaxLength); |
| | | 200 | | |
| | 36 | 201 | | _ = builder.Property(outboxEntry => outboxEntry.EnvelopePayloadMetadataJson) |
| | 36 | 202 | | .IsRequired(); |
| | | 203 | | |
| | 36 | 204 | | _ = builder.HasIndex(outboxEntry => outboxEntry.OutboxEntryId) |
| | 36 | 205 | | .IsUnique(); |
| | | 206 | | |
| | 36 | 207 | | _ = builder.HasIndex(outboxEntry => outboxEntry.Status); |
| | | 208 | | |
| | 36 | 209 | | _ = builder.HasIndex(outboxEntry => outboxEntry.NextRetryUtc); |
| | | 210 | | |
| | 36 | 211 | | _ = builder.HasIndex(outboxEntry => outboxEntry.CreatedUtc); |
| | | 212 | | |
| | 36 | 213 | | _ = builder.HasIndex(outboxEntry => outboxEntry.UpdatedUtc); |
| | | 214 | | |
| | 36 | 215 | | _ = builder.HasIndex(outboxEntry => outboxEntry.DeliveredUtc); |
| | | 216 | | |
| | 36 | 217 | | _ = builder.HasIndex(outboxEntry => outboxEntry.ProviderName); |
| | | 218 | | |
| | 36 | 219 | | _ = builder.HasIndex(outboxEntry => outboxEntry.ProviderRecordId); |
| | | 220 | | |
| | 36 | 221 | | _ = builder.HasIndex(outboxEntry => outboxEntry.LastErrorCode); |
| | | 222 | | |
| | 36 | 223 | | _ = builder.HasIndex(outboxEntry => outboxEntry.ClaimOwner); |
| | | 224 | | |
| | 36 | 225 | | _ = builder.HasIndex(outboxEntry => outboxEntry.ClaimToken); |
| | | 226 | | |
| | 36 | 227 | | _ = builder.HasIndex(outboxEntry => outboxEntry.ClaimExpiresUtc); |
| | | 228 | | |
| | 36 | 229 | | _ = builder.HasIndex(outboxEntry => outboxEntry.EnvelopeId); |
| | | 230 | | |
| | 36 | 231 | | _ = builder.HasIndex(outboxEntry => outboxEntry.EnvelopeEventId); |
| | | 232 | | |
| | 36 | 233 | | _ = builder.HasIndex(outboxEntry => outboxEntry.EnvelopeCorrelationId); |
| | | 234 | | |
| | 36 | 235 | | _ = builder.HasIndex(outboxEntry => outboxEntry.EnvelopeAuditResidueId); |
| | | 236 | | |
| | 36 | 237 | | _ = builder.HasIndex(outboxEntry => outboxEntry.EnvelopePolicyVersion); |
| | | 238 | | |
| | 36 | 239 | | _ = builder.HasIndex(outboxEntry => outboxEntry.EnvelopePolicyHash); |
| | | 240 | | |
| | 36 | 241 | | _ = builder.HasIndex(outboxEntry => outboxEntry.EnvelopeTraceId); |
| | | 242 | | |
| | 36 | 243 | | _ = builder.HasIndex(outboxEntry => outboxEntry.EnvelopeOutboxSequence); |
| | | 244 | | |
| | 36 | 245 | | _ = builder.HasIndex(outboxEntry => new |
| | 36 | 246 | | { |
| | 36 | 247 | | outboxEntry.Status, |
| | 36 | 248 | | outboxEntry.ClaimExpiresUtc, |
| | 36 | 249 | | outboxEntry.CreatedUtc, |
| | 36 | 250 | | outboxEntry.OutboxEntryId |
| | 36 | 251 | | }); |
| | | 252 | | |
| | 36 | 253 | | _ = builder.HasIndex(outboxEntry => new |
| | 36 | 254 | | { |
| | 36 | 255 | | outboxEntry.Status, |
| | 36 | 256 | | outboxEntry.ClaimExpiresUtc, |
| | 36 | 257 | | outboxEntry.NextRetryUtc, |
| | 36 | 258 | | outboxEntry.UpdatedUtc, |
| | 36 | 259 | | outboxEntry.OutboxEntryId |
| | 36 | 260 | | }); |
| | | 261 | | |
| | 36 | 262 | | _ = builder.HasIndex(outboxEntry => new |
| | 36 | 263 | | { |
| | 36 | 264 | | outboxEntry.Status, |
| | 36 | 265 | | outboxEntry.NextRetryUtc, |
| | 36 | 266 | | outboxEntry.UpdatedUtc, |
| | 36 | 267 | | outboxEntry.OutboxEntryId |
| | 36 | 268 | | }); |
| | | 269 | | |
| | 36 | 270 | | _ = builder.HasIndex(outboxEntry => new |
| | 36 | 271 | | { |
| | 36 | 272 | | outboxEntry.Status, |
| | 36 | 273 | | outboxEntry.CreatedUtc, |
| | 36 | 274 | | outboxEntry.OutboxEntryId |
| | 36 | 275 | | }); |
| | | 276 | | |
| | 36 | 277 | | _ = builder.HasIndex(outboxEntry => new |
| | 36 | 278 | | { |
| | 36 | 279 | | outboxEntry.EnvelopeCorrelationId, |
| | 36 | 280 | | outboxEntry.CreatedUtc |
| | 36 | 281 | | }); |
| | | 282 | | |
| | 36 | 283 | | _ = builder.HasIndex(outboxEntry => new |
| | 36 | 284 | | { |
| | 36 | 285 | | outboxEntry.EnvelopeAuditResidueId, |
| | 36 | 286 | | outboxEntry.CreatedUtc |
| | 36 | 287 | | }); |
| | 36 | 288 | | } |
| | | 289 | | } |