| | | 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>Configures durable capability-grant use records.</summary> |
| | | 9 | | public sealed class CapabilityGrantUseEntityConfiguration : IEntityTypeConfiguration<CapabilityGrantUseEntity> |
| | | 10 | | { |
| | 1 | 11 | | private static readonly ValueConverter<DateTimeOffset, long> DateTimeOffsetToUtcTicksConverter = new( |
| | 1 | 12 | | value => value.ToUniversalTime().Ticks, |
| | 1 | 13 | | value => new DateTimeOffset(value, TimeSpan.Zero)); |
| | | 14 | | |
| | | 15 | | /// <inheritdoc /> |
| | | 16 | | public void Configure(EntityTypeBuilder<CapabilityGrantUseEntity> builder) |
| | | 17 | | { |
| | 20 | 18 | | ArgumentNullException.ThrowIfNull(builder); |
| | 20 | 19 | | _ = builder.ToTable("AsiBackboneCapabilityGrantUses"); |
| | 20 | 20 | | _ = builder.HasKey(entity => entity.Id); |
| | 20 | 21 | | _ = builder.Property(entity => entity.Id).ValueGeneratedNever(); |
| | 20 | 22 | | _ = builder.Property(entity => entity.ConcurrencyStamp).IsRequired().HasMaxLength(64).IsConcurrencyToken(); |
| | 20 | 23 | | _ = builder.Property(entity => entity.Issuer).IsRequired().HasMaxLength(256); |
| | 20 | 24 | | _ = builder.Property(entity => entity.TokenId).IsRequired().HasMaxLength(256); |
| | 20 | 25 | | _ = builder.Property(entity => entity.UseCount).IsRequired(); |
| | 20 | 26 | | _ = builder.Property(entity => entity.State).HasConversion<string>().IsRequired().HasMaxLength(64); |
| | 20 | 27 | | _ = builder.Property(entity => entity.LastUsedUtc).HasConversion(DateTimeOffsetToUtcTicksConverter).IsRequired() |
| | 20 | 28 | | _ = builder.Property(entity => entity.RetainUntilUtc).HasConversion(DateTimeOffsetToUtcTicksConverter).IsRequire |
| | 20 | 29 | | _ = builder.HasIndex(entity => new { entity.Issuer, entity.TokenId }).IsUnique(); |
| | 20 | 30 | | _ = builder.HasIndex(entity => entity.RetainUntilUtc); |
| | 20 | 31 | | } |
| | | 32 | | } |