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

35 lines
1.0 KiB
C#
Raw Normal View History

using Heimdall.Domain.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using System.Text.Json;
namespace Heimdall.Infrastructure.Data.Configurations;
public class KnownFaceConfiguration : IEntityTypeConfiguration<KnownFace>
{
private static readonly JsonSerializerOptions JsonOptions = new();
public void Configure(EntityTypeBuilder<KnownFace> builder)
{
builder.ToTable("known_faces");
builder.HasKey(f => f.Id);
builder.Property(f => f.ThumbnailUrl)
.HasMaxLength(2000)
.IsUnicode(false);
builder.Property(f => f.SourceEventId)
.HasMaxLength(100)
.IsUnicode(false);
// Store float[] as JSONB
builder.Property(f => f.Embedding)
.HasColumnType("jsonb")
.HasConversion(
v => JsonSerializer.Serialize(v, JsonOptions),
v => JsonSerializer.Deserialize<float[]>(v, JsonOptions) ?? Array.Empty<float>());
builder.HasIndex(f => f.PersonId);
}
}