| | | 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="GovernanceOutboxEntryEntity" />. |
| | | 10 | | /// </summary> |
| | | 11 | | public sealed class GovernanceOutboxEntryEntityConfiguration |
| | | 12 | | : IEntityTypeConfiguration<GovernanceOutboxEntryEntity> |
| | | 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 DiagnosticTextMaxLength = 4096; |
| | | 28 | | private const int SerializedJsonMaxLength = 65536; |
| | | 29 | | private const int ConcurrencyStampMaxLength = 64; |
| | | 30 | | |
| | 1 | 31 | | private static readonly ValueConverter<DateTimeOffset, long> DateTimeOffsetToUtcTicksConverter = new( |
| | 1 | 32 | | value => value.ToUniversalTime().Ticks, |
| | 1 | 33 | | value => new DateTimeOffset(value, TimeSpan.Zero)); |
| | | 34 | | |
| | 1 | 35 | | private static readonly ValueConverter<DateTimeOffset?, long?> NullableDateTimeOffsetToUtcTicksConverter = new( |
| | 1 | 36 | | value => value.HasValue ? value.Value.ToUniversalTime().Ticks : null, |
| | 1 | 37 | | value => value.HasValue ? new DateTimeOffset(value.Value, TimeSpan.Zero) : null); |
| | | 38 | | |
| | | 39 | | /// <inheritdoc /> |
| | | 40 | | public void Configure(EntityTypeBuilder<GovernanceOutboxEntryEntity> builder) |
| | | 41 | | { |
| | 19 | 42 | | ArgumentNullException.ThrowIfNull(builder); |
| | | 43 | | |
| | 19 | 44 | | _ = builder.ToTable("AsiBackboneGovernanceOutboxEntries"); |
| | | 45 | | |
| | 19 | 46 | | _ = builder.HasKey(outboxEntry => outboxEntry.Id); |
| | | 47 | | |
| | 19 | 48 | | _ = builder.Property(outboxEntry => outboxEntry.Id) |
| | 19 | 49 | | .ValueGeneratedNever(); |
| | | 50 | | |
| | 19 | 51 | | _ = builder.Property(outboxEntry => outboxEntry.ConcurrencyStamp) |
| | 19 | 52 | | .IsRequired() |
| | 19 | 53 | | .HasMaxLength(ConcurrencyStampMaxLength) |
| | 19 | 54 | | .IsConcurrencyToken(); |
| | | 55 | | |
| | 19 | 56 | | _ = builder.Property(outboxEntry => outboxEntry.OutboxEntryId) |
| | 19 | 57 | | .IsRequired() |
| | 19 | 58 | | .HasMaxLength(IdentifierMaxLength); |
| | | 59 | | |
| | 19 | 60 | | _ = builder.Property(outboxEntry => outboxEntry.Status) |
| | 19 | 61 | | .HasConversion<string>() |
| | 19 | 62 | | .IsRequired() |
| | 19 | 63 | | .HasMaxLength(StatusMaxLength); |
| | | 64 | | |
| | 19 | 65 | | _ = builder.Property(outboxEntry => outboxEntry.CreatedUtc) |
| | 19 | 66 | | .HasConversion(DateTimeOffsetToUtcTicksConverter) |
| | 19 | 67 | | .IsRequired(); |
| | | 68 | | |
| | 19 | 69 | | _ = builder.Property(outboxEntry => outboxEntry.UpdatedUtc) |
| | 19 | 70 | | .HasConversion(DateTimeOffsetToUtcTicksConverter) |
| | 19 | 71 | | .IsRequired(); |
| | | 72 | | |
| | 19 | 73 | | _ = builder.Property(outboxEntry => outboxEntry.DeliveredUtc) |
| | 19 | 74 | | .HasConversion(NullableDateTimeOffsetToUtcTicksConverter); |
| | | 75 | | |
| | 19 | 76 | | _ = builder.Property(outboxEntry => outboxEntry.NextRetryUtc) |
| | 19 | 77 | | .HasConversion(NullableDateTimeOffsetToUtcTicksConverter); |
| | | 78 | | |
| | 19 | 79 | | _ = builder.Property(outboxEntry => outboxEntry.RetryCount) |
| | 19 | 80 | | .IsRequired(); |
| | | 81 | | |
| | 19 | 82 | | _ = builder.Property(outboxEntry => outboxEntry.MaxRetryCount) |
| | 19 | 83 | | .IsRequired(); |
| | | 84 | | |
| | 19 | 85 | | _ = builder.Property(outboxEntry => outboxEntry.ProviderName) |
| | 19 | 86 | | .HasMaxLength(ProviderMaxLength); |
| | | 87 | | |
| | 19 | 88 | | _ = builder.Property(outboxEntry => outboxEntry.ProviderRecordId) |
| | 19 | 89 | | .HasMaxLength(IdentifierMaxLength); |
| | | 90 | | |
| | 19 | 91 | | _ = builder.Property(outboxEntry => outboxEntry.DeadLetterReason) |
| | 19 | 92 | | .HasMaxLength(DiagnosticTextMaxLength); |
| | | 93 | | |
| | 19 | 94 | | _ = builder.Property(outboxEntry => outboxEntry.LastErrorCode) |
| | 19 | 95 | | .HasMaxLength(ErrorCodeMaxLength); |
| | | 96 | | |
| | 19 | 97 | | _ = builder.Property(outboxEntry => outboxEntry.LastErrorMessage) |
| | 19 | 98 | | .HasMaxLength(DiagnosticTextMaxLength); |
| | | 99 | | |
| | 19 | 100 | | _ = builder.Property(outboxEntry => outboxEntry.LastErrorProviderName) |
| | 19 | 101 | | .HasMaxLength(ProviderMaxLength); |
| | | 102 | | |
| | 19 | 103 | | _ = builder.Property(outboxEntry => outboxEntry.LastErrorProviderErrorCode) |
| | 19 | 104 | | .HasMaxLength(ProviderErrorCodeMaxLength); |
| | | 105 | | |
| | 19 | 106 | | _ = builder.Property(outboxEntry => outboxEntry.MetadataJson) |
| | 19 | 107 | | .IsRequired() |
| | 19 | 108 | | .HasMaxLength(SerializedJsonMaxLength); |
| | | 109 | | |
| | 19 | 110 | | _ = builder.Property(outboxEntry => outboxEntry.ClaimOwner) |
| | 19 | 111 | | .HasMaxLength(IdentifierMaxLength); |
| | | 112 | | |
| | 19 | 113 | | _ = builder.Property(outboxEntry => outboxEntry.ClaimToken) |
| | 19 | 114 | | .HasMaxLength(IdentifierMaxLength); |
| | | 115 | | |
| | 19 | 116 | | _ = builder.Property(outboxEntry => outboxEntry.ClaimedUtc) |
| | 19 | 117 | | .HasConversion(NullableDateTimeOffsetToUtcTicksConverter); |
| | | 118 | | |
| | 19 | 119 | | _ = builder.Property(outboxEntry => outboxEntry.ClaimExpiresUtc) |
| | 19 | 120 | | .HasConversion(NullableDateTimeOffsetToUtcTicksConverter); |
| | | 121 | | |
| | 19 | 122 | | _ = builder.Property(outboxEntry => outboxEntry.ClaimAttemptCount) |
| | 19 | 123 | | .IsRequired(); |
| | | 124 | | |
| | 19 | 125 | | _ = builder.Property(outboxEntry => outboxEntry.EnvelopeId) |
| | 19 | 126 | | .IsRequired() |
| | 19 | 127 | | .HasMaxLength(IdentifierMaxLength); |
| | | 128 | | |
| | 19 | 129 | | _ = builder.Property(outboxEntry => outboxEntry.EnvelopeSchemaVersion) |
| | 19 | 130 | | .IsRequired() |
| | 19 | 131 | | .HasMaxLength(SchemaVersionMaxLength); |
| | | 132 | | |
| | 19 | 133 | | _ = builder.Property(outboxEntry => outboxEntry.EnvelopeEventType) |
| | 19 | 134 | | .HasConversion<string>() |
| | 19 | 135 | | .IsRequired() |
| | 19 | 136 | | .HasMaxLength(StatusMaxLength); |
| | | 137 | | |
| | 19 | 138 | | _ = builder.Property(outboxEntry => outboxEntry.EnvelopeEventId) |
| | 19 | 139 | | .HasMaxLength(IdentifierMaxLength); |
| | | 140 | | |
| | 19 | 141 | | _ = builder.Property(outboxEntry => outboxEntry.EnvelopeOccurredUtc) |
| | 19 | 142 | | .HasConversion(DateTimeOffsetToUtcTicksConverter) |
| | 19 | 143 | | .IsRequired(); |
| | | 144 | | |
| | 19 | 145 | | _ = builder.Property(outboxEntry => outboxEntry.EnvelopeCreatedUtc) |
| | 19 | 146 | | .HasConversion(DateTimeOffsetToUtcTicksConverter) |
| | 19 | 147 | | .IsRequired(); |
| | | 148 | | |
| | 19 | 149 | | _ = builder.Property(outboxEntry => outboxEntry.EnvelopeCorrelationId) |
| | 19 | 150 | | .HasMaxLength(IdentifierMaxLength); |
| | | 151 | | |
| | 19 | 152 | | _ = builder.Property(outboxEntry => outboxEntry.EnvelopeDecisionReceiptId) |
| | 19 | 153 | | .HasMaxLength(IdentifierMaxLength); |
| | | 154 | | |
| | 19 | 155 | | _ = builder.Property(outboxEntry => outboxEntry.EnvelopeLifecycleStage) |
| | 19 | 156 | | .HasConversion<string>() |
| | 19 | 157 | | .HasMaxLength(StageMaxLength); |
| | | 158 | | |
| | 19 | 159 | | _ = builder.Property(outboxEntry => outboxEntry.EnvelopePolicyVersion) |
| | 19 | 160 | | .HasMaxLength(PolicyVersionMaxLength); |
| | | 161 | | |
| | 19 | 162 | | _ = builder.Property(outboxEntry => outboxEntry.EnvelopePolicyHash) |
| | 19 | 163 | | .HasMaxLength(HashMaxLength); |
| | | 164 | | |
| | 19 | 165 | | _ = builder.Property(outboxEntry => outboxEntry.EnvelopeTraceId) |
| | 19 | 166 | | .HasMaxLength(IdentifierMaxLength); |
| | | 167 | | |
| | 19 | 168 | | _ = builder.Property(outboxEntry => outboxEntry.EnvelopeSpanId) |
| | 19 | 169 | | .HasMaxLength(IdentifierMaxLength); |
| | | 170 | | |
| | 19 | 171 | | _ = builder.Property(outboxEntry => outboxEntry.EnvelopeParentSpanId) |
| | 19 | 172 | | .HasMaxLength(IdentifierMaxLength); |
| | | 173 | | |
| | 19 | 174 | | _ = builder.Property(outboxEntry => outboxEntry.EnvelopeOperationName) |
| | 19 | 175 | | .HasMaxLength(OperationNameMaxLength); |
| | | 176 | | |
| | 19 | 177 | | _ = builder.Property(outboxEntry => outboxEntry.EnvelopeOutcome) |
| | 19 | 178 | | .HasMaxLength(OutcomeMaxLength); |
| | | 179 | | |
| | 19 | 180 | | _ = builder.Property(outboxEntry => outboxEntry.EnvelopeActorId) |
| | 19 | 181 | | .HasMaxLength(IdentifierMaxLength); |
| | | 182 | | |
| | 19 | 183 | | _ = builder.Property(outboxEntry => outboxEntry.EnvelopeEmitterStatus) |
| | 19 | 184 | | .HasMaxLength(StatusMaxLength); |
| | | 185 | | |
| | 19 | 186 | | _ = builder.Property(outboxEntry => outboxEntry.EnvelopeEmitterProvider) |
| | 19 | 187 | | .HasMaxLength(ProviderMaxLength); |
| | | 188 | | |
| | 19 | 189 | | _ = builder.Property(outboxEntry => outboxEntry.EnvelopeGatewayExecutionId) |
| | 19 | 190 | | .HasMaxLength(IdentifierMaxLength); |
| | | 191 | | |
| | 19 | 192 | | _ = builder.Property(outboxEntry => outboxEntry.EnvelopeDecisionStage) |
| | 19 | 193 | | .HasMaxLength(StageMaxLength); |
| | | 194 | | |
| | 19 | 195 | | _ = builder.Property(outboxEntry => outboxEntry.EnvelopeMetadataJson) |
| | 19 | 196 | | .IsRequired() |
| | 19 | 197 | | .HasMaxLength(SerializedJsonMaxLength); |
| | | 198 | | |
| | 19 | 199 | | _ = builder.Property(outboxEntry => outboxEntry.EnvelopePayloadType) |
| | 19 | 200 | | .HasMaxLength(PayloadTypeMaxLength); |
| | | 201 | | |
| | 19 | 202 | | _ = builder.Property(outboxEntry => outboxEntry.EnvelopePayloadSchemaVersion) |
| | 19 | 203 | | .HasMaxLength(SchemaVersionMaxLength); |
| | | 204 | | |
| | 19 | 205 | | _ = builder.Property(outboxEntry => outboxEntry.EnvelopePayloadContentType) |
| | 19 | 206 | | .HasMaxLength(ContentTypeMaxLength); |
| | | 207 | | |
| | 19 | 208 | | _ = builder.Property(outboxEntry => outboxEntry.EnvelopePayloadContentHash) |
| | 19 | 209 | | .HasMaxLength(HashMaxLength); |
| | | 210 | | |
| | 19 | 211 | | _ = builder.Property(outboxEntry => outboxEntry.EnvelopePayloadMetadataJson) |
| | 19 | 212 | | .IsRequired() |
| | 19 | 213 | | .HasMaxLength(SerializedJsonMaxLength); |
| | | 214 | | |
| | 19 | 215 | | _ = builder.HasIndex(outboxEntry => outboxEntry.OutboxEntryId) |
| | 19 | 216 | | .IsUnique(); |
| | | 217 | | |
| | 19 | 218 | | _ = builder.HasIndex(outboxEntry => outboxEntry.ClaimToken); |
| | | 219 | | |
| | 19 | 220 | | _ = builder.HasIndex(outboxEntry => new |
| | 19 | 221 | | { |
| | 19 | 222 | | outboxEntry.Status, |
| | 19 | 223 | | outboxEntry.ClaimExpiresUtc, |
| | 19 | 224 | | outboxEntry.CreatedUtc, |
| | 19 | 225 | | outboxEntry.OutboxEntryId |
| | 19 | 226 | | }); |
| | | 227 | | |
| | 19 | 228 | | _ = builder.HasIndex(outboxEntry => new |
| | 19 | 229 | | { |
| | 19 | 230 | | outboxEntry.Status, |
| | 19 | 231 | | outboxEntry.ClaimExpiresUtc, |
| | 19 | 232 | | outboxEntry.NextRetryUtc, |
| | 19 | 233 | | outboxEntry.UpdatedUtc, |
| | 19 | 234 | | outboxEntry.OutboxEntryId |
| | 19 | 235 | | }); |
| | | 236 | | |
| | 19 | 237 | | _ = builder.HasIndex(outboxEntry => new |
| | 19 | 238 | | { |
| | 19 | 239 | | outboxEntry.Status, |
| | 19 | 240 | | outboxEntry.NextRetryUtc, |
| | 19 | 241 | | outboxEntry.UpdatedUtc, |
| | 19 | 242 | | outboxEntry.OutboxEntryId |
| | 19 | 243 | | }); |
| | | 244 | | |
| | 19 | 245 | | _ = builder.HasIndex(outboxEntry => new |
| | 19 | 246 | | { |
| | 19 | 247 | | outboxEntry.Status, |
| | 19 | 248 | | outboxEntry.CreatedUtc, |
| | 19 | 249 | | outboxEntry.OutboxEntryId |
| | 19 | 250 | | }); |
| | | 251 | | |
| | 19 | 252 | | } |
| | | 253 | | } |