using Deal.Infrastructure.Persistence.Entities; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; namespace Deal.Infrastructure.Persistence.Configurations; /// /// EF-конфигурация пользователя /// public sealed class UserConfiguration : IEntityTypeConfiguration { private const int LoginMaxLength = 200; public void Configure(EntityTypeBuilder builder) { builder.ToTable("users", "public"); builder.HasKey(x => x.Id); builder.Property(x => x.Login).HasMaxLength(LoginMaxLength).IsRequired(); builder.Property(x => x.PasswordHash).IsRequired(); builder.Property(x => x.Status).IsRequired().HasDefaultValue("active"); builder.Property(x => x.CreatedAt).IsRequired().HasDefaultValueSql("now()"); builder.HasIndex(x => x.Login).IsUnique(); builder.HasIndex(x => x.TenantId); builder.HasOne() .WithMany() .HasForeignKey(x => x.TenantId) .OnDelete(DeleteBehavior.Restrict); } }