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

62 lines
2.0 KiB
C#
Raw Normal View History

using Heimdall.Domain.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace Heimdall.Infrastructure.Data.Configurations;
public class RecordingConfiguration : IEntityTypeConfiguration<Recording>
{
public void Configure(EntityTypeBuilder<Recording> builder)
{
builder.ToTable("recordings");
builder.HasKey(r => r.Id);
builder.Property(r => r.Timestamp)
.IsRequired();
builder.Property(r => r.DurationSeconds)
.HasDefaultValue(0.0);
builder.Property(r => r.StoragePath)
.HasMaxLength(2000)
.IsRequired()
.IsUnicode(false);
builder.Property(r => r.SizeBytes)
.IsRequired();
builder.Property(r => r.StorageProvider)
.HasConversion<string>()
.HasMaxLength(20)
.IsRequired()
.IsUnicode(false);
builder.Property(r => r.StorageRoot).HasMaxLength(2000);
builder.Property(r => r.StorageEndpoint).HasMaxLength(2000);
builder.Property(r => r.StorageBucket).HasMaxLength(256);
builder.Property(r => r.StorageLocationCaptured).HasDefaultValue(false).IsRequired();
builder.Property(r => r.CreatedAt)
.HasDefaultValueSql("NOW()");
builder.Property(r => r.UpdatedAt)
.HasDefaultValueSql("NOW()");
// Indexes (spec 2.3)
builder.HasIndex(r => new { r.CameraId, r.Timestamp }); // timeline per camera
builder.HasIndex(r => r.StoragePath).IsUnique(); // storage dedup
builder.HasIndex(r => r.StoragePolicyId);
// Relationships
builder.HasOne(r => r.Camera)
.WithMany()
.HasForeignKey(r => r.CameraId)
.OnDelete(DeleteBehavior.Cascade);
builder.HasOne(r => r.StoragePolicy)
.WithMany()
.HasForeignKey(r => r.StoragePolicyId)
.OnDelete(DeleteBehavior.SetNull);
}
}