Integrations -> Abstractions/Exceptions/Extensions/Models/Options/ Services (включая Storage); Persistence-конфигурации -> Configurations; корень Deal.Api (оркестратор/планировщики/DTO) -> Services/Dtos. namespace приведён к путям, using добавлены/дедуплицированы, FQN обновлены.
37 lines
1.2 KiB
C#
37 lines
1.2 KiB
C#
using Deal.Infrastructure.Persistence.Entities;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
|
using Deal.Infrastructure.Persistence;
|
|
using Deal.Infrastructure.Persistence.Configurations;
|
|
|
|
namespace Deal.Infrastructure.Persistence.Configurations;
|
|
|
|
/// <summary>
|
|
/// EF-конфигурация сессии: таблица sessions в схеме public.
|
|
/// </summary>
|
|
public sealed class SessionConfiguration : IEntityTypeConfiguration<SessionEntity>
|
|
{
|
|
private const int TokenHashMaxLength = 64;
|
|
private const int LoginMaxLength = 200;
|
|
|
|
public void Configure(EntityTypeBuilder<SessionEntity> builder)
|
|
{
|
|
builder.ToTable("sessions", "public");
|
|
|
|
builder.HasKey(x => x.TokenHash);
|
|
|
|
builder.Property(x => x.TokenHash).HasMaxLength(TokenHashMaxLength);
|
|
builder.Property(x => x.Login).HasMaxLength(LoginMaxLength).IsRequired();
|
|
builder.Property(x => x.ExpiresAt).IsRequired();
|
|
builder.Property(x => x.CreatedAt).IsRequired();
|
|
|
|
builder.HasIndex(x => x.UserId);
|
|
builder.HasIndex(x => x.ExpiresAt);
|
|
|
|
builder.HasOne<UserEntity>()
|
|
.WithMany()
|
|
.HasForeignKey(x => x.UserId)
|
|
.OnDelete(DeleteBehavior.Cascade);
|
|
}
|
|
}
|