Files
Heimdall/src/Heimdall.Infrastructure/Data/Configurations/ApiKeyConfiguration.cs
T

37 lines
1008 B
C#
Raw Normal View History

using Heimdall.Domain.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace Heimdall.Infrastructure.Data.Configurations;
public class ApiKeyConfiguration : IEntityTypeConfiguration<ApiKey>
{
public void Configure(EntityTypeBuilder<ApiKey> builder)
{
builder.ToTable("api_keys");
builder.HasKey(k => k.Id);
builder.Property(k => k.KeyHash)
.HasMaxLength(128)
.IsRequired();
builder.Property(k => k.KeyPrefix)
.HasMaxLength(8)
.IsRequired();
builder.Property(k => k.CreatedAt)
.HasDefaultValueSql("NOW()");
// Indexes
builder.HasIndex(k => k.KeyHash);
builder.HasIndex(k => k.KeyPrefix);
builder.HasIndex(k => k.SiteId);
// Relationships
builder.HasOne(k => k.Site)
.WithMany()
.HasForeignKey(k => k.SiteId)
.OnDelete(DeleteBehavior.Restrict);
}
}