34 lines
961 B
C#
34 lines
961 B
C#
using Heimdall.Domain.Entities;
|
|||
|
|
using Microsoft.EntityFrameworkCore;
|
||
|
|
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||
|
|
|
||
|
|
namespace Heimdall.Infrastructure.Data.Configurations;
|
||
|
|
|
||
|
|
public class UserRecoveryCodeConfiguration : IEntityTypeConfiguration<UserRecoveryCode>
|
||
|
|
{
|
||
|
|
public void Configure(EntityTypeBuilder<UserRecoveryCode> builder)
|
||
|
|
{
|
||
|
|
builder.ToTable("user_recovery_codes");
|
||
|
|
|
||
|
|
builder.HasKey(r => r.Id);
|
||
|
|
|
||
|
|
builder.Property(r => r.CodeHash)
|
||
|
|
.HasMaxLength(64)
|
||
|
|
.IsRequired()
|
||
|
|
.IsUnicode(false);
|
||
|
|
|
||
|
|
builder.Property(r => r.UserId)
|
||
|
|
.IsRequired();
|
||
|
|
|
||
|
|
builder.Property(r => r.CreatedAt)
|
||
|
|
.HasDefaultValueSql("NOW()");
|
||
|
|
|
||
|
|
builder.Property(r => r.UsedAt);
|
||
|
|
|
||
|
|
// Indexes for lookup during login (single-use redemption)
|
||
|
|
builder.HasIndex(r => new { r.UserId, r.CodeHash })
|
||
|
|
.IsUnique();
|
||
|
|
|
||
|
|
builder.HasIndex(r => r.UserId);
|
||
|
|
}
|
||
|
|
}
|