feat(domain): entités métier Vehicle/Recording/LicensePlate/StoragePolicy + relations Event→Vehicle/Recording, Camera→StoragePolicy (Fixes #6)
This commit is contained in:
1 parent
33a08f5ea0
commit
29ff980db5
19 files changed
+3658
No files matched your search
@@ -26,13 +26,17 @@ public interface IApplicationDbContext
|
||||
DbSet<UserNotificationConfig> UserNotificationConfigs { get; }
|
||||
DbSet<Group> Groups { get; }
|
||||
DbSet<KnownFace> KnownFaces { get; }
|
||||
DbSet<LicensePlate> LicensePlates { get; }
|
||||
DbSet<Person> Persons { get; }
|
||||
DbSet<Recording> Recordings { get; }
|
||||
DbSet<RevokedRefreshToken> RevokedRefreshTokens { get; }
|
||||
DbSet<Site> Sites { get; }
|
||||
DbSet<SiteCredential> SiteCredentials { get; }
|
||||
DbSet<StoragePolicy> StoragePolicies { get; }
|
||||
DbSet<UserGroup> UserGroups { get; }
|
||||
DbSet<UserRecoveryCode> UserRecoveryCodes { get; }
|
||||
DbSet<UserSite> UserSites { get; }
|
||||
DbSet<Vehicle> Vehicles { get; }
|
||||
Task<int> SaveChangesAsync(CancellationToken cancellationToken);
|
||||
Task SaveChangesWithRetryAsync(int maxRetries = 3, CancellationToken ct = default);
|
||||
}
|
||||
@@ -72,6 +72,12 @@ public class Camera : Entity<Guid>, IAuditableEntity, ISoftDeletable
|
||||
public CameraCredentials? Credentials { get; private set; }
|
||||
public CameraDetectionProfile? DetectionProfile { get; private set; }
|
||||
|
||||
/// <summary>Storage policy applied to this camera's recordings (N:1).</summary>
|
||||
public Guid? StoragePolicyId { get; private set; }
|
||||
public StoragePolicy? StoragePolicy { get; private set; }
|
||||
|
||||
public void AssignStoragePolicy(Guid storagePolicyId) => StoragePolicyId = storagePolicyId;
|
||||
|
||||
private Camera() { } // EF Core
|
||||
|
||||
public Camera(
|
||||
|
||||
@@ -19,12 +19,35 @@ public class CameraEvent : Entity<Guid>, IAuditableEntity
|
||||
public string? MetadataJson { get; private set; } // JSON: bounding boxes, track ID, etc.
|
||||
public DateTime OccurredAt { get; private set; }
|
||||
|
||||
// ── Relations métier (spec 2.1/2.2) ─────────────────────────────
|
||||
/// <summary>Vehicle linked to this event (Event → Vehicle N:1).</summary>
|
||||
public Guid? VehicleId { get; private set; }
|
||||
|
||||
/// <summary>Recording segment linked to this event (Event → Recording N:1).</summary>
|
||||
public Guid? RecordingId { get; private set; }
|
||||
|
||||
/// <summary>Parent event for event hierarchies (Event → Event N:1).</summary>
|
||||
public Guid? ParentEventId { get; private set; }
|
||||
|
||||
// ── Déduplication (spec 2.1) ────────────────────────────────────
|
||||
/// <summary>Stable hash of detection content used for deduplication.</summary>
|
||||
public string? DetectionHash { get; private set; }
|
||||
|
||||
/// <summary>True when the event was suppressed (duplicate / low value).</summary>
|
||||
public bool IsSuppressed { get; private set; }
|
||||
|
||||
/// <summary>Tracking identifier grouping frames of the same object.</summary>
|
||||
public string? TrackId { get; private set; }
|
||||
|
||||
// Audit
|
||||
public DateTime CreatedAt { get; set; }
|
||||
public DateTime UpdatedAt { get; set; }
|
||||
|
||||
// Navigation
|
||||
public Camera Camera { get; private set; } = null!;
|
||||
public Vehicle? Vehicle { get; private set; }
|
||||
public Recording? Recording { get; private set; }
|
||||
public CameraEvent? ParentEvent { get; private set; }
|
||||
|
||||
private CameraEvent() { } // EF Core
|
||||
|
||||
@@ -51,4 +74,11 @@ public class CameraEvent : Entity<Guid>, IAuditableEntity
|
||||
}
|
||||
|
||||
public void AssignAgent(Guid agentId) => AgentId = agentId;
|
||||
|
||||
public void AssignVehicle(Guid vehicleId) => VehicleId = vehicleId;
|
||||
public void AssignRecording(Guid recordingId) => RecordingId = recordingId;
|
||||
public void AssignParentEvent(Guid parentEventId) => ParentEventId = parentEventId;
|
||||
public void SetTrackId(string trackId) => TrackId = trackId;
|
||||
public void SetDetectionHash(string detectionHash) => DetectionHash = detectionHash;
|
||||
public void SetSuppressed(bool suppressed) => IsSuppressed = suppressed;
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
using Heimdall.Domain.Primitives;
|
||||
|
||||
namespace Heimdall.Domain.Entities;
|
||||
|
||||
/// <summary>
|
||||
/// A license plate observation (OCR result).
|
||||
/// Linked to a vehicle and optionally to a person (driver/owner).
|
||||
/// </summary>
|
||||
public class LicensePlate : Entity<Guid>, IAuditableEntity
|
||||
{
|
||||
public string PlateText { get; private set; } = string.Empty;
|
||||
public Guid? VehicleId { get; private set; }
|
||||
public Guid? PersonId { get; private set; }
|
||||
public double Confidence { get; private set; }
|
||||
public DateTime CreatedAt { get; set; }
|
||||
public DateTime UpdatedAt { get; set; }
|
||||
|
||||
// Navigation
|
||||
public Vehicle? Vehicle { get; private set; }
|
||||
public Person? Person { get; private set; }
|
||||
|
||||
private LicensePlate() { } // EF Core
|
||||
|
||||
public LicensePlate(string plateText, Guid? vehicleId = null, Guid? personId = null, double confidence = 0)
|
||||
: base(Guid.NewGuid())
|
||||
{
|
||||
PlateText = plateText;
|
||||
VehicleId = vehicleId;
|
||||
PersonId = personId;
|
||||
Confidence = confidence;
|
||||
}
|
||||
|
||||
public void AssignVehicle(Guid vehicleId) => VehicleId = vehicleId;
|
||||
public void AssignPerson(Guid personId) => PersonId = personId;
|
||||
public void UpdateConfidence(double confidence) => Confidence = confidence;
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
using Heimdall.Domain.Enums;
|
||||
using Heimdall.Domain.Primitives;
|
||||
|
||||
namespace Heimdall.Domain.Entities;
|
||||
|
||||
/// <summary>
|
||||
/// A recorded video segment from a camera, stored on a storage provider (S3 or local).
|
||||
/// Linked to a storage policy that defines retention.
|
||||
/// </summary>
|
||||
public class Recording : Entity<Guid>, IAuditableEntity
|
||||
{
|
||||
public Guid CameraId { get; private set; }
|
||||
public DateTime Timestamp { get; private set; }
|
||||
public double DurationSeconds { get; private set; }
|
||||
public string StoragePath { get; private set; } = string.Empty;
|
||||
public long SizeBytes { get; private set; }
|
||||
public StorageProvider StorageProvider { get; private set; } = StorageProvider.S3;
|
||||
public Guid? StoragePolicyId { get; private set; }
|
||||
public DateTime CreatedAt { get; set; }
|
||||
public DateTime UpdatedAt { get; set; }
|
||||
|
||||
// Navigation
|
||||
public Camera Camera { get; private set; } = null!;
|
||||
public StoragePolicy? StoragePolicy { get; private set; }
|
||||
|
||||
private Recording() { } // EF Core
|
||||
|
||||
public Recording(
|
||||
Guid cameraId,
|
||||
DateTime timestamp,
|
||||
double durationSeconds,
|
||||
string storagePath,
|
||||
long sizeBytes,
|
||||
StorageProvider storageProvider,
|
||||
Guid? storagePolicyId = null)
|
||||
: base(Guid.NewGuid())
|
||||
{
|
||||
CameraId = cameraId;
|
||||
Timestamp = timestamp;
|
||||
DurationSeconds = durationSeconds;
|
||||
StoragePath = storagePath;
|
||||
SizeBytes = sizeBytes;
|
||||
StorageProvider = storageProvider;
|
||||
StoragePolicyId = storagePolicyId;
|
||||
}
|
||||
|
||||
public void AssignStoragePolicy(Guid storagePolicyId) => StoragePolicyId = storagePolicyId;
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
using Heimdall.Domain.Enums;
|
||||
using Heimdall.Domain.Primitives;
|
||||
|
||||
namespace Heimdall.Domain.Entities;
|
||||
|
||||
/// <summary>
|
||||
/// Retention and storage policy for camera recordings.
|
||||
/// Multiple cameras can share the same policy (N:1).
|
||||
/// </summary>
|
||||
public class StoragePolicy : Entity<Guid>, IAuditableEntity
|
||||
{
|
||||
public string Name { get; private set; } = string.Empty;
|
||||
public int RetentionDays { get; private set; } = 30;
|
||||
public StorageProvider StorageProvider { get; private set; } = StorageProvider.S3;
|
||||
public DateTime CreatedAt { get; set; }
|
||||
public DateTime UpdatedAt { get; set; }
|
||||
|
||||
private StoragePolicy() { } // EF Core
|
||||
|
||||
public StoragePolicy(string name, int retentionDays, StorageProvider storageProvider)
|
||||
: base(Guid.NewGuid())
|
||||
{
|
||||
Name = name;
|
||||
RetentionDays = retentionDays;
|
||||
StorageProvider = storageProvider;
|
||||
}
|
||||
|
||||
public void Update(string name, int retentionDays, StorageProvider storageProvider)
|
||||
{
|
||||
Name = name;
|
||||
RetentionDays = retentionDays;
|
||||
StorageProvider = storageProvider;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
using Heimdall.Domain.Primitives;
|
||||
|
||||
namespace Heimdall.Domain.Entities;
|
||||
|
||||
/// <summary>
|
||||
/// A vehicle of interest detected by the system.
|
||||
/// Linked to a person (owner) and to license plate detections.
|
||||
/// </summary>
|
||||
public class Vehicle : Entity<Guid>, IAuditableEntity
|
||||
{
|
||||
public string? LicensePlate { get; private set; }
|
||||
public Guid? PersonId { get; private set; }
|
||||
public string? Make { get; private set; }
|
||||
public string? Model { get; private set; }
|
||||
public string? Color { get; private set; }
|
||||
public DateTime CreatedAt { get; set; }
|
||||
public DateTime UpdatedAt { get; set; }
|
||||
|
||||
// Navigation
|
||||
public Person? Person { get; private set; }
|
||||
|
||||
private Vehicle() { } // EF Core
|
||||
|
||||
public Vehicle(string? licensePlate, Guid? personId = null, string? make = null, string? model = null, string? color = null)
|
||||
: base(Guid.NewGuid())
|
||||
{
|
||||
LicensePlate = licensePlate;
|
||||
PersonId = personId;
|
||||
Make = make;
|
||||
Model = model;
|
||||
Color = color;
|
||||
}
|
||||
|
||||
public void Update(string? licensePlate, string? make, string? model, string? color)
|
||||
{
|
||||
LicensePlate = licensePlate;
|
||||
Make = make;
|
||||
Model = model;
|
||||
Color = color;
|
||||
}
|
||||
|
||||
public void AssignPerson(Guid personId) => PersonId = personId;
|
||||
}
|
||||
@@ -60,6 +60,12 @@ public class AppDbContext : IdentityDbContext<AppUser, AppRole, Guid>, IApplicat
|
||||
// 2FA recovery codes (stored hashed)
|
||||
public DbSet<UserRecoveryCode> UserRecoveryCodes => Set<UserRecoveryCode>();
|
||||
|
||||
// Domain métier (spec 2.1)
|
||||
public DbSet<Vehicle> Vehicles => Set<Vehicle>();
|
||||
public DbSet<Recording> Recordings => Set<Recording>();
|
||||
public DbSet<LicensePlate> LicensePlates => Set<LicensePlate>();
|
||||
public DbSet<StoragePolicy> StoragePolicies => Set<StoragePolicy>();
|
||||
|
||||
public async Task SaveChangesWithRetryAsync(int maxRetries = 3, CancellationToken ct = default)
|
||||
{
|
||||
await DbContextExtensions.SaveChangesWithRetryAsync(this, maxRetries, ct).ConfigureAwait(false);
|
||||
|
||||
@@ -117,5 +117,13 @@ public class CameraConfiguration : IEntityTypeConfiguration<Camera>
|
||||
.WithOne(dp => dp.Camera)
|
||||
.HasForeignKey<CameraDetectionProfile>(dp => dp.CameraId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
// Storage policy (N:1 — plusieurs caméras partagent une politique)
|
||||
builder.HasOne(c => c.StoragePolicy)
|
||||
.WithMany()
|
||||
.HasForeignKey(c => c.StoragePolicyId)
|
||||
.OnDelete(DeleteBehavior.SetNull);
|
||||
|
||||
builder.HasIndex(c => c.StoragePolicyId);
|
||||
}
|
||||
}
|
||||
@@ -37,6 +37,17 @@ public class CameraEventConfiguration : IEntityTypeConfiguration<CameraEvent>
|
||||
builder.Property(e => e.OccurredAt)
|
||||
.IsRequired();
|
||||
|
||||
builder.Property(e => e.DetectionHash)
|
||||
.HasMaxLength(128)
|
||||
.IsUnicode(false);
|
||||
|
||||
builder.Property(e => e.TrackId)
|
||||
.HasMaxLength(100)
|
||||
.IsUnicode(false);
|
||||
|
||||
builder.Property(e => e.IsSuppressed)
|
||||
.HasDefaultValue(false);
|
||||
|
||||
builder.Property(e => e.CreatedAt)
|
||||
.HasDefaultValueSql("NOW()");
|
||||
|
||||
@@ -51,10 +62,32 @@ public class CameraEventConfiguration : IEntityTypeConfiguration<CameraEvent>
|
||||
|
||||
builder.HasIndex(e => e.OccurredAt);
|
||||
|
||||
// Indexes déduplication / relations (spec 2.3)
|
||||
builder.HasIndex(e => e.TrackId);
|
||||
builder.HasIndex(e => e.DetectionHash);
|
||||
builder.HasIndex(e => e.ParentEventId);
|
||||
builder.HasIndex(e => e.VehicleId);
|
||||
builder.HasIndex(e => e.RecordingId);
|
||||
|
||||
// Relationships
|
||||
builder.HasOne(e => e.Camera)
|
||||
.WithMany()
|
||||
.HasForeignKey(e => e.CameraId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
builder.HasOne(e => e.Vehicle)
|
||||
.WithMany()
|
||||
.HasForeignKey(e => e.VehicleId)
|
||||
.OnDelete(DeleteBehavior.SetNull);
|
||||
|
||||
builder.HasOne(e => e.Recording)
|
||||
.WithMany()
|
||||
.HasForeignKey(e => e.RecordingId)
|
||||
.OnDelete(DeleteBehavior.SetNull);
|
||||
|
||||
builder.HasOne(e => e.ParentEvent)
|
||||
.WithMany()
|
||||
.HasForeignKey(e => e.ParentEventId)
|
||||
.OnDelete(DeleteBehavior.SetNull);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
using Heimdall.Domain.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace Heimdall.Infrastructure.Data.Configurations;
|
||||
|
||||
public class LicensePlateConfiguration : IEntityTypeConfiguration<LicensePlate>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<LicensePlate> builder)
|
||||
{
|
||||
builder.ToTable("license_plates");
|
||||
|
||||
builder.HasKey(p => p.Id);
|
||||
|
||||
builder.Property(p => p.PlateText)
|
||||
.HasMaxLength(20)
|
||||
.IsRequired()
|
||||
.IsUnicode(false);
|
||||
|
||||
builder.Property(p => p.Confidence)
|
||||
.HasDefaultValue(0.0);
|
||||
|
||||
builder.Property(p => p.CreatedAt)
|
||||
.HasDefaultValueSql("NOW()");
|
||||
|
||||
builder.Property(p => p.UpdatedAt)
|
||||
.HasDefaultValueSql("NOW()");
|
||||
|
||||
// Indexes (spec 2.3) — GIN trigram pour recherche floue de plaque
|
||||
builder.HasIndex(p => p.PlateText)
|
||||
.HasMethod("gin")
|
||||
.HasOperators("gin_trgm_ops");
|
||||
|
||||
builder.HasIndex(p => p.VehicleId);
|
||||
builder.HasIndex(p => p.PersonId);
|
||||
|
||||
// Relationships
|
||||
builder.HasOne(p => p.Vehicle)
|
||||
.WithMany()
|
||||
.HasForeignKey(p => p.VehicleId)
|
||||
.OnDelete(DeleteBehavior.SetNull);
|
||||
|
||||
builder.HasOne(p => p.Person)
|
||||
.WithMany()
|
||||
.HasForeignKey(p => p.PersonId)
|
||||
.OnDelete(DeleteBehavior.SetNull);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
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.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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
using Heimdall.Domain.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace Heimdall.Infrastructure.Data.Configurations;
|
||||
|
||||
public class StoragePolicyConfiguration : IEntityTypeConfiguration<StoragePolicy>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<StoragePolicy> builder)
|
||||
{
|
||||
builder.ToTable("storage_policies");
|
||||
|
||||
builder.HasKey(p => p.Id);
|
||||
|
||||
builder.Property(p => p.Name)
|
||||
.HasMaxLength(100)
|
||||
.IsRequired()
|
||||
.IsUnicode(false);
|
||||
|
||||
builder.Property(p => p.RetentionDays)
|
||||
.IsRequired();
|
||||
|
||||
builder.Property(p => p.StorageProvider)
|
||||
.HasConversion<string>()
|
||||
.HasMaxLength(20)
|
||||
.IsRequired()
|
||||
.IsUnicode(false);
|
||||
|
||||
builder.Property(p => p.CreatedAt)
|
||||
.HasDefaultValueSql("NOW()");
|
||||
|
||||
builder.Property(p => p.UpdatedAt)
|
||||
.HasDefaultValueSql("NOW()");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
using Heimdall.Domain.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace Heimdall.Infrastructure.Data.Configurations;
|
||||
|
||||
public class VehicleConfiguration : IEntityTypeConfiguration<Vehicle>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<Vehicle> builder)
|
||||
{
|
||||
builder.ToTable("vehicles");
|
||||
|
||||
builder.HasKey(v => v.Id);
|
||||
|
||||
builder.Property(v => v.LicensePlate)
|
||||
.HasMaxLength(20)
|
||||
.IsUnicode(false);
|
||||
|
||||
builder.Property(v => v.Make)
|
||||
.HasMaxLength(100)
|
||||
.IsUnicode(false);
|
||||
|
||||
builder.Property(v => v.Model)
|
||||
.HasMaxLength(100)
|
||||
.IsUnicode(false);
|
||||
|
||||
builder.Property(v => v.Color)
|
||||
.HasMaxLength(50)
|
||||
.IsUnicode(false);
|
||||
|
||||
builder.Property(v => v.CreatedAt)
|
||||
.HasDefaultValueSql("NOW()");
|
||||
|
||||
builder.Property(v => v.UpdatedAt)
|
||||
.HasDefaultValueSql("NOW()");
|
||||
|
||||
// Indexes
|
||||
builder.HasIndex(v => v.LicensePlate);
|
||||
builder.HasIndex(v => v.PersonId);
|
||||
|
||||
// Relationships
|
||||
builder.HasOne(v => v.Person)
|
||||
.WithMany()
|
||||
.HasForeignKey(v => v.PersonId)
|
||||
.OnDelete(DeleteBehavior.SetNull);
|
||||
}
|
||||
}
|
||||
+2214
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,355 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Heimdall.Infrastructure.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AddBusinessEntities : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
// Extension trigram requise pour l'index GIN sur license_plates(plate_text)
|
||||
migrationBuilder.Sql("CREATE EXTENSION IF NOT EXISTS pg_trgm;");
|
||||
|
||||
migrationBuilder.AddColumn<Guid>(
|
||||
name: "StoragePolicyId",
|
||||
table: "cameras",
|
||||
type: "uuid",
|
||||
nullable: true);
|
||||
|
||||
migrationBuilder.AddColumn<string>(
|
||||
name: "DetectionHash",
|
||||
table: "camera_events",
|
||||
type: "character varying(128)",
|
||||
unicode: false,
|
||||
maxLength: 128,
|
||||
nullable: true);
|
||||
|
||||
migrationBuilder.AddColumn<bool>(
|
||||
name: "IsSuppressed",
|
||||
table: "camera_events",
|
||||
type: "boolean",
|
||||
nullable: false,
|
||||
defaultValue: false);
|
||||
|
||||
migrationBuilder.AddColumn<Guid>(
|
||||
name: "ParentEventId",
|
||||
table: "camera_events",
|
||||
type: "uuid",
|
||||
nullable: true);
|
||||
|
||||
migrationBuilder.AddColumn<Guid>(
|
||||
name: "RecordingId",
|
||||
table: "camera_events",
|
||||
type: "uuid",
|
||||
nullable: true);
|
||||
|
||||
migrationBuilder.AddColumn<string>(
|
||||
name: "TrackId",
|
||||
table: "camera_events",
|
||||
type: "character varying(100)",
|
||||
unicode: false,
|
||||
maxLength: 100,
|
||||
nullable: true);
|
||||
|
||||
migrationBuilder.AddColumn<Guid>(
|
||||
name: "VehicleId",
|
||||
table: "camera_events",
|
||||
type: "uuid",
|
||||
nullable: true);
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "storage_policies",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
Name = table.Column<string>(type: "character varying(100)", unicode: false, maxLength: 100, nullable: false),
|
||||
RetentionDays = table.Column<int>(type: "integer", nullable: false),
|
||||
StorageProvider = table.Column<string>(type: "character varying(20)", unicode: false, maxLength: 20, nullable: false),
|
||||
CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false, defaultValueSql: "NOW()"),
|
||||
UpdatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false, defaultValueSql: "NOW()")
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_storage_policies", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "vehicles",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
LicensePlate = table.Column<string>(type: "character varying(20)", unicode: false, maxLength: 20, nullable: true),
|
||||
PersonId = table.Column<Guid>(type: "uuid", nullable: true),
|
||||
Make = table.Column<string>(type: "character varying(100)", unicode: false, maxLength: 100, nullable: true),
|
||||
Model = table.Column<string>(type: "character varying(100)", unicode: false, maxLength: 100, nullable: true),
|
||||
Color = table.Column<string>(type: "character varying(50)", unicode: false, maxLength: 50, nullable: true),
|
||||
CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false, defaultValueSql: "NOW()"),
|
||||
UpdatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false, defaultValueSql: "NOW()")
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_vehicles", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_vehicles_persons_PersonId",
|
||||
column: x => x.PersonId,
|
||||
principalTable: "persons",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.SetNull);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "recordings",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
CameraId = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
Timestamp = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
||||
DurationSeconds = table.Column<double>(type: "double precision", nullable: false, defaultValue: 0.0),
|
||||
StoragePath = table.Column<string>(type: "character varying(2000)", unicode: false, maxLength: 2000, nullable: false),
|
||||
SizeBytes = table.Column<long>(type: "bigint", nullable: false),
|
||||
StorageProvider = table.Column<string>(type: "character varying(20)", unicode: false, maxLength: 20, nullable: false),
|
||||
StoragePolicyId = table.Column<Guid>(type: "uuid", nullable: true),
|
||||
CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false, defaultValueSql: "NOW()"),
|
||||
UpdatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false, defaultValueSql: "NOW()")
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_recordings", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_recordings_cameras_CameraId",
|
||||
column: x => x.CameraId,
|
||||
principalTable: "cameras",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_recordings_storage_policies_StoragePolicyId",
|
||||
column: x => x.StoragePolicyId,
|
||||
principalTable: "storage_policies",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.SetNull);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "license_plates",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
PlateText = table.Column<string>(type: "character varying(20)", unicode: false, maxLength: 20, nullable: false),
|
||||
VehicleId = table.Column<Guid>(type: "uuid", nullable: true),
|
||||
PersonId = table.Column<Guid>(type: "uuid", nullable: true),
|
||||
Confidence = table.Column<double>(type: "double precision", nullable: false, defaultValue: 0.0),
|
||||
CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false, defaultValueSql: "NOW()"),
|
||||
UpdatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false, defaultValueSql: "NOW()")
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_license_plates", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_license_plates_persons_PersonId",
|
||||
column: x => x.PersonId,
|
||||
principalTable: "persons",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.SetNull);
|
||||
table.ForeignKey(
|
||||
name: "FK_license_plates_vehicles_VehicleId",
|
||||
column: x => x.VehicleId,
|
||||
principalTable: "vehicles",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.SetNull);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_cameras_StoragePolicyId",
|
||||
table: "cameras",
|
||||
column: "StoragePolicyId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_camera_events_DetectionHash",
|
||||
table: "camera_events",
|
||||
column: "DetectionHash");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_camera_events_ParentEventId",
|
||||
table: "camera_events",
|
||||
column: "ParentEventId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_camera_events_RecordingId",
|
||||
table: "camera_events",
|
||||
column: "RecordingId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_camera_events_TrackId",
|
||||
table: "camera_events",
|
||||
column: "TrackId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_camera_events_VehicleId",
|
||||
table: "camera_events",
|
||||
column: "VehicleId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_license_plates_PersonId",
|
||||
table: "license_plates",
|
||||
column: "PersonId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_license_plates_PlateText",
|
||||
table: "license_plates",
|
||||
column: "PlateText")
|
||||
.Annotation("Npgsql:IndexMethod", "gin")
|
||||
.Annotation("Npgsql:IndexOperators", new[] { "gin_trgm_ops" });
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_license_plates_VehicleId",
|
||||
table: "license_plates",
|
||||
column: "VehicleId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_recordings_CameraId_Timestamp",
|
||||
table: "recordings",
|
||||
columns: new[] { "CameraId", "Timestamp" });
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_recordings_StoragePath",
|
||||
table: "recordings",
|
||||
column: "StoragePath",
|
||||
unique: true);
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_recordings_StoragePolicyId",
|
||||
table: "recordings",
|
||||
column: "StoragePolicyId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_vehicles_LicensePlate",
|
||||
table: "vehicles",
|
||||
column: "LicensePlate");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_vehicles_PersonId",
|
||||
table: "vehicles",
|
||||
column: "PersonId");
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_camera_events_camera_events_ParentEventId",
|
||||
table: "camera_events",
|
||||
column: "ParentEventId",
|
||||
principalTable: "camera_events",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.SetNull);
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_camera_events_recordings_RecordingId",
|
||||
table: "camera_events",
|
||||
column: "RecordingId",
|
||||
principalTable: "recordings",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.SetNull);
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_camera_events_vehicles_VehicleId",
|
||||
table: "camera_events",
|
||||
column: "VehicleId",
|
||||
principalTable: "vehicles",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.SetNull);
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_cameras_storage_policies_StoragePolicyId",
|
||||
table: "cameras",
|
||||
column: "StoragePolicyId",
|
||||
principalTable: "storage_policies",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.SetNull);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_camera_events_camera_events_ParentEventId",
|
||||
table: "camera_events");
|
||||
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_camera_events_recordings_RecordingId",
|
||||
table: "camera_events");
|
||||
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_camera_events_vehicles_VehicleId",
|
||||
table: "camera_events");
|
||||
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_cameras_storage_policies_StoragePolicyId",
|
||||
table: "cameras");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "license_plates");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "recordings");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "vehicles");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "storage_policies");
|
||||
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_cameras_StoragePolicyId",
|
||||
table: "cameras");
|
||||
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_camera_events_DetectionHash",
|
||||
table: "camera_events");
|
||||
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_camera_events_ParentEventId",
|
||||
table: "camera_events");
|
||||
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_camera_events_RecordingId",
|
||||
table: "camera_events");
|
||||
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_camera_events_TrackId",
|
||||
table: "camera_events");
|
||||
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_camera_events_VehicleId",
|
||||
table: "camera_events");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "StoragePolicyId",
|
||||
table: "cameras");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "DetectionHash",
|
||||
table: "camera_events");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "IsSuppressed",
|
||||
table: "camera_events");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "ParentEventId",
|
||||
table: "camera_events");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "RecordingId",
|
||||
table: "camera_events");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "TrackId",
|
||||
table: "camera_events");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "VehicleId",
|
||||
table: "camera_events");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -598,6 +598,9 @@ namespace Heimdall.Infrastructure.Migrations
|
||||
.IsUnicode(false)
|
||||
.HasColumnType("character varying(20)");
|
||||
|
||||
b.Property<Guid?>("StoragePolicyId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<string>("SubRtspUrl")
|
||||
.HasMaxLength(1000)
|
||||
.IsUnicode(false)
|
||||
@@ -618,6 +621,8 @@ namespace Heimdall.Infrastructure.Migrations
|
||||
|
||||
b.HasIndex("SiteId");
|
||||
|
||||
b.HasIndex("StoragePolicyId");
|
||||
|
||||
b.ToTable("cameras", (string)null);
|
||||
});
|
||||
|
||||
@@ -917,6 +922,16 @@ namespace Heimdall.Infrastructure.Migrations
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasDefaultValueSql("NOW()");
|
||||
|
||||
b.Property<string>("DetectionHash")
|
||||
.HasMaxLength(128)
|
||||
.IsUnicode(false)
|
||||
.HasColumnType("character varying(128)");
|
||||
|
||||
b.Property<bool>("IsSuppressed")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("boolean")
|
||||
.HasDefaultValue(false);
|
||||
|
||||
b.Property<string>("Label")
|
||||
.HasMaxLength(200)
|
||||
.IsUnicode(false)
|
||||
@@ -928,6 +943,12 @@ namespace Heimdall.Infrastructure.Migrations
|
||||
b.Property<DateTime>("OccurredAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<Guid?>("ParentEventId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<Guid?>("RecordingId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<string>("SnapshotThumbUrl")
|
||||
.HasMaxLength(2000)
|
||||
.IsUnicode(false)
|
||||
@@ -938,6 +959,11 @@ namespace Heimdall.Infrastructure.Migrations
|
||||
.IsUnicode(false)
|
||||
.HasColumnType("character varying(2000)");
|
||||
|
||||
b.Property<string>("TrackId")
|
||||
.HasMaxLength(100)
|
||||
.IsUnicode(false)
|
||||
.HasColumnType("character varying(100)");
|
||||
|
||||
b.Property<int>("Type")
|
||||
.HasColumnType("integer");
|
||||
|
||||
@@ -946,10 +972,23 @@ namespace Heimdall.Infrastructure.Migrations
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasDefaultValueSql("NOW()");
|
||||
|
||||
b.Property<Guid?>("VehicleId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("DetectionHash");
|
||||
|
||||
b.HasIndex("OccurredAt");
|
||||
|
||||
b.HasIndex("ParentEventId");
|
||||
|
||||
b.HasIndex("RecordingId");
|
||||
|
||||
b.HasIndex("TrackId");
|
||||
|
||||
b.HasIndex("VehicleId");
|
||||
|
||||
b.HasIndex("CameraId", "OccurredAt")
|
||||
.IsDescending(false, true);
|
||||
|
||||
@@ -1081,6 +1120,53 @@ namespace Heimdall.Infrastructure.Migrations
|
||||
b.ToTable("known_faces", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Heimdall.Domain.Entities.LicensePlate", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<double>("Confidence")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("double precision")
|
||||
.HasDefaultValue(0.0);
|
||||
|
||||
b.Property<DateTime>("CreatedAt")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasDefaultValueSql("NOW()");
|
||||
|
||||
b.Property<Guid?>("PersonId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<string>("PlateText")
|
||||
.IsRequired()
|
||||
.HasMaxLength(20)
|
||||
.IsUnicode(false)
|
||||
.HasColumnType("character varying(20)");
|
||||
|
||||
b.Property<DateTime>("UpdatedAt")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasDefaultValueSql("NOW()");
|
||||
|
||||
b.Property<Guid?>("VehicleId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("PersonId");
|
||||
|
||||
b.HasIndex("PlateText");
|
||||
|
||||
NpgsqlIndexBuilderExtensions.HasMethod(b.HasIndex("PlateText"), "gin");
|
||||
NpgsqlIndexBuilderExtensions.HasOperators(b.HasIndex("PlateText"), new[] { "gin_trgm_ops" });
|
||||
|
||||
b.HasIndex("VehicleId");
|
||||
|
||||
b.ToTable("license_plates", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Heimdall.Domain.Entities.Notification", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
@@ -1248,6 +1334,63 @@ namespace Heimdall.Infrastructure.Migrations
|
||||
b.ToTable("persons", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Heimdall.Domain.Entities.Recording", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<Guid>("CameraId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<DateTime>("CreatedAt")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasDefaultValueSql("NOW()");
|
||||
|
||||
b.Property<double>("DurationSeconds")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("double precision")
|
||||
.HasDefaultValue(0.0);
|
||||
|
||||
b.Property<long>("SizeBytes")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<string>("StoragePath")
|
||||
.IsRequired()
|
||||
.HasMaxLength(2000)
|
||||
.IsUnicode(false)
|
||||
.HasColumnType("character varying(2000)");
|
||||
|
||||
b.Property<Guid?>("StoragePolicyId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<string>("StorageProvider")
|
||||
.IsRequired()
|
||||
.HasMaxLength(20)
|
||||
.IsUnicode(false)
|
||||
.HasColumnType("character varying(20)");
|
||||
|
||||
b.Property<DateTime>("Timestamp")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<DateTime>("UpdatedAt")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasDefaultValueSql("NOW()");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("StoragePath")
|
||||
.IsUnique();
|
||||
|
||||
b.HasIndex("StoragePolicyId");
|
||||
|
||||
b.HasIndex("CameraId", "Timestamp");
|
||||
|
||||
b.ToTable("recordings", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Heimdall.Domain.Entities.RevokedRefreshToken", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
@@ -1383,6 +1526,42 @@ namespace Heimdall.Infrastructure.Migrations
|
||||
b.ToTable("site_credentials", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Heimdall.Domain.Entities.StoragePolicy", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<DateTime>("CreatedAt")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasDefaultValueSql("NOW()");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasMaxLength(100)
|
||||
.IsUnicode(false)
|
||||
.HasColumnType("character varying(100)");
|
||||
|
||||
b.Property<int>("RetentionDays")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("StorageProvider")
|
||||
.IsRequired()
|
||||
.HasMaxLength(20)
|
||||
.IsUnicode(false)
|
||||
.HasColumnType("character varying(20)");
|
||||
|
||||
b.Property<DateTime>("UpdatedAt")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasDefaultValueSql("NOW()");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("storage_policies", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Heimdall.Domain.Entities.UserGroup", b =>
|
||||
{
|
||||
b.Property<Guid>("UserId")
|
||||
@@ -1504,6 +1683,54 @@ namespace Heimdall.Infrastructure.Migrations
|
||||
b.ToTable("user_sites", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Heimdall.Domain.Entities.Vehicle", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<string>("Color")
|
||||
.HasMaxLength(50)
|
||||
.IsUnicode(false)
|
||||
.HasColumnType("character varying(50)");
|
||||
|
||||
b.Property<DateTime>("CreatedAt")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasDefaultValueSql("NOW()");
|
||||
|
||||
b.Property<string>("LicensePlate")
|
||||
.HasMaxLength(20)
|
||||
.IsUnicode(false)
|
||||
.HasColumnType("character varying(20)");
|
||||
|
||||
b.Property<string>("Make")
|
||||
.HasMaxLength(100)
|
||||
.IsUnicode(false)
|
||||
.HasColumnType("character varying(100)");
|
||||
|
||||
b.Property<string>("Model")
|
||||
.HasMaxLength(100)
|
||||
.IsUnicode(false)
|
||||
.HasColumnType("character varying(100)");
|
||||
|
||||
b.Property<Guid?>("PersonId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<DateTime>("UpdatedAt")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasDefaultValueSql("NOW()");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("LicensePlate");
|
||||
|
||||
b.HasIndex("PersonId");
|
||||
|
||||
b.ToTable("vehicles", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<System.Guid>", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
@@ -1673,9 +1900,16 @@ namespace Heimdall.Infrastructure.Migrations
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("Heimdall.Domain.Entities.StoragePolicy", "StoragePolicy")
|
||||
.WithMany()
|
||||
.HasForeignKey("StoragePolicyId")
|
||||
.OnDelete(DeleteBehavior.SetNull);
|
||||
|
||||
b.Navigation("Agent");
|
||||
|
||||
b.Navigation("Site");
|
||||
|
||||
b.Navigation("StoragePolicy");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Heimdall.Domain.Entities.CameraAssignment", b =>
|
||||
@@ -1738,7 +1972,28 @@ namespace Heimdall.Infrastructure.Migrations
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("Heimdall.Domain.Entities.CameraEvent", "ParentEvent")
|
||||
.WithMany()
|
||||
.HasForeignKey("ParentEventId")
|
||||
.OnDelete(DeleteBehavior.SetNull);
|
||||
|
||||
b.HasOne("Heimdall.Domain.Entities.Recording", "Recording")
|
||||
.WithMany()
|
||||
.HasForeignKey("RecordingId")
|
||||
.OnDelete(DeleteBehavior.SetNull);
|
||||
|
||||
b.HasOne("Heimdall.Domain.Entities.Vehicle", "Vehicle")
|
||||
.WithMany()
|
||||
.HasForeignKey("VehicleId")
|
||||
.OnDelete(DeleteBehavior.SetNull);
|
||||
|
||||
b.Navigation("Camera");
|
||||
|
||||
b.Navigation("ParentEvent");
|
||||
|
||||
b.Navigation("Recording");
|
||||
|
||||
b.Navigation("Vehicle");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Heimdall.Domain.Entities.DiscoveredStreamUrl", b =>
|
||||
@@ -1763,6 +2018,41 @@ namespace Heimdall.Infrastructure.Migrations
|
||||
b.Navigation("Person");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Heimdall.Domain.Entities.LicensePlate", b =>
|
||||
{
|
||||
b.HasOne("Heimdall.Domain.Entities.Person", "Person")
|
||||
.WithMany()
|
||||
.HasForeignKey("PersonId")
|
||||
.OnDelete(DeleteBehavior.SetNull);
|
||||
|
||||
b.HasOne("Heimdall.Domain.Entities.Vehicle", "Vehicle")
|
||||
.WithMany()
|
||||
.HasForeignKey("VehicleId")
|
||||
.OnDelete(DeleteBehavior.SetNull);
|
||||
|
||||
b.Navigation("Person");
|
||||
|
||||
b.Navigation("Vehicle");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Heimdall.Domain.Entities.Recording", b =>
|
||||
{
|
||||
b.HasOne("Heimdall.Domain.Entities.Camera", "Camera")
|
||||
.WithMany()
|
||||
.HasForeignKey("CameraId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("Heimdall.Domain.Entities.StoragePolicy", "StoragePolicy")
|
||||
.WithMany()
|
||||
.HasForeignKey("StoragePolicyId")
|
||||
.OnDelete(DeleteBehavior.SetNull);
|
||||
|
||||
b.Navigation("Camera");
|
||||
|
||||
b.Navigation("StoragePolicy");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Heimdall.Domain.Entities.SiteCredential", b =>
|
||||
{
|
||||
b.HasOne("Heimdall.Domain.Entities.Site", "Site")
|
||||
@@ -1812,6 +2102,16 @@ namespace Heimdall.Infrastructure.Migrations
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Heimdall.Domain.Entities.Vehicle", b =>
|
||||
{
|
||||
b.HasOne("Heimdall.Domain.Entities.Person", "Person")
|
||||
.WithMany()
|
||||
.HasForeignKey("PersonId")
|
||||
.OnDelete(DeleteBehavior.SetNull);
|
||||
|
||||
b.Navigation("Person");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<System.Guid>", b =>
|
||||
{
|
||||
b.HasOne("Heimdall.Domain.Entities.AppRole", null)
|
||||
|
||||
@@ -0,0 +1,158 @@
|
||||
using Heimdall.Domain.Entities;
|
||||
using Heimdall.Domain.Enums;
|
||||
using Shouldly;
|
||||
|
||||
namespace Heimdall.Domain.Tests.Entities;
|
||||
|
||||
public class BusinessEntityTests
|
||||
{
|
||||
// ─── StoragePolicy ─────────────────────────────────────────────
|
||||
|
||||
[Fact]
|
||||
public void StoragePolicy_create_should_set_properties()
|
||||
{
|
||||
var policy = new StoragePolicy("30 jours", 30, StorageProvider.S3);
|
||||
|
||||
policy.Name.ShouldBe("30 jours");
|
||||
policy.RetentionDays.ShouldBe(30);
|
||||
policy.StorageProvider.ShouldBe(StorageProvider.S3);
|
||||
policy.Id.ShouldNotBe(Guid.Empty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void StoragePolicy_update_should_change_values()
|
||||
{
|
||||
var policy = new StoragePolicy("30 jours", 30, StorageProvider.S3);
|
||||
|
||||
policy.Update("90 jours", 90, StorageProvider.Local);
|
||||
|
||||
policy.Name.ShouldBe("90 jours");
|
||||
policy.RetentionDays.ShouldBe(90);
|
||||
policy.StorageProvider.ShouldBe(StorageProvider.Local);
|
||||
}
|
||||
|
||||
// ─── Vehicle ───────────────────────────────────────────────────
|
||||
|
||||
[Fact]
|
||||
public void Vehicle_create_should_set_properties()
|
||||
{
|
||||
var vehicle = new Vehicle("AB-123-CD", null, "Renault", "Clio", "Noir");
|
||||
|
||||
vehicle.LicensePlate.ShouldBe("AB-123-CD");
|
||||
vehicle.Make.ShouldBe("Renault");
|
||||
vehicle.Model.ShouldBe("Clio");
|
||||
vehicle.Color.ShouldBe("Noir");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Vehicle_assign_person_should_set_relation()
|
||||
{
|
||||
var vehicle = new Vehicle("AB-123-CD");
|
||||
var personId = Guid.NewGuid();
|
||||
|
||||
vehicle.AssignPerson(personId);
|
||||
|
||||
vehicle.PersonId.ShouldBe(personId);
|
||||
}
|
||||
|
||||
// ─── Recording ─────────────────────────────────────────────────
|
||||
|
||||
[Fact]
|
||||
public void Recording_create_should_set_properties()
|
||||
{
|
||||
var cameraId = Guid.NewGuid();
|
||||
var policyId = Guid.NewGuid();
|
||||
var ts = new DateTime(2026, 7, 1, 12, 0, 0, DateTimeKind.Utc);
|
||||
var recording = new Recording(cameraId, ts, 60.0, "recordings/2026/07/01/12/cam1.mp4", 10_000_000, StorageProvider.S3, policyId);
|
||||
|
||||
recording.CameraId.ShouldBe(cameraId);
|
||||
recording.Timestamp.ShouldBe(ts);
|
||||
recording.DurationSeconds.ShouldBe(60.0);
|
||||
recording.StoragePath.ShouldBe("recordings/2026/07/01/12/cam1.mp4");
|
||||
recording.SizeBytes.ShouldBe(10_000_000L);
|
||||
recording.StorageProvider.ShouldBe(StorageProvider.S3);
|
||||
recording.StoragePolicyId.ShouldBe(policyId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Recording_assign_policy_should_update_relation()
|
||||
{
|
||||
var recording = new Recording(Guid.NewGuid(), DateTime.UtcNow, 60, "path.mp4", 100, StorageProvider.Local);
|
||||
var policyId = Guid.NewGuid();
|
||||
|
||||
recording.AssignStoragePolicy(policyId);
|
||||
|
||||
recording.StoragePolicyId.ShouldBe(policyId);
|
||||
}
|
||||
|
||||
// ─── LicensePlate ──────────────────────────────────────────────
|
||||
|
||||
[Fact]
|
||||
public void LicensePlate_create_should_set_properties()
|
||||
{
|
||||
var plate = new LicensePlate("AB-123-CD", null, null, 0.98);
|
||||
|
||||
plate.PlateText.ShouldBe("AB-123-CD");
|
||||
plate.Confidence.ShouldBe(0.98);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void LicensePlate_assign_vehicle_and_person_should_set_relations()
|
||||
{
|
||||
var plate = new LicensePlate("AB-123-CD");
|
||||
var vehicleId = Guid.NewGuid();
|
||||
var personId = Guid.NewGuid();
|
||||
|
||||
plate.AssignVehicle(vehicleId);
|
||||
plate.AssignPerson(personId);
|
||||
|
||||
plate.VehicleId.ShouldBe(vehicleId);
|
||||
plate.PersonId.ShouldBe(personId);
|
||||
}
|
||||
|
||||
// ─── CameraEvent — relations enrichies (spec 2.2) ─────────────
|
||||
|
||||
[Fact]
|
||||
public void CameraEvent_assign_vehicle_recording_and_parent_should_set_relations()
|
||||
{
|
||||
var evt = new CameraEvent(Guid.NewGuid(), EventType.VehicleDetected, 0.9);
|
||||
var vehicleId = Guid.NewGuid();
|
||||
var recordingId = Guid.NewGuid();
|
||||
var parentId = Guid.NewGuid();
|
||||
|
||||
evt.AssignVehicle(vehicleId);
|
||||
evt.AssignRecording(recordingId);
|
||||
evt.AssignParentEvent(parentId);
|
||||
|
||||
evt.VehicleId.ShouldBe(vehicleId);
|
||||
evt.RecordingId.ShouldBe(recordingId);
|
||||
evt.ParentEventId.ShouldBe(parentId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CameraEvent_dedup_fields_should_be_settable()
|
||||
{
|
||||
var evt = new CameraEvent(Guid.NewGuid(), EventType.PersonDetected, 0.85);
|
||||
|
||||
evt.SetTrackId("track-42");
|
||||
evt.SetDetectionHash("sha256:abc123");
|
||||
evt.SetSuppressed(true);
|
||||
|
||||
evt.TrackId.ShouldBe("track-42");
|
||||
evt.DetectionHash.ShouldBe("sha256:abc123");
|
||||
evt.IsSuppressed.ShouldBeTrue();
|
||||
}
|
||||
|
||||
// ─── Camera → StoragePolicy (N:1) ──────────────────────────────
|
||||
|
||||
[Fact]
|
||||
public void Camera_assign_storage_policy_should_set_relation()
|
||||
{
|
||||
var camera = new Camera(Guid.NewGuid(), "Entrée");
|
||||
var policyId = Guid.NewGuid();
|
||||
|
||||
camera.AssignStoragePolicy(policyId);
|
||||
|
||||
camera.StoragePolicyId.ShouldBe(policyId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,196 @@
|
||||
using Heimdall.Domain.Entities;
|
||||
using Heimdall.Domain.Enums;
|
||||
using Heimdall.Infrastructure.Data;
|
||||
using Heimdall.Infrastructure.Data.Interceptors;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Shouldly;
|
||||
|
||||
using Heimdall.TestCommon;
|
||||
|
||||
namespace Heimdall.Infrastructure.Tests;
|
||||
|
||||
/// <summary>
|
||||
/// Validation des entités métier (spec 2.1/2.2) sur PostgreSQL réel :
|
||||
/// Vehicle, Recording, LicensePlate, StoragePolicy + relations CameraEvent→Vehicle/Recording,
|
||||
/// Camera→StoragePolicy N:1.
|
||||
/// </summary>
|
||||
[Collection("PostgresInfra")]
|
||||
public class BusinessEntityPersistenceTests : IAsyncLifetime
|
||||
{
|
||||
private readonly IDbContextFactory<AppDbContext> _dbFactory;
|
||||
|
||||
public BusinessEntityPersistenceTests(PostgreSqlContainerFixture postgres)
|
||||
{
|
||||
_dbFactory = CreateFactory(postgres.ConnectionString);
|
||||
}
|
||||
|
||||
public async Task InitializeAsync()
|
||||
{
|
||||
await ResetDatabaseAsync();
|
||||
}
|
||||
|
||||
public Task DisposeAsync() => Task.CompletedTask;
|
||||
|
||||
private async Task ResetDatabaseAsync()
|
||||
{
|
||||
await using var db = await _dbFactory.CreateDbContextAsync();
|
||||
await db.Database.ExecuteSqlRawAsync(
|
||||
"TRUNCATE TABLE license_plates, recordings, vehicles, storage_policies, camera_events, cameras, sites RESTART IDENTITY CASCADE");
|
||||
}
|
||||
|
||||
private static TestDbContextFactory CreateFactory(string connectionString)
|
||||
{
|
||||
var opts = new DbContextOptionsBuilder<AppDbContext>()
|
||||
.UseNpgsql(connectionString, npgsql =>
|
||||
npgsql.MigrationsHistoryTable("__EFMigrationsHistory", "public"))
|
||||
.Options;
|
||||
|
||||
// Ensure tables exist (l'extension pg_trgm est requise pour l'index GIN trigram)
|
||||
using var conn = new Npgsql.NpgsqlConnection(connectionString);
|
||||
conn.Open();
|
||||
using (var cmd = conn.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = "CREATE EXTENSION IF NOT EXISTS pg_trgm;";
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
using var ctx = new AppDbContext(opts, new AuditInterceptor());
|
||||
ctx.Database.EnsureCreated();
|
||||
|
||||
return new TestDbContextFactory(opts);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task StoragePolicy_can_be_created_and_shared_by_cameras()
|
||||
{
|
||||
await using var db = await _dbFactory.CreateDbContextAsync();
|
||||
var site = new Site("Biz Site", "test", "UTC");
|
||||
db.Sites.Add(site);
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
var policy = new StoragePolicy("30 jours", 30, StorageProvider.S3);
|
||||
db.StoragePolicies.Add(policy);
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
var cam1 = new Camera(site.Id, "Cam-1");
|
||||
cam1.AssignStoragePolicy(policy.Id);
|
||||
var cam2 = new Camera(site.Id, "Cam-2");
|
||||
cam2.AssignStoragePolicy(policy.Id);
|
||||
db.Cameras.AddRange(cam1, cam2);
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
// Recharger : les 2 caméras partagent la même politique (N:1)
|
||||
var reloaded = await db.Cameras
|
||||
.Include(c => c.StoragePolicy)
|
||||
.Where(c => c.SiteId == site.Id)
|
||||
.ToListAsync();
|
||||
reloaded.Count.ShouldBe(2);
|
||||
reloaded.ShouldAllBe(c => c.StoragePolicyId == policy.Id);
|
||||
reloaded.ShouldAllBe(c => c.StoragePolicy!.Name == "30 jours");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task CameraEvent_can_link_vehicle_and_recording()
|
||||
{
|
||||
await using var db = await _dbFactory.CreateDbContextAsync();
|
||||
var site = new Site("Biz Site 2", "test", "UTC");
|
||||
db.Sites.Add(site);
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
var camera = new Camera(site.Id, "Cam-Event");
|
||||
db.Cameras.Add(camera);
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
var vehicle = new Vehicle("AB-123-CD", null, "Renault", "Clio", "Noir");
|
||||
db.Vehicles.Add(vehicle);
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
var recording = new Recording(camera.Id, DateTime.UtcNow, 60, "rec/1.mp4", 1000, StorageProvider.S3);
|
||||
db.Recordings.Add(recording);
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
var evt = new CameraEvent(camera.Id, EventType.VehicleDetected, 0.92);
|
||||
evt.AssignVehicle(vehicle.Id);
|
||||
evt.AssignRecording(recording.Id);
|
||||
evt.SetTrackId("track-1");
|
||||
evt.SetDetectionHash("hash-1");
|
||||
db.CameraEvents.Add(evt);
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
var reloaded = await db.CameraEvents
|
||||
.Include(e => e.Vehicle)
|
||||
.Include(e => e.Recording)
|
||||
.SingleAsync(e => e.Id == evt.Id);
|
||||
reloaded.VehicleId.ShouldBe(vehicle.Id);
|
||||
reloaded.Vehicle!.LicensePlate.ShouldBe("AB-123-CD");
|
||||
reloaded.RecordingId.ShouldBe(recording.Id);
|
||||
reloaded.Recording!.StoragePath.ShouldBe("rec/1.mp4");
|
||||
reloaded.TrackId.ShouldBe("track-1");
|
||||
reloaded.DetectionHash.ShouldBe("hash-1");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task LicensePlate_can_link_vehicle_and_person()
|
||||
{
|
||||
await using var db = await _dbFactory.CreateDbContextAsync();
|
||||
var person = new Person("Jean Dupont");
|
||||
db.Persons.Add(person);
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
var vehicle = new Vehicle("AB-123-CD");
|
||||
vehicle.AssignPerson(person.Id);
|
||||
db.Vehicles.Add(vehicle);
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
var plate = new LicensePlate("AB-123-CD", vehicle.Id, person.Id, 0.98);
|
||||
db.LicensePlates.Add(plate);
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
var reloaded = await db.LicensePlates
|
||||
.Include(p => p.Vehicle)
|
||||
.Include(p => p.Person)
|
||||
.SingleAsync(p => p.Id == plate.Id);
|
||||
reloaded.PlateText.ShouldBe("AB-123-CD");
|
||||
reloaded.VehicleId.ShouldBe(vehicle.Id);
|
||||
reloaded.PersonId.ShouldBe(person.Id);
|
||||
reloaded.Vehicle!.LicensePlate.ShouldBe("AB-123-CD");
|
||||
reloaded.Person!.DisplayName.ShouldBe("Jean Dupont");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task CameraEvent_parent_child_hierarchy_works()
|
||||
{
|
||||
await using var db = await _dbFactory.CreateDbContextAsync();
|
||||
var site = new Site("Biz Site 3", "test", "UTC");
|
||||
db.Sites.Add(site);
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
var camera = new Camera(site.Id, "Cam-Hier");
|
||||
db.Cameras.Add(camera);
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
var parent = new CameraEvent(camera.Id, EventType.MotionDetected, 0.8);
|
||||
db.CameraEvents.Add(parent);
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
var child = new CameraEvent(camera.Id, EventType.PersonDetected, 0.95);
|
||||
child.AssignParentEvent(parent.Id);
|
||||
db.CameraEvents.Add(child);
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
var reloaded = await db.CameraEvents
|
||||
.Include(e => e.ParentEvent)
|
||||
.SingleAsync(e => e.Id == child.Id);
|
||||
reloaded.ParentEventId.ShouldBe(parent.Id);
|
||||
reloaded.ParentEvent!.Type.ShouldBe(EventType.MotionDetected);
|
||||
}
|
||||
|
||||
private sealed class TestDbContextFactory(DbContextOptions<AppDbContext> opts)
|
||||
: IDbContextFactory<AppDbContext>
|
||||
{
|
||||
private static readonly AuditInterceptor Audit = new();
|
||||
|
||||
public AppDbContext CreateDbContext() => new(opts, Audit);
|
||||
public Task<AppDbContext> CreateDbContextAsync(CancellationToken ct = default)
|
||||
=> Task.FromResult(new AppDbContext(opts, Audit));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user