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;
///
/// EF-конфигурация сессии: таблица sessions в схеме public.
///
public sealed class SessionConfiguration : IEntityTypeConfiguration
{
private const int TokenHashMaxLength = 64;
private const int LoginMaxLength = 200;
public void Configure(EntityTypeBuilder 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()
.WithMany()
.HasForeignKey(x => x.UserId)
.OnDelete(DeleteBehavior.Cascade);
}
}