Files
Deal/src/core/Deal.Infrastructure/Persistence/Configurations/SessionConfiguration.cs
T
Rustam Khalimov 410194b0cb Разбить Infrastructure и корень Deal.Api по назначению
Integrations -> Abstractions/Exceptions/Extensions/Models/Options/
Services (включая Storage); Persistence-конфигурации -> Configurations;
корень Deal.Api (оркестратор/планировщики/DTO) -> Services/Dtos.
namespace приведён к путям, using добавлены/дедуплицированы, FQN
обновлены.
2026-09-11 13:20:10 +03:00

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);
}
}