Identity
This commit is contained in:
+34
@@ -0,0 +1,34 @@
|
||||
using System.Text.Json;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
using Nashel.Modules.Identity.Domain.Aggregates;
|
||||
using Nashel.Modules.Identity.Domain.Enums;
|
||||
|
||||
namespace Nashel.Modules.Identity.Infrastructure.Persistence.Configurations;
|
||||
|
||||
public class AccountConfiguration : IEntityTypeConfiguration<Account>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<Account> builder)
|
||||
{
|
||||
builder.ToTable("Accounts", "identity");
|
||||
|
||||
builder.HasKey(x => x.Id);
|
||||
|
||||
builder.Property(x => x.Phone)
|
||||
.IsRequired()
|
||||
.HasMaxLength(20);
|
||||
|
||||
builder.HasIndex(x => x.Phone)
|
||||
.IsUnique();
|
||||
|
||||
builder.Property(x => x.PasswordHash)
|
||||
.IsRequired();
|
||||
|
||||
// Хранение ролей как JSONB для простоты и совместимости с AOT (используя генерацию кода System.Text.Json при необходимости)
|
||||
builder.Property(x => x.Roles)
|
||||
.HasConversion(
|
||||
v => JsonSerializer.Serialize(v, (JsonSerializerOptions?)null),
|
||||
v => JsonSerializer.Deserialize<List<Role>>(v, (JsonSerializerOptions?)null) ?? new List<Role>())
|
||||
.HasColumnType("jsonb");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Nashel.Modules.Identity.Domain.Aggregates;
|
||||
using Nashel.Modules.Identity.Infrastructure.Persistence.Configurations;
|
||||
|
||||
namespace Nashel.Modules.Identity.Infrastructure.Persistence;
|
||||
|
||||
public class IdentityDbContext : DbContext
|
||||
{
|
||||
public IdentityDbContext(DbContextOptions<IdentityDbContext> options) : base(options)
|
||||
{
|
||||
}
|
||||
|
||||
public DbSet<Account> Accounts { get; set; }
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.ApplyConfiguration(new AccountConfiguration());
|
||||
base.OnModelCreating(modelBuilder);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user