Add users & migrations

This commit is contained in:
lumijiez
2025-06-06 19:15:50 +03:00
parent 8a2cb322fc
commit 27a59d7049
10 changed files with 1513 additions and 0 deletions

View File

@@ -0,0 +1,65 @@
using Imprink.Domain.Entities.Users;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace Imprink.Infrastructure.Configuration.Users;
public class UserConfiguration : EntityBaseConfiguration<User>
{
public override void Configure(EntityTypeBuilder<User> builder)
{
base.Configure(builder);
builder.Property(u => u.Id)
.HasMaxLength(450)
.ValueGeneratedNever();
builder.Property(u => u.Email)
.IsRequired()
.HasMaxLength(256);
builder.Property(u => u.FirstName)
.IsRequired()
.HasMaxLength(100);
builder.Property(u => u.LastName)
.IsRequired()
.HasMaxLength(100);
builder.Property(u => u.PhoneNumber)
.HasMaxLength(20);
builder.Property(u => u.DateOfBirth)
.HasColumnType("date");
builder.Property(u => u.IsActive)
.IsRequired()
.HasDefaultValue(true);
builder.Property(u => u.LastLoginAt)
.HasColumnType("datetime2");
builder.HasIndex(u => u.Email)
.IsUnique()
.HasDatabaseName("IX_User_Email");
builder.HasIndex(u => u.IsActive)
.HasDatabaseName("IX_User_IsActive");
builder.HasMany(u => u.Addresses)
.WithOne()
.HasForeignKey(a => a.UserId)
.HasPrincipalKey(u => u.Id)
.OnDelete(DeleteBehavior.Cascade);
builder.HasMany(u => u.UserRoles)
.WithOne()
.HasForeignKey(ur => ur.UserId)
.HasPrincipalKey(u => u.Id)
.OnDelete(DeleteBehavior.Cascade);
builder.Ignore(u => u.FullName);
builder.Ignore(u => u.DefaultAddress);
builder.Ignore(u => u.Roles);
}
}