From a33a436c26961ce33345631cd982f2805ee2a116 Mon Sep 17 00:00:00 2001 From: Arnaud Dartois Date: Mon, 20 Jul 2026 09:50:43 +0000 Subject: [PATCH] chore: apply auto-fixes and code improvements - AuthService: fix public registration logic revert - JwtService: add ILogger dependency - SoftDeleteInterceptor removed (merged) - XML doc comments on all services - Error boundary + error page in Blazor - Optimize StatsService queries - ApiClient error handling improvements --- src/Heimdall.Agent/Services/AgentState.cs | 14 +- .../Services/CameraStreamService.cs | 19 +- .../Controllers/SettingsController.cs | 22 +- src/Heimdall.Application/DTOs/CameraDto.cs | 4 +- .../Data/AppDbContext.cs | 8 +- .../Data/AppDbContextFactory.cs | 4 +- .../Interceptors/SoftDeleteInterceptor.cs | 31 - .../DependencyInjection.cs | 3 +- .../20260716204205_InitialCreate.Designer.cs | 841 --------- ...17192108_AddMustChangePassword.Designer.cs | 846 --------- .../20260717192108_AddMustChangePassword.cs | 29 - ...192341_AddAuditLogUserRelation.Designer.cs | 856 --------- .../20260717192341_AddAuditLogUserRelation.cs | 30 - .../20260718143003_AddAppSettings.Designer.cs | 985 ----------- .../20260718143003_AddAppSettings.cs | 78 - .../20260719064824_AddGroups.Designer.cs | 1326 -------------- .../Migrations/20260719064824_AddGroups.cs | 366 ---- ...719122001_AddCameraAssignments.Designer.cs | 1383 --------------- .../20260719122001_AddCameraAssignments.cs | 68 - ...20260719125356_AddCameraEvents.Designer.cs | 1457 ---------------- .../20260719125356_AddCameraEvents.cs | 66 - .../20260719152833_AddPersonsAndKnownFaces.cs | 84 - ...95445_AddCameraDiscoveryFields.Designer.cs | 1548 ----------------- ...20260719195445_AddCameraDiscoveryFields.cs | 202 --- ... 20260720094830_InitialCreate.Designer.cs} | 6 +- ...ate.cs => 20260720094830_InitialCreate.cs} | 480 ++++- .../Migrations/AppDbContextModelSnapshot.cs | 2 +- .../Security/JwtService.cs | 24 +- .../Services/AgentService.cs | 6 +- .../Services/AuthService.cs | 2 +- .../Services/CameraService.cs | 2 +- .../Services/SnapshotService.cs | 19 +- .../Services/StatsService.cs | 26 +- src/Heimdall.Web/Components/App.razor | 24 +- .../Pages/Admin/AllAgentsPage.razor | 4 +- .../Components/Pages/Admin/ClaimsPage.razor | 4 +- src/Heimdall.Web/Components/Pages/Error.razor | 36 + src/Heimdall.Web/Components/Pages/Login.razor | 4 +- .../Components/Pages/Register.razor | 4 +- src/Heimdall.Web/Program.cs | 93 +- src/Heimdall.Web/Services/AuthHelper.cs | 9 +- .../Services/HeimdallApiClient.cs | 5 +- src/Heimdall.Workers/Program.cs | 5 +- .../CameraAssignmentServiceTests.cs | 6 +- .../CameraEventServiceTests.cs | 6 +- .../Controllers/AuthControllerTests.cs | 71 + .../Controllers/SettingsControllerTests.cs | 39 + .../Heimdall.IntegrationTests.csproj | 4 +- 48 files changed, 814 insertions(+), 10337 deletions(-) delete mode 100644 src/Heimdall.Infrastructure/Data/Interceptors/SoftDeleteInterceptor.cs delete mode 100644 src/Heimdall.Infrastructure/Migrations/20260716204205_InitialCreate.Designer.cs delete mode 100644 src/Heimdall.Infrastructure/Migrations/20260717192108_AddMustChangePassword.Designer.cs delete mode 100644 src/Heimdall.Infrastructure/Migrations/20260717192108_AddMustChangePassword.cs delete mode 100644 src/Heimdall.Infrastructure/Migrations/20260717192341_AddAuditLogUserRelation.Designer.cs delete mode 100644 src/Heimdall.Infrastructure/Migrations/20260717192341_AddAuditLogUserRelation.cs delete mode 100644 src/Heimdall.Infrastructure/Migrations/20260718143003_AddAppSettings.Designer.cs delete mode 100644 src/Heimdall.Infrastructure/Migrations/20260718143003_AddAppSettings.cs delete mode 100644 src/Heimdall.Infrastructure/Migrations/20260719064824_AddGroups.Designer.cs delete mode 100644 src/Heimdall.Infrastructure/Migrations/20260719064824_AddGroups.cs delete mode 100644 src/Heimdall.Infrastructure/Migrations/20260719122001_AddCameraAssignments.Designer.cs delete mode 100644 src/Heimdall.Infrastructure/Migrations/20260719122001_AddCameraAssignments.cs delete mode 100644 src/Heimdall.Infrastructure/Migrations/20260719125356_AddCameraEvents.Designer.cs delete mode 100644 src/Heimdall.Infrastructure/Migrations/20260719125356_AddCameraEvents.cs delete mode 100644 src/Heimdall.Infrastructure/Migrations/20260719152833_AddPersonsAndKnownFaces.cs delete mode 100644 src/Heimdall.Infrastructure/Migrations/20260719195445_AddCameraDiscoveryFields.Designer.cs delete mode 100644 src/Heimdall.Infrastructure/Migrations/20260719195445_AddCameraDiscoveryFields.cs rename src/Heimdall.Infrastructure/Migrations/{20260719152833_AddPersonsAndKnownFaces.Designer.cs => 20260720094830_InitialCreate.Designer.cs} (99%) rename src/Heimdall.Infrastructure/Migrations/{20260716204205_InitialCreate.cs => 20260720094830_InitialCreate.cs} (51%) create mode 100644 src/Heimdall.Web/Components/Pages/Error.razor diff --git a/src/Heimdall.Agent/Services/AgentState.cs b/src/Heimdall.Agent/Services/AgentState.cs index 9a8c039..a283e84 100644 --- a/src/Heimdall.Agent/Services/AgentState.cs +++ b/src/Heimdall.Agent/Services/AgentState.cs @@ -1,3 +1,4 @@ +using System.Runtime.InteropServices; using System.Text.Json; namespace Heimdall.Agent.Services; @@ -73,13 +74,24 @@ public sealed class AgentState } /// - /// Persists the current identity to disk. + /// Persists the current identity to disk with restrictive permissions (0600). + /// The API key is stored as plaintext — in a production deployment, consider + /// encrypting the file or using a hardware-bound keystore (e.g., TPM/TPM2). /// public async Task SaveAsync(CancellationToken ct = default) { Directory.CreateDirectory(_stateDir); + + // Set restrictive directory permissions (owner only) + if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + File.SetUnixFileMode(_stateDir, UnixFileMode.UserRead | UnixFileMode.UserWrite | UnixFileMode.UserExecute); + var json = JsonSerializer.Serialize(this); await File.WriteAllTextAsync(StatePath, json, ct); + + // Restrict file to owner read/write only (0600) + if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + File.SetUnixFileMode(StatePath, UnixFileMode.UserRead | UnixFileMode.UserWrite); } /// diff --git a/src/Heimdall.Agent/Services/CameraStreamService.cs b/src/Heimdall.Agent/Services/CameraStreamService.cs index c41681e..18988da 100644 --- a/src/Heimdall.Agent/Services/CameraStreamService.cs +++ b/src/Heimdall.Agent/Services/CameraStreamService.cs @@ -36,13 +36,27 @@ public sealed class CameraStreamService : IDisposable var psi = new ProcessStartInfo { FileName = "ffmpeg", - Arguments = $"-rtsp_transport tcp -i \"{rtspUrl}\" -f image2pipe -vcodec mjpeg -q:v 3 -update 1 -", RedirectStandardOutput = true, RedirectStandardError = true, UseShellExecute = false, CreateNoWindow = true, }; + // Use ArgumentList to prevent argument injection via rtspUrl + psi.ArgumentList.Add("-rtsp_transport"); + psi.ArgumentList.Add("tcp"); + psi.ArgumentList.Add("-i"); + psi.ArgumentList.Add(rtspUrl); + psi.ArgumentList.Add("-f"); + psi.ArgumentList.Add("image2pipe"); + psi.ArgumentList.Add("-vcodec"); + psi.ArgumentList.Add("mjpeg"); + psi.ArgumentList.Add("-q:v"); + psi.ArgumentList.Add("3"); + psi.ArgumentList.Add("-update"); + psi.ArgumentList.Add("1"); + psi.ArgumentList.Add("-"); + var process = new Process { StartInfo = psi }; process.Start(); @@ -70,6 +84,9 @@ public sealed class CameraStreamService : IDisposable if (_sessions.TryRemove(cameraId, out var session)) { session.Cancel(); + // Mark semaphore as released BEFORE releasing, so CleanupSession's + // finally block does NOT double-release (see SemaphoreReleased flag). + session.SemaphoreReleased = true; _throttle.Release(); _logger.LogInformation("Stream stopped for camera {CameraId}", cameraId); } diff --git a/src/Heimdall.Api/Controllers/SettingsController.cs b/src/Heimdall.Api/Controllers/SettingsController.cs index f4fbcec..45a952f 100644 --- a/src/Heimdall.Api/Controllers/SettingsController.cs +++ b/src/Heimdall.Api/Controllers/SettingsController.cs @@ -39,7 +39,14 @@ public class SettingsController : ControllerBase var result = await _settingService.GetAllSettingsAsync(ct); if (!result.IsSuccess) return StatusCode(result.StatusCode ?? 400, new { error = result.Error }); - return Ok(result.Data); + + // Redact sensitive values before returning to client + var redacted = result.Data!.Select(s => s with + { + Value = RedactValue(s.ValueType, s.Value, s.Key) + }).ToList(); + + return Ok(redacted); } /// Get a global setting by key (Admin only). @@ -50,9 +57,16 @@ public class SettingsController : ControllerBase public async Task GetByKey(string key, CancellationToken ct) { var result = await _settingService.GetSettingByKeyAsync(key, ct); - return result.IsSuccess - ? Ok(result.Data) - : NotFound(new { error = result.Error }); + if (!result.IsSuccess) + return NotFound(new { error = result.Error }); + + // Redact sensitive values before returning to client + var redacted = result.Data! with + { + Value = RedactValue(result.Data.ValueType, result.Data.Value, result.Data.Key) + }; + + return Ok(redacted); } /// Create a new global setting (Admin only). diff --git a/src/Heimdall.Application/DTOs/CameraDto.cs b/src/Heimdall.Application/DTOs/CameraDto.cs index 3488a34..43a6291 100644 --- a/src/Heimdall.Application/DTOs/CameraDto.cs +++ b/src/Heimdall.Application/DTOs/CameraDto.cs @@ -12,7 +12,9 @@ public record CreateCameraRequest( public record UpdateCameraRequest( string Name, string? RtspUrl, - CameraStatus? Status); + CameraStatus? Status, + string? Manufacturer = null, + string? Model = null); /// Camera response including all discovery and stream test metadata. public record CameraResponse( diff --git a/src/Heimdall.Infrastructure/Data/AppDbContext.cs b/src/Heimdall.Infrastructure/Data/AppDbContext.cs index 5245a0c..8317743 100644 --- a/src/Heimdall.Infrastructure/Data/AppDbContext.cs +++ b/src/Heimdall.Infrastructure/Data/AppDbContext.cs @@ -10,15 +10,12 @@ namespace Heimdall.Infrastructure.Data; public class AppDbContext : IdentityDbContext { private readonly AuditInterceptor _auditInterceptor; - private readonly SoftDeleteInterceptor _softDeleteInterceptor; public AppDbContext( DbContextOptions options, - AuditInterceptor auditInterceptor, - SoftDeleteInterceptor softDeleteInterceptor) : base(options) + AuditInterceptor auditInterceptor) : base(options) { _auditInterceptor = auditInterceptor; - _softDeleteInterceptor = softDeleteInterceptor; } // Domain entities @@ -77,8 +74,7 @@ public class AppDbContext : IdentityDbContext protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { optionsBuilder.AddInterceptors( - _auditInterceptor, - _softDeleteInterceptor); + _auditInterceptor); // Suppress informational EF Core messages that create noise in // error tracking (GlitchTip #538). Redundant index warnings are diff --git a/src/Heimdall.Infrastructure/Data/AppDbContextFactory.cs b/src/Heimdall.Infrastructure/Data/AppDbContextFactory.cs index ed64371..9fba9ff 100644 --- a/src/Heimdall.Infrastructure/Data/AppDbContextFactory.cs +++ b/src/Heimdall.Infrastructure/Data/AppDbContextFactory.cs @@ -1,3 +1,4 @@ + using Heimdall.Infrastructure.Data.Interceptors; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Design; @@ -22,7 +23,6 @@ public class AppDbContextFactory : IDesignTimeDbContextFactory return new AppDbContext( optionsBuilder.Options, - new AuditInterceptor(), - new SoftDeleteInterceptor()); + new AuditInterceptor()); } } diff --git a/src/Heimdall.Infrastructure/Data/Interceptors/SoftDeleteInterceptor.cs b/src/Heimdall.Infrastructure/Data/Interceptors/SoftDeleteInterceptor.cs deleted file mode 100644 index 41901db..0000000 --- a/src/Heimdall.Infrastructure/Data/Interceptors/SoftDeleteInterceptor.cs +++ /dev/null @@ -1,31 +0,0 @@ -using Heimdall.Domain.Primitives; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Diagnostics; - -namespace Heimdall.Infrastructure.Data.Interceptors; - -public sealed class SoftDeleteInterceptor : SaveChangesInterceptor -{ - public override ValueTask> SavingChangesAsync( - DbContextEventData eventData, - InterceptionResult result, - CancellationToken cancellationToken = default) - { - if (eventData.Context is null) - return base.SavingChangesAsync(eventData, result, cancellationToken); - - var entries = eventData.Context.ChangeTracker - .Entries(); - - foreach (var entry in entries) - { - if (entry.State is EntityState.Deleted) - { - entry.State = EntityState.Modified; - entry.Entity.SoftDelete(); - } - } - - return base.SavingChangesAsync(eventData, result, cancellationToken); - } -} diff --git a/src/Heimdall.Infrastructure/DependencyInjection.cs b/src/Heimdall.Infrastructure/DependencyInjection.cs index 760370b..9c03c7e 100644 --- a/src/Heimdall.Infrastructure/DependencyInjection.cs +++ b/src/Heimdall.Infrastructure/DependencyInjection.cs @@ -24,9 +24,8 @@ public static class DependencyInjection var env = environmentName ?? Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Production"; var isTesting = env == "Testing"; - // EF Core interceptors (registered as singletons — they are stateless) + // EF Core interceptor (registered as singleton — it is stateless) services.AddSingleton(); - services.AddSingleton(); if (isTesting) { diff --git a/src/Heimdall.Infrastructure/Migrations/20260716204205_InitialCreate.Designer.cs b/src/Heimdall.Infrastructure/Migrations/20260716204205_InitialCreate.Designer.cs deleted file mode 100644 index bc89781..0000000 --- a/src/Heimdall.Infrastructure/Migrations/20260716204205_InitialCreate.Designer.cs +++ /dev/null @@ -1,841 +0,0 @@ -// -using System; -using Heimdall.Infrastructure.Data; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; - -#nullable disable - -namespace Heimdall.Infrastructure.Migrations -{ - [DbContext(typeof(AppDbContext))] - [Migration("20260716204205_InitialCreate")] - partial class InitialCreate - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "10.0.8") - .HasAnnotation("Relational:MaxIdentifierLength", 63); - - NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); - - modelBuilder.Entity("Heimdall.Domain.Entities.Agent", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("ApiKeyHash") - .HasMaxLength(128) - .HasColumnType("character varying(128)"); - - b.Property("ApiKeyPrefix") - .HasMaxLength(8) - .HasColumnType("character varying(8)"); - - b.Property("CpuCores") - .HasColumnType("integer"); - - b.Property("CreatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.Property("DeletedAt") - .HasColumnType("timestamp with time zone"); - - b.Property("GpuType") - .IsRequired() - .HasMaxLength(20) - .HasColumnType("character varying(20)"); - - b.Property("HasGpu") - .HasColumnType("boolean"); - - b.Property("Hostname") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("character varying(255)"); - - b.Property("IsDeleted") - .HasColumnType("boolean"); - - b.Property("LastHeartbeat") - .HasColumnType("timestamp with time zone"); - - b.Property("MemoryMb") - .HasColumnType("bigint"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(200) - .HasColumnType("character varying(200)"); - - b.Property("PublicIp") - .HasMaxLength(45) - .HasColumnType("character varying(45)"); - - b.Property("SiteId") - .HasColumnType("uuid"); - - b.Property("Status") - .IsRequired() - .HasMaxLength(20) - .HasColumnType("character varying(20)"); - - b.Property("UpdatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.Property("Version") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("character varying(50)"); - - b.HasKey("Id"); - - b.HasIndex("LastHeartbeat") - .HasFilter("\"Status\" = 'Online'"); - - b.HasIndex("SiteId"); - - b.ToTable("agents", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.ApiKey", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("CreatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.Property("CreatedByUserId") - .HasColumnType("uuid"); - - b.Property("Enabled") - .HasColumnType("boolean"); - - b.Property("ExpiresAt") - .HasColumnType("timestamp with time zone"); - - b.Property("KeyHash") - .IsRequired() - .HasMaxLength(128) - .HasColumnType("character varying(128)"); - - b.Property("KeyPrefix") - .IsRequired() - .HasMaxLength(8) - .HasColumnType("character varying(8)"); - - b.Property("LastUsedAt") - .HasColumnType("timestamp with time zone"); - - b.Property("SiteId") - .HasColumnType("uuid"); - - b.HasKey("Id"); - - b.HasIndex("KeyHash"); - - b.HasIndex("KeyPrefix"); - - b.HasIndex("SiteId"); - - b.ToTable("api_keys", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.AppRole", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("ConcurrencyStamp") - .IsConcurrencyToken() - .HasColumnType("text"); - - b.Property("Name") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.Property("NormalizedName") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.HasKey("Id"); - - b.HasIndex("NormalizedName") - .IsUnique() - .HasDatabaseName("RoleNameIndex"); - - b.ToTable("roles", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.AppUser", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("AccessFailedCount") - .HasColumnType("integer"); - - b.Property("ConcurrencyStamp") - .IsConcurrencyToken() - .HasColumnType("text"); - - b.Property("CreatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.Property("DisplayName") - .IsRequired() - .HasMaxLength(200) - .HasColumnType("character varying(200)"); - - b.Property("Email") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.Property("EmailConfirmed") - .HasColumnType("boolean"); - - b.Property("Language") - .IsRequired() - .ValueGeneratedOnAdd() - .HasMaxLength(10) - .HasColumnType("character varying(10)") - .HasDefaultValue("fr"); - - b.Property("LockoutEnabled") - .HasColumnType("boolean"); - - b.Property("LockoutEnd") - .HasColumnType("timestamp with time zone"); - - b.Property("NormalizedEmail") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.Property("NormalizedUserName") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.Property("PasswordHash") - .HasColumnType("text"); - - b.Property("PhoneNumber") - .HasColumnType("text"); - - b.Property("PhoneNumberConfirmed") - .HasColumnType("boolean"); - - b.Property("SecurityStamp") - .HasColumnType("text"); - - b.Property("Theme") - .ValueGeneratedOnAdd() - .HasMaxLength(20) - .HasColumnType("character varying(20)") - .HasDefaultValue("Auto"); - - b.Property("TwoFactorEnabled") - .HasColumnType("boolean"); - - b.Property("UserName") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.HasKey("Id"); - - b.HasIndex("NormalizedEmail") - .HasDatabaseName("EmailIndex"); - - b.HasIndex("NormalizedUserName") - .IsUnique() - .HasDatabaseName("UserNameIndex"); - - b.ToTable("users", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.AuditLog", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("Action") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("IpAddress") - .HasMaxLength(45) - .HasColumnType("character varying(45)"); - - b.Property("NewValue") - .HasColumnType("text"); - - b.Property("OldValue") - .HasColumnType("text"); - - b.Property("ResourceId") - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("ResourceType") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("Timestamp") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.Property("UserId") - .HasColumnType("uuid"); - - b.HasKey("Id"); - - b.HasIndex("Timestamp") - .IsDescending(); - - b.HasIndex("UserId"); - - b.HasIndex("ResourceType", "ResourceId", "Timestamp") - .IsDescending(false, false, true); - - b.ToTable("audit_logs", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.Camera", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("AgentId") - .HasColumnType("uuid"); - - b.Property("CreatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.Property("DeletedAt") - .HasColumnType("timestamp with time zone"); - - b.Property("HasAudio") - .HasColumnType("boolean"); - - b.Property("HasMotionDetection") - .HasColumnType("boolean"); - - b.Property("HasPtz") - .HasColumnType("boolean"); - - b.Property("IsDeleted") - .HasColumnType("boolean"); - - b.Property("Manufacturer") - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("Model") - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(200) - .HasColumnType("character varying(200)"); - - b.Property("RtspUrl") - .HasMaxLength(1000) - .HasColumnType("character varying(1000)"); - - b.Property("SiteId") - .HasColumnType("uuid"); - - b.Property("Status") - .IsRequired() - .HasMaxLength(20) - .HasColumnType("character varying(20)"); - - b.Property("UpdatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.HasKey("Id"); - - b.HasIndex("AgentId"); - - b.HasIndex("SiteId"); - - b.ToTable("cameras", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.CameraCredentials", b => - { - b.Property("CameraId") - .HasColumnType("uuid"); - - b.Property("CreatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.Property("OnvifPassword") - .IsRequired() - .HasMaxLength(500) - .HasColumnType("character varying(500)"); - - b.Property("OnvifUsername") - .IsRequired() - .ValueGeneratedOnAdd() - .HasMaxLength(100) - .HasColumnType("character varying(100)") - .HasDefaultValue("admin"); - - b.Property("RtspPassword") - .IsRequired() - .HasMaxLength(500) - .HasColumnType("character varying(500)"); - - b.Property("RtspUsername") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("UpdatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.HasKey("CameraId"); - - b.ToTable("camera_credentials", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.CameraDetectionProfile", b => - { - b.Property("CameraId") - .HasColumnType("uuid"); - - b.Property("ActiveIntervalMs") - .HasColumnType("integer"); - - b.Property("AnimalCooldownSec") - .HasColumnType("integer"); - - b.Property("DetectAnimal") - .HasColumnType("boolean"); - - b.Property("DetectMotion") - .HasColumnType("boolean"); - - b.Property("DetectPackage") - .HasColumnType("boolean"); - - b.Property("DetectPerson") - .HasColumnType("boolean"); - - b.Property("DetectVehicle") - .HasColumnType("boolean"); - - b.Property("FaceRecognition") - .HasColumnType("boolean"); - - b.Property("IdleIntervalMs") - .HasColumnType("integer"); - - b.Property("IoUThreshold") - .HasColumnType("double precision"); - - b.Property("LicensePlateRecognition") - .HasColumnType("boolean"); - - b.Property("MaxEventsPerMinute") - .HasColumnType("integer"); - - b.Property("MinConfidence") - .ValueGeneratedOnAdd() - .HasColumnType("double precision") - .HasDefaultValue(0.40000000000000002); - - b.Property("MotionIntervalMs") - .HasColumnType("integer"); - - b.Property("MotionThreshold") - .HasColumnType("double precision"); - - b.Property("PersonCooldownSec") - .HasColumnType("integer"); - - b.Property("RequireMotionForAI") - .HasColumnType("boolean"); - - b.Property("VehicleCooldownSec") - .HasColumnType("integer"); - - b.Property("YoloModel") - .IsRequired() - .ValueGeneratedOnAdd() - .HasMaxLength(50) - .HasColumnType("character varying(50)") - .HasDefaultValue("yolov8n"); - - b.HasKey("CameraId"); - - b.ToTable("camera_detection_profiles", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.Site", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("Address") - .HasMaxLength(500) - .HasColumnType("character varying(500)"); - - b.Property("CreatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.Property("DeletedAt") - .HasColumnType("timestamp with time zone"); - - b.Property("Enabled") - .HasColumnType("boolean"); - - b.Property("IsDeleted") - .HasColumnType("boolean"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(200) - .HasColumnType("character varying(200)"); - - b.Property("RegistrationTokenHash") - .HasMaxLength(128) - .HasColumnType("character varying(128)"); - - b.Property("Timezone") - .IsRequired() - .ValueGeneratedOnAdd() - .HasMaxLength(100) - .HasColumnType("character varying(100)") - .HasDefaultValue("UTC"); - - b.Property("TokenExpiresAt") - .HasColumnType("timestamp with time zone"); - - b.Property("UpdatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.HasKey("Id"); - - b.HasIndex("IsDeleted") - .HasFilter("\"IsDeleted\" = false"); - - b.HasIndex("Name"); - - b.ToTable("sites", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.UserSite", b => - { - b.Property("UserId") - .HasColumnType("uuid"); - - b.Property("SiteId") - .HasColumnType("uuid"); - - b.HasKey("UserId", "SiteId"); - - b.HasIndex("SiteId"); - - b.ToTable("user_sites", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("ClaimType") - .HasColumnType("text"); - - b.Property("ClaimValue") - .HasColumnType("text"); - - b.Property("RoleId") - .HasColumnType("uuid"); - - b.HasKey("Id"); - - b.HasIndex("RoleId"); - - b.ToTable("role_claims", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("ClaimType") - .HasColumnType("text"); - - b.Property("ClaimValue") - .HasColumnType("text"); - - b.Property("UserId") - .HasColumnType("uuid"); - - b.HasKey("Id"); - - b.HasIndex("UserId"); - - b.ToTable("user_claims", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => - { - b.Property("LoginProvider") - .HasColumnType("text"); - - b.Property("ProviderKey") - .HasColumnType("text"); - - b.Property("ProviderDisplayName") - .HasColumnType("text"); - - b.Property("UserId") - .HasColumnType("uuid"); - - b.HasKey("LoginProvider", "ProviderKey"); - - b.HasIndex("UserId"); - - b.ToTable("user_logins", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => - { - b.Property("UserId") - .HasColumnType("uuid"); - - b.Property("RoleId") - .HasColumnType("uuid"); - - b.HasKey("UserId", "RoleId"); - - b.HasIndex("RoleId"); - - b.ToTable("user_roles", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => - { - b.Property("UserId") - .HasColumnType("uuid"); - - b.Property("LoginProvider") - .HasColumnType("text"); - - b.Property("Name") - .HasColumnType("text"); - - b.Property("Value") - .HasColumnType("text"); - - b.HasKey("UserId", "LoginProvider", "Name"); - - b.ToTable("user_tokens", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.Agent", b => - { - b.HasOne("Heimdall.Domain.Entities.Site", "Site") - .WithMany("Agents") - .HasForeignKey("SiteId") - .OnDelete(DeleteBehavior.Restrict) - .IsRequired(); - - b.Navigation("Site"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.ApiKey", b => - { - b.HasOne("Heimdall.Domain.Entities.Site", "Site") - .WithMany() - .HasForeignKey("SiteId") - .OnDelete(DeleteBehavior.Restrict); - - b.Navigation("Site"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.Camera", b => - { - b.HasOne("Heimdall.Domain.Entities.Agent", "Agent") - .WithMany("Cameras") - .HasForeignKey("AgentId") - .OnDelete(DeleteBehavior.SetNull); - - b.HasOne("Heimdall.Domain.Entities.Site", "Site") - .WithMany("Cameras") - .HasForeignKey("SiteId") - .OnDelete(DeleteBehavior.Restrict) - .IsRequired(); - - b.Navigation("Agent"); - - b.Navigation("Site"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.CameraCredentials", b => - { - b.HasOne("Heimdall.Domain.Entities.Camera", "Camera") - .WithOne("Credentials") - .HasForeignKey("Heimdall.Domain.Entities.CameraCredentials", "CameraId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Camera"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.CameraDetectionProfile", b => - { - b.HasOne("Heimdall.Domain.Entities.Camera", "Camera") - .WithOne("DetectionProfile") - .HasForeignKey("Heimdall.Domain.Entities.CameraDetectionProfile", "CameraId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Camera"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.UserSite", b => - { - b.HasOne("Heimdall.Domain.Entities.Site", "Site") - .WithMany() - .HasForeignKey("SiteId") - .OnDelete(DeleteBehavior.Restrict) - .IsRequired(); - - b.HasOne("Heimdall.Domain.Entities.AppUser", "User") - .WithMany("UserSites") - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Site"); - - b.Navigation("User"); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => - { - b.HasOne("Heimdall.Domain.Entities.AppRole", null) - .WithMany() - .HasForeignKey("RoleId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => - { - b.HasOne("Heimdall.Domain.Entities.AppUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => - { - b.HasOne("Heimdall.Domain.Entities.AppUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => - { - b.HasOne("Heimdall.Domain.Entities.AppRole", null) - .WithMany() - .HasForeignKey("RoleId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("Heimdall.Domain.Entities.AppUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => - { - b.HasOne("Heimdall.Domain.Entities.AppUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.Agent", b => - { - b.Navigation("Cameras"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.AppUser", b => - { - b.Navigation("UserSites"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.Camera", b => - { - b.Navigation("Credentials"); - - b.Navigation("DetectionProfile"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.Site", b => - { - b.Navigation("Agents"); - - b.Navigation("Cameras"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/src/Heimdall.Infrastructure/Migrations/20260717192108_AddMustChangePassword.Designer.cs b/src/Heimdall.Infrastructure/Migrations/20260717192108_AddMustChangePassword.Designer.cs deleted file mode 100644 index e30130f..0000000 --- a/src/Heimdall.Infrastructure/Migrations/20260717192108_AddMustChangePassword.Designer.cs +++ /dev/null @@ -1,846 +0,0 @@ -// -using System; -using Heimdall.Infrastructure.Data; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; - -#nullable disable - -namespace Heimdall.Infrastructure.Migrations -{ - [DbContext(typeof(AppDbContext))] - [Migration("20260717192108_AddMustChangePassword")] - partial class AddMustChangePassword - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "10.0.8") - .HasAnnotation("Relational:MaxIdentifierLength", 63); - - NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); - - modelBuilder.Entity("Heimdall.Domain.Entities.Agent", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("ApiKeyHash") - .HasMaxLength(128) - .HasColumnType("character varying(128)"); - - b.Property("ApiKeyPrefix") - .HasMaxLength(8) - .HasColumnType("character varying(8)"); - - b.Property("CpuCores") - .HasColumnType("integer"); - - b.Property("CreatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.Property("DeletedAt") - .HasColumnType("timestamp with time zone"); - - b.Property("GpuType") - .IsRequired() - .HasMaxLength(20) - .HasColumnType("character varying(20)"); - - b.Property("HasGpu") - .HasColumnType("boolean"); - - b.Property("Hostname") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("character varying(255)"); - - b.Property("IsDeleted") - .HasColumnType("boolean"); - - b.Property("LastHeartbeat") - .HasColumnType("timestamp with time zone"); - - b.Property("MemoryMb") - .HasColumnType("bigint"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(200) - .HasColumnType("character varying(200)"); - - b.Property("PublicIp") - .HasMaxLength(45) - .HasColumnType("character varying(45)"); - - b.Property("SiteId") - .HasColumnType("uuid"); - - b.Property("Status") - .IsRequired() - .HasMaxLength(20) - .HasColumnType("character varying(20)"); - - b.Property("UpdatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.Property("Version") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("character varying(50)"); - - b.HasKey("Id"); - - b.HasIndex("LastHeartbeat") - .HasFilter("\"Status\" = 'Online'"); - - b.HasIndex("SiteId"); - - b.ToTable("agents", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.ApiKey", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("CreatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.Property("CreatedByUserId") - .HasColumnType("uuid"); - - b.Property("Enabled") - .HasColumnType("boolean"); - - b.Property("ExpiresAt") - .HasColumnType("timestamp with time zone"); - - b.Property("KeyHash") - .IsRequired() - .HasMaxLength(128) - .HasColumnType("character varying(128)"); - - b.Property("KeyPrefix") - .IsRequired() - .HasMaxLength(8) - .HasColumnType("character varying(8)"); - - b.Property("LastUsedAt") - .HasColumnType("timestamp with time zone"); - - b.Property("SiteId") - .HasColumnType("uuid"); - - b.HasKey("Id"); - - b.HasIndex("KeyHash"); - - b.HasIndex("KeyPrefix"); - - b.HasIndex("SiteId"); - - b.ToTable("api_keys", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.AppRole", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("ConcurrencyStamp") - .IsConcurrencyToken() - .HasColumnType("text"); - - b.Property("Name") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.Property("NormalizedName") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.HasKey("Id"); - - b.HasIndex("NormalizedName") - .IsUnique() - .HasDatabaseName("RoleNameIndex"); - - b.ToTable("roles", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.AppUser", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("AccessFailedCount") - .HasColumnType("integer"); - - b.Property("ConcurrencyStamp") - .IsConcurrencyToken() - .HasColumnType("text"); - - b.Property("CreatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.Property("DisplayName") - .IsRequired() - .HasMaxLength(200) - .HasColumnType("character varying(200)"); - - b.Property("Email") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.Property("EmailConfirmed") - .HasColumnType("boolean"); - - b.Property("Language") - .IsRequired() - .ValueGeneratedOnAdd() - .HasMaxLength(10) - .HasColumnType("character varying(10)") - .HasDefaultValue("fr"); - - b.Property("LockoutEnabled") - .HasColumnType("boolean"); - - b.Property("LockoutEnd") - .HasColumnType("timestamp with time zone"); - - b.Property("MustChangePassword") - .ValueGeneratedOnAdd() - .HasColumnType("boolean") - .HasDefaultValue(false); - - b.Property("NormalizedEmail") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.Property("NormalizedUserName") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.Property("PasswordHash") - .HasColumnType("text"); - - b.Property("PhoneNumber") - .HasColumnType("text"); - - b.Property("PhoneNumberConfirmed") - .HasColumnType("boolean"); - - b.Property("SecurityStamp") - .HasColumnType("text"); - - b.Property("Theme") - .ValueGeneratedOnAdd() - .HasMaxLength(20) - .HasColumnType("character varying(20)") - .HasDefaultValue("Auto"); - - b.Property("TwoFactorEnabled") - .HasColumnType("boolean"); - - b.Property("UserName") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.HasKey("Id"); - - b.HasIndex("NormalizedEmail") - .HasDatabaseName("EmailIndex"); - - b.HasIndex("NormalizedUserName") - .IsUnique() - .HasDatabaseName("UserNameIndex"); - - b.ToTable("users", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.AuditLog", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("Action") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("IpAddress") - .HasMaxLength(45) - .HasColumnType("character varying(45)"); - - b.Property("NewValue") - .HasColumnType("text"); - - b.Property("OldValue") - .HasColumnType("text"); - - b.Property("ResourceId") - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("ResourceType") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("Timestamp") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.Property("UserId") - .HasColumnType("uuid"); - - b.HasKey("Id"); - - b.HasIndex("Timestamp") - .IsDescending(); - - b.HasIndex("UserId"); - - b.HasIndex("ResourceType", "ResourceId", "Timestamp") - .IsDescending(false, false, true); - - b.ToTable("audit_logs", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.Camera", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("AgentId") - .HasColumnType("uuid"); - - b.Property("CreatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.Property("DeletedAt") - .HasColumnType("timestamp with time zone"); - - b.Property("HasAudio") - .HasColumnType("boolean"); - - b.Property("HasMotionDetection") - .HasColumnType("boolean"); - - b.Property("HasPtz") - .HasColumnType("boolean"); - - b.Property("IsDeleted") - .HasColumnType("boolean"); - - b.Property("Manufacturer") - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("Model") - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(200) - .HasColumnType("character varying(200)"); - - b.Property("RtspUrl") - .HasMaxLength(1000) - .HasColumnType("character varying(1000)"); - - b.Property("SiteId") - .HasColumnType("uuid"); - - b.Property("Status") - .IsRequired() - .HasMaxLength(20) - .HasColumnType("character varying(20)"); - - b.Property("UpdatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.HasKey("Id"); - - b.HasIndex("AgentId"); - - b.HasIndex("SiteId"); - - b.ToTable("cameras", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.CameraCredentials", b => - { - b.Property("CameraId") - .HasColumnType("uuid"); - - b.Property("CreatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.Property("OnvifPassword") - .IsRequired() - .HasMaxLength(500) - .HasColumnType("character varying(500)"); - - b.Property("OnvifUsername") - .IsRequired() - .ValueGeneratedOnAdd() - .HasMaxLength(100) - .HasColumnType("character varying(100)") - .HasDefaultValue("admin"); - - b.Property("RtspPassword") - .IsRequired() - .HasMaxLength(500) - .HasColumnType("character varying(500)"); - - b.Property("RtspUsername") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("UpdatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.HasKey("CameraId"); - - b.ToTable("camera_credentials", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.CameraDetectionProfile", b => - { - b.Property("CameraId") - .HasColumnType("uuid"); - - b.Property("ActiveIntervalMs") - .HasColumnType("integer"); - - b.Property("AnimalCooldownSec") - .HasColumnType("integer"); - - b.Property("DetectAnimal") - .HasColumnType("boolean"); - - b.Property("DetectMotion") - .HasColumnType("boolean"); - - b.Property("DetectPackage") - .HasColumnType("boolean"); - - b.Property("DetectPerson") - .HasColumnType("boolean"); - - b.Property("DetectVehicle") - .HasColumnType("boolean"); - - b.Property("FaceRecognition") - .HasColumnType("boolean"); - - b.Property("IdleIntervalMs") - .HasColumnType("integer"); - - b.Property("IoUThreshold") - .HasColumnType("double precision"); - - b.Property("LicensePlateRecognition") - .HasColumnType("boolean"); - - b.Property("MaxEventsPerMinute") - .HasColumnType("integer"); - - b.Property("MinConfidence") - .ValueGeneratedOnAdd() - .HasColumnType("double precision") - .HasDefaultValue(0.40000000000000002); - - b.Property("MotionIntervalMs") - .HasColumnType("integer"); - - b.Property("MotionThreshold") - .HasColumnType("double precision"); - - b.Property("PersonCooldownSec") - .HasColumnType("integer"); - - b.Property("RequireMotionForAI") - .HasColumnType("boolean"); - - b.Property("VehicleCooldownSec") - .HasColumnType("integer"); - - b.Property("YoloModel") - .IsRequired() - .ValueGeneratedOnAdd() - .HasMaxLength(50) - .HasColumnType("character varying(50)") - .HasDefaultValue("yolov8n"); - - b.HasKey("CameraId"); - - b.ToTable("camera_detection_profiles", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.Site", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("Address") - .HasMaxLength(500) - .HasColumnType("character varying(500)"); - - b.Property("CreatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.Property("DeletedAt") - .HasColumnType("timestamp with time zone"); - - b.Property("Enabled") - .HasColumnType("boolean"); - - b.Property("IsDeleted") - .HasColumnType("boolean"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(200) - .HasColumnType("character varying(200)"); - - b.Property("RegistrationTokenHash") - .HasMaxLength(128) - .HasColumnType("character varying(128)"); - - b.Property("Timezone") - .IsRequired() - .ValueGeneratedOnAdd() - .HasMaxLength(100) - .HasColumnType("character varying(100)") - .HasDefaultValue("UTC"); - - b.Property("TokenExpiresAt") - .HasColumnType("timestamp with time zone"); - - b.Property("UpdatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.HasKey("Id"); - - b.HasIndex("IsDeleted") - .HasFilter("\"IsDeleted\" = false"); - - b.HasIndex("Name"); - - b.ToTable("sites", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.UserSite", b => - { - b.Property("UserId") - .HasColumnType("uuid"); - - b.Property("SiteId") - .HasColumnType("uuid"); - - b.HasKey("UserId", "SiteId"); - - b.HasIndex("SiteId"); - - b.ToTable("user_sites", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("ClaimType") - .HasColumnType("text"); - - b.Property("ClaimValue") - .HasColumnType("text"); - - b.Property("RoleId") - .HasColumnType("uuid"); - - b.HasKey("Id"); - - b.HasIndex("RoleId"); - - b.ToTable("role_claims", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("ClaimType") - .HasColumnType("text"); - - b.Property("ClaimValue") - .HasColumnType("text"); - - b.Property("UserId") - .HasColumnType("uuid"); - - b.HasKey("Id"); - - b.HasIndex("UserId"); - - b.ToTable("user_claims", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => - { - b.Property("LoginProvider") - .HasColumnType("text"); - - b.Property("ProviderKey") - .HasColumnType("text"); - - b.Property("ProviderDisplayName") - .HasColumnType("text"); - - b.Property("UserId") - .HasColumnType("uuid"); - - b.HasKey("LoginProvider", "ProviderKey"); - - b.HasIndex("UserId"); - - b.ToTable("user_logins", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => - { - b.Property("UserId") - .HasColumnType("uuid"); - - b.Property("RoleId") - .HasColumnType("uuid"); - - b.HasKey("UserId", "RoleId"); - - b.HasIndex("RoleId"); - - b.ToTable("user_roles", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => - { - b.Property("UserId") - .HasColumnType("uuid"); - - b.Property("LoginProvider") - .HasColumnType("text"); - - b.Property("Name") - .HasColumnType("text"); - - b.Property("Value") - .HasColumnType("text"); - - b.HasKey("UserId", "LoginProvider", "Name"); - - b.ToTable("user_tokens", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.Agent", b => - { - b.HasOne("Heimdall.Domain.Entities.Site", "Site") - .WithMany("Agents") - .HasForeignKey("SiteId") - .OnDelete(DeleteBehavior.Restrict) - .IsRequired(); - - b.Navigation("Site"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.ApiKey", b => - { - b.HasOne("Heimdall.Domain.Entities.Site", "Site") - .WithMany() - .HasForeignKey("SiteId") - .OnDelete(DeleteBehavior.Restrict); - - b.Navigation("Site"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.Camera", b => - { - b.HasOne("Heimdall.Domain.Entities.Agent", "Agent") - .WithMany("Cameras") - .HasForeignKey("AgentId") - .OnDelete(DeleteBehavior.SetNull); - - b.HasOne("Heimdall.Domain.Entities.Site", "Site") - .WithMany("Cameras") - .HasForeignKey("SiteId") - .OnDelete(DeleteBehavior.Restrict) - .IsRequired(); - - b.Navigation("Agent"); - - b.Navigation("Site"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.CameraCredentials", b => - { - b.HasOne("Heimdall.Domain.Entities.Camera", "Camera") - .WithOne("Credentials") - .HasForeignKey("Heimdall.Domain.Entities.CameraCredentials", "CameraId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Camera"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.CameraDetectionProfile", b => - { - b.HasOne("Heimdall.Domain.Entities.Camera", "Camera") - .WithOne("DetectionProfile") - .HasForeignKey("Heimdall.Domain.Entities.CameraDetectionProfile", "CameraId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Camera"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.UserSite", b => - { - b.HasOne("Heimdall.Domain.Entities.Site", "Site") - .WithMany() - .HasForeignKey("SiteId") - .OnDelete(DeleteBehavior.Restrict) - .IsRequired(); - - b.HasOne("Heimdall.Domain.Entities.AppUser", "User") - .WithMany("UserSites") - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Site"); - - b.Navigation("User"); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => - { - b.HasOne("Heimdall.Domain.Entities.AppRole", null) - .WithMany() - .HasForeignKey("RoleId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => - { - b.HasOne("Heimdall.Domain.Entities.AppUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => - { - b.HasOne("Heimdall.Domain.Entities.AppUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => - { - b.HasOne("Heimdall.Domain.Entities.AppRole", null) - .WithMany() - .HasForeignKey("RoleId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("Heimdall.Domain.Entities.AppUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => - { - b.HasOne("Heimdall.Domain.Entities.AppUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.Agent", b => - { - b.Navigation("Cameras"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.AppUser", b => - { - b.Navigation("UserSites"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.Camera", b => - { - b.Navigation("Credentials"); - - b.Navigation("DetectionProfile"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.Site", b => - { - b.Navigation("Agents"); - - b.Navigation("Cameras"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/src/Heimdall.Infrastructure/Migrations/20260717192108_AddMustChangePassword.cs b/src/Heimdall.Infrastructure/Migrations/20260717192108_AddMustChangePassword.cs deleted file mode 100644 index cab52d8..0000000 --- a/src/Heimdall.Infrastructure/Migrations/20260717192108_AddMustChangePassword.cs +++ /dev/null @@ -1,29 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace Heimdall.Infrastructure.Migrations -{ - /// - public partial class AddMustChangePassword : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.AddColumn( - name: "MustChangePassword", - table: "users", - type: "boolean", - nullable: false, - defaultValue: false); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropColumn( - name: "MustChangePassword", - table: "users"); - } - } -} diff --git a/src/Heimdall.Infrastructure/Migrations/20260717192341_AddAuditLogUserRelation.Designer.cs b/src/Heimdall.Infrastructure/Migrations/20260717192341_AddAuditLogUserRelation.Designer.cs deleted file mode 100644 index 2147211..0000000 --- a/src/Heimdall.Infrastructure/Migrations/20260717192341_AddAuditLogUserRelation.Designer.cs +++ /dev/null @@ -1,856 +0,0 @@ -// -using System; -using Heimdall.Infrastructure.Data; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; - -#nullable disable - -namespace Heimdall.Infrastructure.Migrations -{ - [DbContext(typeof(AppDbContext))] - [Migration("20260717192341_AddAuditLogUserRelation")] - partial class AddAuditLogUserRelation - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "10.0.8") - .HasAnnotation("Relational:MaxIdentifierLength", 63); - - NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); - - modelBuilder.Entity("Heimdall.Domain.Entities.Agent", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("ApiKeyHash") - .HasMaxLength(128) - .HasColumnType("character varying(128)"); - - b.Property("ApiKeyPrefix") - .HasMaxLength(8) - .HasColumnType("character varying(8)"); - - b.Property("CpuCores") - .HasColumnType("integer"); - - b.Property("CreatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.Property("DeletedAt") - .HasColumnType("timestamp with time zone"); - - b.Property("GpuType") - .IsRequired() - .HasMaxLength(20) - .HasColumnType("character varying(20)"); - - b.Property("HasGpu") - .HasColumnType("boolean"); - - b.Property("Hostname") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("character varying(255)"); - - b.Property("IsDeleted") - .HasColumnType("boolean"); - - b.Property("LastHeartbeat") - .HasColumnType("timestamp with time zone"); - - b.Property("MemoryMb") - .HasColumnType("bigint"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(200) - .HasColumnType("character varying(200)"); - - b.Property("PublicIp") - .HasMaxLength(45) - .HasColumnType("character varying(45)"); - - b.Property("SiteId") - .HasColumnType("uuid"); - - b.Property("Status") - .IsRequired() - .HasMaxLength(20) - .HasColumnType("character varying(20)"); - - b.Property("UpdatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.Property("Version") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("character varying(50)"); - - b.HasKey("Id"); - - b.HasIndex("LastHeartbeat") - .HasFilter("\"Status\" = 'Online'"); - - b.HasIndex("SiteId"); - - b.ToTable("agents", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.ApiKey", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("CreatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.Property("CreatedByUserId") - .HasColumnType("uuid"); - - b.Property("Enabled") - .HasColumnType("boolean"); - - b.Property("ExpiresAt") - .HasColumnType("timestamp with time zone"); - - b.Property("KeyHash") - .IsRequired() - .HasMaxLength(128) - .HasColumnType("character varying(128)"); - - b.Property("KeyPrefix") - .IsRequired() - .HasMaxLength(8) - .HasColumnType("character varying(8)"); - - b.Property("LastUsedAt") - .HasColumnType("timestamp with time zone"); - - b.Property("SiteId") - .HasColumnType("uuid"); - - b.HasKey("Id"); - - b.HasIndex("KeyHash"); - - b.HasIndex("KeyPrefix"); - - b.HasIndex("SiteId"); - - b.ToTable("api_keys", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.AppRole", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("ConcurrencyStamp") - .IsConcurrencyToken() - .HasColumnType("text"); - - b.Property("Name") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.Property("NormalizedName") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.HasKey("Id"); - - b.HasIndex("NormalizedName") - .IsUnique() - .HasDatabaseName("RoleNameIndex"); - - b.ToTable("roles", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.AppUser", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("AccessFailedCount") - .HasColumnType("integer"); - - b.Property("ConcurrencyStamp") - .IsConcurrencyToken() - .HasColumnType("text"); - - b.Property("CreatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.Property("DisplayName") - .IsRequired() - .HasMaxLength(200) - .HasColumnType("character varying(200)"); - - b.Property("Email") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.Property("EmailConfirmed") - .HasColumnType("boolean"); - - b.Property("Language") - .IsRequired() - .ValueGeneratedOnAdd() - .HasMaxLength(10) - .HasColumnType("character varying(10)") - .HasDefaultValue("fr"); - - b.Property("LockoutEnabled") - .HasColumnType("boolean"); - - b.Property("LockoutEnd") - .HasColumnType("timestamp with time zone"); - - b.Property("MustChangePassword") - .ValueGeneratedOnAdd() - .HasColumnType("boolean") - .HasDefaultValue(false); - - b.Property("NormalizedEmail") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.Property("NormalizedUserName") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.Property("PasswordHash") - .HasColumnType("text"); - - b.Property("PhoneNumber") - .HasColumnType("text"); - - b.Property("PhoneNumberConfirmed") - .HasColumnType("boolean"); - - b.Property("SecurityStamp") - .HasColumnType("text"); - - b.Property("Theme") - .ValueGeneratedOnAdd() - .HasMaxLength(20) - .HasColumnType("character varying(20)") - .HasDefaultValue("Auto"); - - b.Property("TwoFactorEnabled") - .HasColumnType("boolean"); - - b.Property("UserName") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.HasKey("Id"); - - b.HasIndex("NormalizedEmail") - .HasDatabaseName("EmailIndex"); - - b.HasIndex("NormalizedUserName") - .IsUnique() - .HasDatabaseName("UserNameIndex"); - - b.ToTable("users", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.AuditLog", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("Action") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("IpAddress") - .HasMaxLength(45) - .HasColumnType("character varying(45)"); - - b.Property("NewValue") - .HasColumnType("text"); - - b.Property("OldValue") - .HasColumnType("text"); - - b.Property("ResourceId") - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("ResourceType") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("Timestamp") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.Property("UserId") - .HasColumnType("uuid"); - - b.HasKey("Id"); - - b.HasIndex("Timestamp") - .IsDescending(); - - b.HasIndex("UserId"); - - b.HasIndex("ResourceType", "ResourceId", "Timestamp") - .IsDescending(false, false, true); - - b.ToTable("audit_logs", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.Camera", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("AgentId") - .HasColumnType("uuid"); - - b.Property("CreatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.Property("DeletedAt") - .HasColumnType("timestamp with time zone"); - - b.Property("HasAudio") - .HasColumnType("boolean"); - - b.Property("HasMotionDetection") - .HasColumnType("boolean"); - - b.Property("HasPtz") - .HasColumnType("boolean"); - - b.Property("IsDeleted") - .HasColumnType("boolean"); - - b.Property("Manufacturer") - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("Model") - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(200) - .HasColumnType("character varying(200)"); - - b.Property("RtspUrl") - .HasMaxLength(1000) - .HasColumnType("character varying(1000)"); - - b.Property("SiteId") - .HasColumnType("uuid"); - - b.Property("Status") - .IsRequired() - .HasMaxLength(20) - .HasColumnType("character varying(20)"); - - b.Property("UpdatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.HasKey("Id"); - - b.HasIndex("AgentId"); - - b.HasIndex("SiteId"); - - b.ToTable("cameras", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.CameraCredentials", b => - { - b.Property("CameraId") - .HasColumnType("uuid"); - - b.Property("CreatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.Property("OnvifPassword") - .IsRequired() - .HasMaxLength(500) - .HasColumnType("character varying(500)"); - - b.Property("OnvifUsername") - .IsRequired() - .ValueGeneratedOnAdd() - .HasMaxLength(100) - .HasColumnType("character varying(100)") - .HasDefaultValue("admin"); - - b.Property("RtspPassword") - .IsRequired() - .HasMaxLength(500) - .HasColumnType("character varying(500)"); - - b.Property("RtspUsername") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("UpdatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.HasKey("CameraId"); - - b.ToTable("camera_credentials", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.CameraDetectionProfile", b => - { - b.Property("CameraId") - .HasColumnType("uuid"); - - b.Property("ActiveIntervalMs") - .HasColumnType("integer"); - - b.Property("AnimalCooldownSec") - .HasColumnType("integer"); - - b.Property("DetectAnimal") - .HasColumnType("boolean"); - - b.Property("DetectMotion") - .HasColumnType("boolean"); - - b.Property("DetectPackage") - .HasColumnType("boolean"); - - b.Property("DetectPerson") - .HasColumnType("boolean"); - - b.Property("DetectVehicle") - .HasColumnType("boolean"); - - b.Property("FaceRecognition") - .HasColumnType("boolean"); - - b.Property("IdleIntervalMs") - .HasColumnType("integer"); - - b.Property("IoUThreshold") - .HasColumnType("double precision"); - - b.Property("LicensePlateRecognition") - .HasColumnType("boolean"); - - b.Property("MaxEventsPerMinute") - .HasColumnType("integer"); - - b.Property("MinConfidence") - .ValueGeneratedOnAdd() - .HasColumnType("double precision") - .HasDefaultValue(0.40000000000000002); - - b.Property("MotionIntervalMs") - .HasColumnType("integer"); - - b.Property("MotionThreshold") - .HasColumnType("double precision"); - - b.Property("PersonCooldownSec") - .HasColumnType("integer"); - - b.Property("RequireMotionForAI") - .HasColumnType("boolean"); - - b.Property("VehicleCooldownSec") - .HasColumnType("integer"); - - b.Property("YoloModel") - .IsRequired() - .ValueGeneratedOnAdd() - .HasMaxLength(50) - .HasColumnType("character varying(50)") - .HasDefaultValue("yolov8n"); - - b.HasKey("CameraId"); - - b.ToTable("camera_detection_profiles", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.Site", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("Address") - .HasMaxLength(500) - .HasColumnType("character varying(500)"); - - b.Property("CreatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.Property("DeletedAt") - .HasColumnType("timestamp with time zone"); - - b.Property("Enabled") - .HasColumnType("boolean"); - - b.Property("IsDeleted") - .HasColumnType("boolean"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(200) - .HasColumnType("character varying(200)"); - - b.Property("RegistrationTokenHash") - .HasMaxLength(128) - .HasColumnType("character varying(128)"); - - b.Property("Timezone") - .IsRequired() - .ValueGeneratedOnAdd() - .HasMaxLength(100) - .HasColumnType("character varying(100)") - .HasDefaultValue("UTC"); - - b.Property("TokenExpiresAt") - .HasColumnType("timestamp with time zone"); - - b.Property("UpdatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.HasKey("Id"); - - b.HasIndex("IsDeleted") - .HasFilter("\"IsDeleted\" = false"); - - b.HasIndex("Name"); - - b.ToTable("sites", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.UserSite", b => - { - b.Property("UserId") - .HasColumnType("uuid"); - - b.Property("SiteId") - .HasColumnType("uuid"); - - b.HasKey("UserId", "SiteId"); - - b.HasIndex("SiteId"); - - b.ToTable("user_sites", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("ClaimType") - .HasColumnType("text"); - - b.Property("ClaimValue") - .HasColumnType("text"); - - b.Property("RoleId") - .HasColumnType("uuid"); - - b.HasKey("Id"); - - b.HasIndex("RoleId"); - - b.ToTable("role_claims", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("ClaimType") - .HasColumnType("text"); - - b.Property("ClaimValue") - .HasColumnType("text"); - - b.Property("UserId") - .HasColumnType("uuid"); - - b.HasKey("Id"); - - b.HasIndex("UserId"); - - b.ToTable("user_claims", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => - { - b.Property("LoginProvider") - .HasColumnType("text"); - - b.Property("ProviderKey") - .HasColumnType("text"); - - b.Property("ProviderDisplayName") - .HasColumnType("text"); - - b.Property("UserId") - .HasColumnType("uuid"); - - b.HasKey("LoginProvider", "ProviderKey"); - - b.HasIndex("UserId"); - - b.ToTable("user_logins", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => - { - b.Property("UserId") - .HasColumnType("uuid"); - - b.Property("RoleId") - .HasColumnType("uuid"); - - b.HasKey("UserId", "RoleId"); - - b.HasIndex("RoleId"); - - b.ToTable("user_roles", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => - { - b.Property("UserId") - .HasColumnType("uuid"); - - b.Property("LoginProvider") - .HasColumnType("text"); - - b.Property("Name") - .HasColumnType("text"); - - b.Property("Value") - .HasColumnType("text"); - - b.HasKey("UserId", "LoginProvider", "Name"); - - b.ToTable("user_tokens", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.Agent", b => - { - b.HasOne("Heimdall.Domain.Entities.Site", "Site") - .WithMany("Agents") - .HasForeignKey("SiteId") - .OnDelete(DeleteBehavior.Restrict) - .IsRequired(); - - b.Navigation("Site"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.ApiKey", b => - { - b.HasOne("Heimdall.Domain.Entities.Site", "Site") - .WithMany() - .HasForeignKey("SiteId") - .OnDelete(DeleteBehavior.Restrict); - - b.Navigation("Site"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.AuditLog", b => - { - b.HasOne("Heimdall.Domain.Entities.AppUser", "User") - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.SetNull); - - b.Navigation("User"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.Camera", b => - { - b.HasOne("Heimdall.Domain.Entities.Agent", "Agent") - .WithMany("Cameras") - .HasForeignKey("AgentId") - .OnDelete(DeleteBehavior.SetNull); - - b.HasOne("Heimdall.Domain.Entities.Site", "Site") - .WithMany("Cameras") - .HasForeignKey("SiteId") - .OnDelete(DeleteBehavior.Restrict) - .IsRequired(); - - b.Navigation("Agent"); - - b.Navigation("Site"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.CameraCredentials", b => - { - b.HasOne("Heimdall.Domain.Entities.Camera", "Camera") - .WithOne("Credentials") - .HasForeignKey("Heimdall.Domain.Entities.CameraCredentials", "CameraId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Camera"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.CameraDetectionProfile", b => - { - b.HasOne("Heimdall.Domain.Entities.Camera", "Camera") - .WithOne("DetectionProfile") - .HasForeignKey("Heimdall.Domain.Entities.CameraDetectionProfile", "CameraId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Camera"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.UserSite", b => - { - b.HasOne("Heimdall.Domain.Entities.Site", "Site") - .WithMany() - .HasForeignKey("SiteId") - .OnDelete(DeleteBehavior.Restrict) - .IsRequired(); - - b.HasOne("Heimdall.Domain.Entities.AppUser", "User") - .WithMany("UserSites") - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Site"); - - b.Navigation("User"); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => - { - b.HasOne("Heimdall.Domain.Entities.AppRole", null) - .WithMany() - .HasForeignKey("RoleId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => - { - b.HasOne("Heimdall.Domain.Entities.AppUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => - { - b.HasOne("Heimdall.Domain.Entities.AppUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => - { - b.HasOne("Heimdall.Domain.Entities.AppRole", null) - .WithMany() - .HasForeignKey("RoleId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("Heimdall.Domain.Entities.AppUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => - { - b.HasOne("Heimdall.Domain.Entities.AppUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.Agent", b => - { - b.Navigation("Cameras"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.AppUser", b => - { - b.Navigation("UserSites"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.Camera", b => - { - b.Navigation("Credentials"); - - b.Navigation("DetectionProfile"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.Site", b => - { - b.Navigation("Agents"); - - b.Navigation("Cameras"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/src/Heimdall.Infrastructure/Migrations/20260717192341_AddAuditLogUserRelation.cs b/src/Heimdall.Infrastructure/Migrations/20260717192341_AddAuditLogUserRelation.cs deleted file mode 100644 index 24a218b..0000000 --- a/src/Heimdall.Infrastructure/Migrations/20260717192341_AddAuditLogUserRelation.cs +++ /dev/null @@ -1,30 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace Heimdall.Infrastructure.Migrations -{ - /// - public partial class AddAuditLogUserRelation : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.AddForeignKey( - name: "FK_audit_logs_users_UserId", - table: "audit_logs", - column: "UserId", - principalTable: "users", - principalColumn: "Id", - onDelete: ReferentialAction.SetNull); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropForeignKey( - name: "FK_audit_logs_users_UserId", - table: "audit_logs"); - } - } -} diff --git a/src/Heimdall.Infrastructure/Migrations/20260718143003_AddAppSettings.Designer.cs b/src/Heimdall.Infrastructure/Migrations/20260718143003_AddAppSettings.Designer.cs deleted file mode 100644 index 507b105..0000000 --- a/src/Heimdall.Infrastructure/Migrations/20260718143003_AddAppSettings.Designer.cs +++ /dev/null @@ -1,985 +0,0 @@ -// -using System; -using Heimdall.Infrastructure.Data; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; - -#nullable disable - -namespace Heimdall.Infrastructure.Migrations -{ - [DbContext(typeof(AppDbContext))] - [Migration("20260718143003_AddAppSettings")] - partial class AddAppSettings - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "10.0.8") - .HasAnnotation("Relational:MaxIdentifierLength", 63); - - NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); - - modelBuilder.Entity("Heimdall.Domain.Entities.Agent", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("ApiKeyHash") - .HasMaxLength(128) - .IsUnicode(false) - .HasColumnType("character varying(128)"); - - b.Property("ApiKeyPrefix") - .HasMaxLength(8) - .IsUnicode(false) - .HasColumnType("character varying(8)"); - - b.Property("CpuCores") - .HasColumnType("integer"); - - b.Property("CreatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.Property("DeletedAt") - .HasColumnType("timestamp with time zone"); - - b.Property("GpuType") - .IsRequired() - .HasMaxLength(20) - .IsUnicode(false) - .HasColumnType("character varying(20)"); - - b.Property("HasGpu") - .HasColumnType("boolean"); - - b.Property("Hostname") - .IsRequired() - .HasMaxLength(255) - .IsUnicode(false) - .HasColumnType("character varying(255)"); - - b.Property("IsDeleted") - .HasColumnType("boolean"); - - b.Property("LastHeartbeat") - .HasColumnType("timestamp with time zone"); - - b.Property("MemoryMb") - .HasColumnType("bigint"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(200) - .IsUnicode(false) - .HasColumnType("character varying(200)"); - - b.Property("PublicIp") - .HasMaxLength(45) - .IsUnicode(false) - .HasColumnType("character varying(45)"); - - b.Property("SiteId") - .HasColumnType("uuid"); - - b.Property("Status") - .IsRequired() - .HasMaxLength(20) - .IsUnicode(false) - .HasColumnType("character varying(20)"); - - b.Property("UpdatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.Property("Version") - .IsRequired() - .HasMaxLength(50) - .IsUnicode(false) - .HasColumnType("character varying(50)"); - - b.HasKey("Id"); - - b.HasIndex("LastHeartbeat") - .HasFilter("\"Status\" = 'Online'"); - - b.HasIndex("SiteId"); - - b.ToTable("agents", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.AgentSetting", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("AgentId") - .HasColumnType("uuid") - .HasColumnName("agent_id"); - - b.Property("CreatedAt") - .HasColumnType("timestamp with time zone") - .HasColumnName("created_at"); - - b.Property("Key") - .IsRequired() - .HasMaxLength(200) - .HasColumnType("character varying(200)") - .HasColumnName("key"); - - b.Property("UpdatedAt") - .HasColumnType("timestamp with time zone") - .HasColumnName("updated_at"); - - b.Property("Value") - .IsRequired() - .HasColumnType("text") - .HasColumnName("value"); - - b.HasKey("Id"); - - b.HasIndex("AgentId", "Key") - .IsUnique(); - - b.ToTable("agent_settings", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.ApiKey", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("CreatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.Property("CreatedByUserId") - .HasColumnType("uuid"); - - b.Property("Enabled") - .HasColumnType("boolean"); - - b.Property("ExpiresAt") - .HasColumnType("timestamp with time zone"); - - b.Property("KeyHash") - .IsRequired() - .HasMaxLength(128) - .IsUnicode(false) - .HasColumnType("character varying(128)"); - - b.Property("KeyPrefix") - .IsRequired() - .HasMaxLength(8) - .IsUnicode(false) - .HasColumnType("character varying(8)"); - - b.Property("LastUsedAt") - .HasColumnType("timestamp with time zone"); - - b.Property("SiteId") - .HasColumnType("uuid"); - - b.HasKey("Id"); - - b.HasIndex("KeyHash"); - - b.HasIndex("KeyPrefix"); - - b.HasIndex("SiteId"); - - b.ToTable("api_keys", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.AppRole", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("ConcurrencyStamp") - .IsConcurrencyToken() - .HasColumnType("text"); - - b.Property("Name") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.Property("NormalizedName") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.HasKey("Id"); - - b.HasIndex("NormalizedName") - .IsUnique() - .HasDatabaseName("RoleNameIndex"); - - b.ToTable("roles", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.AppSetting", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("AllowedValues") - .HasMaxLength(2000) - .HasColumnType("character varying(2000)") - .HasColumnName("allowed_values"); - - b.Property("Category") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("character varying(100)") - .HasColumnName("category"); - - b.Property("CreatedAt") - .HasColumnType("timestamp with time zone") - .HasColumnName("created_at"); - - b.Property("Description") - .HasMaxLength(500) - .HasColumnType("character varying(500)") - .HasColumnName("description"); - - b.Property("Key") - .IsRequired() - .HasMaxLength(200) - .HasColumnType("character varying(200)") - .HasColumnName("key"); - - b.Property("UpdatedAt") - .HasColumnType("timestamp with time zone") - .HasColumnName("updated_at"); - - b.Property("Value") - .IsRequired() - .HasColumnType("text") - .HasColumnName("value"); - - b.Property("ValueType") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("character varying(50)") - .HasColumnName("value_type"); - - b.HasKey("Id"); - - b.HasIndex("Key") - .IsUnique(); - - b.ToTable("app_settings", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.AppUser", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("AccessFailedCount") - .HasColumnType("integer"); - - b.Property("ConcurrencyStamp") - .IsConcurrencyToken() - .HasColumnType("text"); - - b.Property("CreatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.Property("DisplayName") - .IsRequired() - .HasMaxLength(200) - .HasColumnType("character varying(200)"); - - b.Property("Email") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.Property("EmailConfirmed") - .HasColumnType("boolean"); - - b.Property("Language") - .IsRequired() - .ValueGeneratedOnAdd() - .HasMaxLength(10) - .IsUnicode(false) - .HasColumnType("character varying(10)") - .HasDefaultValue("fr"); - - b.Property("LockoutEnabled") - .HasColumnType("boolean"); - - b.Property("LockoutEnd") - .HasColumnType("timestamp with time zone"); - - b.Property("MustChangePassword") - .ValueGeneratedOnAdd() - .HasColumnType("boolean") - .HasDefaultValue(false); - - b.Property("NormalizedEmail") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.Property("NormalizedUserName") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.Property("PasswordHash") - .HasColumnType("text"); - - b.Property("PhoneNumber") - .HasColumnType("text"); - - b.Property("PhoneNumberConfirmed") - .HasColumnType("boolean"); - - b.Property("SecurityStamp") - .HasColumnType("text"); - - b.Property("Theme") - .ValueGeneratedOnAdd() - .HasMaxLength(20) - .IsUnicode(false) - .HasColumnType("character varying(20)") - .HasDefaultValue("Auto"); - - b.Property("TwoFactorEnabled") - .HasColumnType("boolean"); - - b.Property("UserName") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.HasKey("Id"); - - b.HasIndex("NormalizedEmail") - .HasDatabaseName("EmailIndex"); - - b.HasIndex("NormalizedUserName") - .IsUnique() - .HasDatabaseName("UserNameIndex"); - - b.ToTable("users", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.AuditLog", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("Action") - .IsRequired() - .HasMaxLength(100) - .IsUnicode(false) - .HasColumnType("character varying(100)"); - - b.Property("IpAddress") - .HasMaxLength(45) - .IsUnicode(false) - .HasColumnType("character varying(45)"); - - b.Property("NewValue") - .HasColumnType("text"); - - b.Property("OldValue") - .HasColumnType("text"); - - b.Property("ResourceId") - .HasMaxLength(100) - .IsUnicode(false) - .HasColumnType("character varying(100)"); - - b.Property("ResourceType") - .IsRequired() - .HasMaxLength(100) - .IsUnicode(false) - .HasColumnType("character varying(100)"); - - b.Property("Timestamp") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.Property("UserId") - .HasColumnType("uuid"); - - b.HasKey("Id"); - - b.HasIndex("Timestamp") - .IsDescending(); - - b.HasIndex("UserId"); - - b.HasIndex("ResourceType", "ResourceId", "Timestamp") - .IsDescending(false, false, true); - - b.ToTable("audit_logs", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.Camera", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("AgentId") - .HasColumnType("uuid"); - - b.Property("CreatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.Property("DeletedAt") - .HasColumnType("timestamp with time zone"); - - b.Property("HasAudio") - .HasColumnType("boolean"); - - b.Property("HasMotionDetection") - .HasColumnType("boolean"); - - b.Property("HasPtz") - .HasColumnType("boolean"); - - b.Property("IsDeleted") - .HasColumnType("boolean"); - - b.Property("Manufacturer") - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("Model") - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(200) - .IsUnicode(false) - .HasColumnType("character varying(200)"); - - b.Property("RtspUrl") - .HasMaxLength(1000) - .IsUnicode(false) - .HasColumnType("character varying(1000)"); - - b.Property("SiteId") - .HasColumnType("uuid"); - - b.Property("Status") - .IsRequired() - .HasMaxLength(20) - .IsUnicode(false) - .HasColumnType("character varying(20)"); - - b.Property("UpdatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.HasKey("Id"); - - b.HasIndex("AgentId"); - - b.HasIndex("SiteId"); - - b.ToTable("cameras", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.CameraCredentials", b => - { - b.Property("CameraId") - .HasColumnType("uuid"); - - b.Property("CreatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.Property("OnvifPassword") - .IsRequired() - .HasMaxLength(500) - .IsUnicode(false) - .HasColumnType("character varying(500)"); - - b.Property("OnvifUsername") - .IsRequired() - .ValueGeneratedOnAdd() - .HasMaxLength(100) - .IsUnicode(false) - .HasColumnType("character varying(100)") - .HasDefaultValue("admin"); - - b.Property("RtspPassword") - .IsRequired() - .HasMaxLength(500) - .IsUnicode(false) - .HasColumnType("character varying(500)"); - - b.Property("RtspUsername") - .IsRequired() - .HasMaxLength(100) - .IsUnicode(false) - .HasColumnType("character varying(100)"); - - b.Property("UpdatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.HasKey("CameraId"); - - b.ToTable("camera_credentials", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.CameraDetectionProfile", b => - { - b.Property("CameraId") - .HasColumnType("uuid"); - - b.Property("ActiveIntervalMs") - .HasColumnType("integer"); - - b.Property("AnimalCooldownSec") - .HasColumnType("integer"); - - b.Property("DetectAnimal") - .HasColumnType("boolean"); - - b.Property("DetectMotion") - .HasColumnType("boolean"); - - b.Property("DetectPackage") - .HasColumnType("boolean"); - - b.Property("DetectPerson") - .HasColumnType("boolean"); - - b.Property("DetectVehicle") - .HasColumnType("boolean"); - - b.Property("FaceRecognition") - .HasColumnType("boolean"); - - b.Property("IdleIntervalMs") - .HasColumnType("integer"); - - b.Property("IoUThreshold") - .HasColumnType("double precision"); - - b.Property("LicensePlateRecognition") - .HasColumnType("boolean"); - - b.Property("MaxEventsPerMinute") - .HasColumnType("integer"); - - b.Property("MinConfidence") - .ValueGeneratedOnAdd() - .HasColumnType("double precision") - .HasDefaultValue(0.40000000000000002); - - b.Property("MotionIntervalMs") - .HasColumnType("integer"); - - b.Property("MotionThreshold") - .HasColumnType("double precision"); - - b.Property("PersonCooldownSec") - .HasColumnType("integer"); - - b.Property("RequireMotionForAI") - .HasColumnType("boolean"); - - b.Property("VehicleCooldownSec") - .HasColumnType("integer"); - - b.Property("YoloModel") - .IsRequired() - .ValueGeneratedOnAdd() - .HasMaxLength(50) - .IsUnicode(false) - .HasColumnType("character varying(50)") - .HasDefaultValue("yolov8n"); - - b.HasKey("CameraId"); - - b.ToTable("camera_detection_profiles", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.Site", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("Address") - .HasMaxLength(500) - .HasColumnType("character varying(500)"); - - b.Property("CreatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.Property("DeletedAt") - .HasColumnType("timestamp with time zone"); - - b.Property("Enabled") - .HasColumnType("boolean"); - - b.Property("IsDeleted") - .HasColumnType("boolean"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(200) - .HasColumnType("character varying(200)"); - - b.Property("RegistrationTokenHash") - .HasMaxLength(128) - .IsUnicode(false) - .HasColumnType("character varying(128)"); - - b.Property("Timezone") - .IsRequired() - .ValueGeneratedOnAdd() - .HasMaxLength(100) - .IsUnicode(false) - .HasColumnType("character varying(100)") - .HasDefaultValue("UTC"); - - b.Property("TokenExpiresAt") - .HasColumnType("timestamp with time zone"); - - b.Property("UpdatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.HasKey("Id"); - - b.HasIndex("IsDeleted") - .HasFilter("\"IsDeleted\" = false"); - - b.HasIndex("Name"); - - b.ToTable("sites", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.UserSite", b => - { - b.Property("UserId") - .HasColumnType("uuid"); - - b.Property("SiteId") - .HasColumnType("uuid"); - - b.HasKey("UserId", "SiteId"); - - b.HasIndex("SiteId"); - - b.ToTable("user_sites", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("ClaimType") - .HasColumnType("text"); - - b.Property("ClaimValue") - .HasColumnType("text"); - - b.Property("RoleId") - .HasColumnType("uuid"); - - b.HasKey("Id"); - - b.HasIndex("RoleId"); - - b.ToTable("role_claims", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("ClaimType") - .HasColumnType("text"); - - b.Property("ClaimValue") - .HasColumnType("text"); - - b.Property("UserId") - .HasColumnType("uuid"); - - b.HasKey("Id"); - - b.HasIndex("UserId"); - - b.ToTable("user_claims", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => - { - b.Property("LoginProvider") - .HasColumnType("text"); - - b.Property("ProviderKey") - .HasColumnType("text"); - - b.Property("ProviderDisplayName") - .HasColumnType("text"); - - b.Property("UserId") - .HasColumnType("uuid"); - - b.HasKey("LoginProvider", "ProviderKey"); - - b.HasIndex("UserId"); - - b.ToTable("user_logins", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => - { - b.Property("UserId") - .HasColumnType("uuid"); - - b.Property("RoleId") - .HasColumnType("uuid"); - - b.HasKey("UserId", "RoleId"); - - b.HasIndex("RoleId"); - - b.ToTable("user_roles", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => - { - b.Property("UserId") - .HasColumnType("uuid"); - - b.Property("LoginProvider") - .HasColumnType("text"); - - b.Property("Name") - .HasColumnType("text"); - - b.Property("Value") - .HasColumnType("text"); - - b.HasKey("UserId", "LoginProvider", "Name"); - - b.ToTable("user_tokens", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.Agent", b => - { - b.HasOne("Heimdall.Domain.Entities.Site", "Site") - .WithMany("Agents") - .HasForeignKey("SiteId") - .OnDelete(DeleteBehavior.Restrict) - .IsRequired(); - - b.Navigation("Site"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.AgentSetting", b => - { - b.HasOne("Heimdall.Domain.Entities.Agent", "Agent") - .WithMany() - .HasForeignKey("AgentId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Agent"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.ApiKey", b => - { - b.HasOne("Heimdall.Domain.Entities.Site", "Site") - .WithMany() - .HasForeignKey("SiteId") - .OnDelete(DeleteBehavior.Restrict); - - b.Navigation("Site"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.AuditLog", b => - { - b.HasOne("Heimdall.Domain.Entities.AppUser", "User") - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.SetNull); - - b.Navigation("User"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.Camera", b => - { - b.HasOne("Heimdall.Domain.Entities.Agent", "Agent") - .WithMany("Cameras") - .HasForeignKey("AgentId") - .OnDelete(DeleteBehavior.SetNull); - - b.HasOne("Heimdall.Domain.Entities.Site", "Site") - .WithMany("Cameras") - .HasForeignKey("SiteId") - .OnDelete(DeleteBehavior.Restrict) - .IsRequired(); - - b.Navigation("Agent"); - - b.Navigation("Site"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.CameraCredentials", b => - { - b.HasOne("Heimdall.Domain.Entities.Camera", "Camera") - .WithOne("Credentials") - .HasForeignKey("Heimdall.Domain.Entities.CameraCredentials", "CameraId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Camera"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.CameraDetectionProfile", b => - { - b.HasOne("Heimdall.Domain.Entities.Camera", "Camera") - .WithOne("DetectionProfile") - .HasForeignKey("Heimdall.Domain.Entities.CameraDetectionProfile", "CameraId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Camera"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.UserSite", b => - { - b.HasOne("Heimdall.Domain.Entities.Site", "Site") - .WithMany() - .HasForeignKey("SiteId") - .OnDelete(DeleteBehavior.Restrict) - .IsRequired(); - - b.HasOne("Heimdall.Domain.Entities.AppUser", "User") - .WithMany("UserSites") - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Site"); - - b.Navigation("User"); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => - { - b.HasOne("Heimdall.Domain.Entities.AppRole", null) - .WithMany() - .HasForeignKey("RoleId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => - { - b.HasOne("Heimdall.Domain.Entities.AppUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => - { - b.HasOne("Heimdall.Domain.Entities.AppUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => - { - b.HasOne("Heimdall.Domain.Entities.AppRole", null) - .WithMany() - .HasForeignKey("RoleId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("Heimdall.Domain.Entities.AppUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => - { - b.HasOne("Heimdall.Domain.Entities.AppUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.Agent", b => - { - b.Navigation("Cameras"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.AppUser", b => - { - b.Navigation("UserSites"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.Camera", b => - { - b.Navigation("Credentials"); - - b.Navigation("DetectionProfile"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.Site", b => - { - b.Navigation("Agents"); - - b.Navigation("Cameras"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/src/Heimdall.Infrastructure/Migrations/20260718143003_AddAppSettings.cs b/src/Heimdall.Infrastructure/Migrations/20260718143003_AddAppSettings.cs deleted file mode 100644 index 965669d..0000000 --- a/src/Heimdall.Infrastructure/Migrations/20260718143003_AddAppSettings.cs +++ /dev/null @@ -1,78 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace Heimdall.Infrastructure.Migrations -{ - /// - public partial class AddAppSettings : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "agent_settings", - columns: table => new - { - Id = table.Column(type: "uuid", nullable: false), - agent_id = table.Column(type: "uuid", nullable: false), - key = table.Column(type: "character varying(200)", maxLength: 200, nullable: false), - value = table.Column(type: "text", nullable: false), - created_at = table.Column(type: "timestamp with time zone", nullable: false), - updated_at = table.Column(type: "timestamp with time zone", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_agent_settings", x => x.Id); - table.ForeignKey( - name: "FK_agent_settings_agents_agent_id", - column: x => x.agent_id, - principalTable: "agents", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "app_settings", - columns: table => new - { - Id = table.Column(type: "uuid", nullable: false), - key = table.Column(type: "character varying(200)", maxLength: 200, nullable: false), - value = table.Column(type: "text", nullable: false), - description = table.Column(type: "character varying(500)", maxLength: 500, nullable: true), - category = table.Column(type: "character varying(100)", maxLength: 100, nullable: false), - value_type = table.Column(type: "character varying(50)", maxLength: 50, nullable: false), - allowed_values = table.Column(type: "character varying(2000)", maxLength: 2000, nullable: true), - created_at = table.Column(type: "timestamp with time zone", nullable: false), - updated_at = table.Column(type: "timestamp with time zone", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_app_settings", x => x.Id); - }); - - migrationBuilder.CreateIndex( - name: "IX_agent_settings_agent_id_key", - table: "agent_settings", - columns: new[] { "agent_id", "key" }, - unique: true); - - migrationBuilder.CreateIndex( - name: "IX_app_settings_key", - table: "app_settings", - column: "key", - unique: true); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "agent_settings"); - - migrationBuilder.DropTable( - name: "app_settings"); - } - } -} diff --git a/src/Heimdall.Infrastructure/Migrations/20260719064824_AddGroups.Designer.cs b/src/Heimdall.Infrastructure/Migrations/20260719064824_AddGroups.Designer.cs deleted file mode 100644 index ddb2dbf..0000000 --- a/src/Heimdall.Infrastructure/Migrations/20260719064824_AddGroups.Designer.cs +++ /dev/null @@ -1,1326 +0,0 @@ -// -using System; -using Heimdall.Infrastructure.Data; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; - -#nullable disable - -namespace Heimdall.Infrastructure.Migrations -{ - [DbContext(typeof(AppDbContext))] - [Migration("20260719064824_AddGroups")] - partial class AddGroups - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "10.0.10") - .HasAnnotation("Relational:MaxIdentifierLength", 63); - - NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); - - modelBuilder.Entity("Heimdall.Domain.Entities.Agent", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("ApiKeyHash") - .HasMaxLength(128) - .IsUnicode(false) - .HasColumnType("character varying(128)"); - - b.Property("ApiKeyPrefix") - .HasMaxLength(8) - .IsUnicode(false) - .HasColumnType("character varying(8)"); - - b.Property("CpuCores") - .HasColumnType("integer"); - - b.Property("CreatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.Property("DeletedAt") - .HasColumnType("timestamp with time zone"); - - b.Property("GpuType") - .IsRequired() - .HasMaxLength(20) - .IsUnicode(false) - .HasColumnType("character varying(20)"); - - b.Property("HasGpu") - .HasColumnType("boolean"); - - b.Property("Hostname") - .IsRequired() - .HasMaxLength(255) - .IsUnicode(false) - .HasColumnType("character varying(255)"); - - b.Property("IsDeleted") - .HasColumnType("boolean"); - - b.Property("LastHeartbeat") - .HasColumnType("timestamp with time zone"); - - b.Property("MemoryMb") - .HasColumnType("bigint"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(200) - .IsUnicode(false) - .HasColumnType("character varying(200)"); - - b.Property("PublicIp") - .HasMaxLength(45) - .IsUnicode(false) - .HasColumnType("character varying(45)"); - - b.Property("SiteId") - .HasColumnType("uuid"); - - b.Property("Status") - .IsRequired() - .HasMaxLength(20) - .IsUnicode(false) - .HasColumnType("character varying(20)"); - - b.Property("UpdatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.Property("Version") - .IsRequired() - .HasMaxLength(50) - .IsUnicode(false) - .HasColumnType("character varying(50)"); - - b.HasKey("Id"); - - b.HasIndex("LastHeartbeat") - .HasFilter("\"Status\" = 'Online'"); - - b.HasIndex("SiteId"); - - b.ToTable("agents", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.AgentSetting", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("AgentId") - .HasColumnType("uuid") - .HasColumnName("agent_id"); - - b.Property("CreatedAt") - .HasColumnType("timestamp with time zone") - .HasColumnName("created_at"); - - b.Property("Key") - .IsRequired() - .HasMaxLength(200) - .HasColumnType("character varying(200)") - .HasColumnName("key"); - - b.Property("UpdatedAt") - .HasColumnType("timestamp with time zone") - .HasColumnName("updated_at"); - - b.Property("Value") - .IsRequired() - .HasColumnType("text") - .HasColumnName("value"); - - b.HasKey("Id"); - - b.HasIndex("AgentId", "Key") - .IsUnique(); - - b.ToTable("agent_settings", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.ApiKey", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("CreatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.Property("CreatedByUserId") - .HasColumnType("uuid"); - - b.Property("Enabled") - .HasColumnType("boolean"); - - b.Property("ExpiresAt") - .HasColumnType("timestamp with time zone"); - - b.Property("KeyHash") - .IsRequired() - .HasMaxLength(128) - .IsUnicode(false) - .HasColumnType("character varying(128)"); - - b.Property("KeyPrefix") - .IsRequired() - .HasMaxLength(8) - .IsUnicode(false) - .HasColumnType("character varying(8)"); - - b.Property("LastUsedAt") - .HasColumnType("timestamp with time zone"); - - b.Property("SiteId") - .HasColumnType("uuid"); - - b.HasKey("Id"); - - b.HasIndex("KeyHash"); - - b.HasIndex("KeyPrefix"); - - b.HasIndex("SiteId"); - - b.ToTable("api_keys", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.AppRole", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("ConcurrencyStamp") - .IsConcurrencyToken() - .HasColumnType("text"); - - b.Property("Name") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.Property("NormalizedName") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.HasKey("Id"); - - b.HasIndex("NormalizedName") - .IsUnique() - .HasDatabaseName("RoleNameIndex"); - - b.ToTable("roles", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.AppSetting", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("AllowedValues") - .HasMaxLength(2000) - .HasColumnType("character varying(2000)") - .HasColumnName("allowed_values"); - - b.Property("Category") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("character varying(100)") - .HasColumnName("category"); - - b.Property("CreatedAt") - .HasColumnType("timestamp with time zone") - .HasColumnName("created_at"); - - b.Property("Description") - .HasMaxLength(500) - .HasColumnType("character varying(500)") - .HasColumnName("description"); - - b.Property("Key") - .IsRequired() - .HasMaxLength(200) - .HasColumnType("character varying(200)") - .HasColumnName("key"); - - b.Property("UpdatedAt") - .HasColumnType("timestamp with time zone") - .HasColumnName("updated_at"); - - b.Property("Value") - .IsRequired() - .HasColumnType("text") - .HasColumnName("value"); - - b.Property("ValueType") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("character varying(50)") - .HasColumnName("value_type"); - - b.HasKey("Id"); - - b.HasIndex("Key") - .IsUnique(); - - b.ToTable("app_settings", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.AppUser", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("AccessFailedCount") - .HasColumnType("integer"); - - b.Property("ConcurrencyStamp") - .IsConcurrencyToken() - .HasColumnType("text"); - - b.Property("CreatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.Property("DisplayName") - .IsRequired() - .HasMaxLength(200) - .HasColumnType("character varying(200)"); - - b.Property("Email") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.Property("EmailConfirmed") - .HasColumnType("boolean"); - - b.Property("Language") - .IsRequired() - .ValueGeneratedOnAdd() - .HasMaxLength(10) - .IsUnicode(false) - .HasColumnType("character varying(10)") - .HasDefaultValue("fr"); - - b.Property("LockoutEnabled") - .HasColumnType("boolean"); - - b.Property("LockoutEnd") - .HasColumnType("timestamp with time zone"); - - b.Property("MustChangePassword") - .ValueGeneratedOnAdd() - .HasColumnType("boolean") - .HasDefaultValue(false); - - b.Property("NormalizedEmail") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.Property("NormalizedUserName") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.Property("PasswordHash") - .HasColumnType("text"); - - b.Property("PhoneNumber") - .HasColumnType("text"); - - b.Property("PhoneNumberConfirmed") - .HasColumnType("boolean"); - - b.Property("SecurityStamp") - .HasColumnType("text"); - - b.Property("Theme") - .ValueGeneratedOnAdd() - .HasMaxLength(20) - .IsUnicode(false) - .HasColumnType("character varying(20)") - .HasDefaultValue("Auto"); - - b.Property("TwoFactorEnabled") - .HasColumnType("boolean"); - - b.Property("UserName") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.HasKey("Id"); - - b.HasIndex("NormalizedEmail") - .HasDatabaseName("EmailIndex"); - - b.HasIndex("NormalizedUserName") - .IsUnique() - .HasDatabaseName("UserNameIndex"); - - b.ToTable("users", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.AuditLog", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("Action") - .IsRequired() - .HasMaxLength(100) - .IsUnicode(false) - .HasColumnType("character varying(100)"); - - b.Property("IpAddress") - .HasMaxLength(45) - .IsUnicode(false) - .HasColumnType("character varying(45)"); - - b.Property("NewValue") - .HasColumnType("text"); - - b.Property("OldValue") - .HasColumnType("text"); - - b.Property("ResourceId") - .HasMaxLength(100) - .IsUnicode(false) - .HasColumnType("character varying(100)"); - - b.Property("ResourceType") - .IsRequired() - .HasMaxLength(100) - .IsUnicode(false) - .HasColumnType("character varying(100)"); - - b.Property("Timestamp") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.Property("UserId") - .HasColumnType("uuid"); - - b.HasKey("Id"); - - b.HasIndex("Timestamp") - .IsDescending(); - - b.HasIndex("UserId"); - - b.HasIndex("ResourceType", "ResourceId", "Timestamp") - .IsDescending(false, false, true); - - b.ToTable("audit_logs", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.Camera", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("AgentId") - .HasColumnType("uuid"); - - b.Property("Capabilities") - .IsRequired() - .HasMaxLength(64) - .IsUnicode(false) - .HasColumnType("character varying(64)"); - - b.Property("CreatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.Property("DeletedAt") - .HasColumnType("timestamp with time zone"); - - b.Property("DetectedType") - .IsRequired() - .HasMaxLength(20) - .IsUnicode(false) - .HasColumnType("character varying(20)"); - - b.Property("DiscoveryMethod") - .IsRequired() - .HasMaxLength(20) - .IsUnicode(false) - .HasColumnType("character varying(20)"); - - b.Property("HasAudio") - .HasColumnType("boolean"); - - b.Property("HasMotionDetection") - .HasColumnType("boolean"); - - b.Property("HasPtz") - .HasColumnType("boolean"); - - b.Property("HttpPort") - .HasColumnType("integer"); - - b.Property("IpAddress") - .HasMaxLength(45) - .HasColumnType("character varying(45)"); - - b.Property("IsDeleted") - .HasColumnType("boolean"); - - b.Property("LastDiscoveredAt") - .HasColumnType("timestamp with time zone"); - - b.Property("LastStreamTestAt") - .HasColumnType("timestamp with time zone"); - - b.Property("LastTestedCodecs") - .HasMaxLength(200) - .IsUnicode(false) - .HasColumnType("character varying(200)"); - - b.Property("LastTestedHeight") - .HasColumnType("integer"); - - b.Property("LastTestedLatencyMs") - .HasColumnType("bigint"); - - b.Property("LastTestedWidth") - .HasColumnType("integer"); - - b.Property("MacAddress") - .HasMaxLength(17) - .HasColumnType("character varying(17)"); - - b.Property("Manufacturer") - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("Model") - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(200) - .IsUnicode(false) - .HasColumnType("character varying(200)"); - - b.Property("OnvifPort") - .HasColumnType("integer"); - - b.Property("RtspPort") - .HasColumnType("integer"); - - b.Property("RtspUrl") - .HasMaxLength(1000) - .IsUnicode(false) - .HasColumnType("character varying(1000)"); - - b.Property("SiteId") - .HasColumnType("uuid"); - - b.Property("Status") - .IsRequired() - .HasMaxLength(20) - .IsUnicode(false) - .HasColumnType("character varying(20)"); - - b.Property("SubRtspUrl") - .HasMaxLength(1000) - .IsUnicode(false) - .HasColumnType("character varying(1000)"); - - b.Property("UpdatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.HasKey("Id"); - - b.HasIndex("AgentId"); - - b.HasIndex("IpAddress"); - - b.HasIndex("MacAddress"); - - b.HasIndex("SiteId"); - - b.ToTable("cameras", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.CameraCredentials", b => - { - b.Property("CameraId") - .HasColumnType("uuid"); - - b.Property("CreatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.Property("OnvifPassword") - .IsRequired() - .HasMaxLength(500) - .IsUnicode(false) - .HasColumnType("character varying(500)"); - - b.Property("OnvifUsername") - .IsRequired() - .ValueGeneratedOnAdd() - .HasMaxLength(100) - .IsUnicode(false) - .HasColumnType("character varying(100)") - .HasDefaultValue("admin"); - - b.Property("RtspPassword") - .IsRequired() - .HasMaxLength(500) - .IsUnicode(false) - .HasColumnType("character varying(500)"); - - b.Property("RtspUsername") - .IsRequired() - .HasMaxLength(100) - .IsUnicode(false) - .HasColumnType("character varying(100)"); - - b.Property("UpdatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.HasKey("CameraId"); - - b.ToTable("camera_credentials", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.CameraDetectionProfile", b => - { - b.Property("CameraId") - .HasColumnType("uuid"); - - b.Property("ActiveIntervalMs") - .HasColumnType("integer"); - - b.Property("AnimalCooldownSec") - .HasColumnType("integer"); - - b.Property("DetectAnimal") - .HasColumnType("boolean"); - - b.Property("DetectMotion") - .HasColumnType("boolean"); - - b.Property("DetectPackage") - .HasColumnType("boolean"); - - b.Property("DetectPerson") - .HasColumnType("boolean"); - - b.Property("DetectVehicle") - .HasColumnType("boolean"); - - b.Property("FaceRecognition") - .HasColumnType("boolean"); - - b.Property("IdleIntervalMs") - .HasColumnType("integer"); - - b.Property("IoUThreshold") - .HasColumnType("double precision"); - - b.Property("LicensePlateRecognition") - .HasColumnType("boolean"); - - b.Property("MaxEventsPerMinute") - .HasColumnType("integer"); - - b.Property("MinConfidence") - .ValueGeneratedOnAdd() - .HasColumnType("double precision") - .HasDefaultValue(0.40000000000000002); - - b.Property("MotionIntervalMs") - .HasColumnType("integer"); - - b.Property("MotionThreshold") - .HasColumnType("double precision"); - - b.Property("PersonCooldownSec") - .HasColumnType("integer"); - - b.Property("RequireMotionForAI") - .HasColumnType("boolean"); - - b.Property("VehicleCooldownSec") - .HasColumnType("integer"); - - b.Property("YoloModel") - .IsRequired() - .ValueGeneratedOnAdd() - .HasMaxLength(50) - .IsUnicode(false) - .HasColumnType("character varying(50)") - .HasDefaultValue("yolov8n"); - - b.HasKey("CameraId"); - - b.ToTable("camera_detection_profiles", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.CameraDiscoveryResult", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("DetectedType") - .IsRequired() - .HasMaxLength(20) - .IsUnicode(false) - .HasColumnType("character varying(20)"); - - b.Property("DiscoveryMethod") - .IsRequired() - .HasMaxLength(20) - .IsUnicode(false) - .HasColumnType("character varying(20)"); - - b.Property("HomeKitDeviceId") - .HasMaxLength(50) - .IsUnicode(false) - .HasColumnType("character varying(50)"); - - b.Property("HomeKitModel") - .HasMaxLength(200) - .IsUnicode(false) - .HasColumnType("character varying(200)"); - - b.Property("HomeKitName") - .HasMaxLength(200) - .IsUnicode(false) - .HasColumnType("character varying(200)"); - - b.Property("Hostname") - .HasMaxLength(255) - .IsUnicode(false) - .HasColumnType("character varying(255)"); - - b.Property("HttpPort") - .HasColumnType("integer"); - - b.Property("HttpServerHeader") - .HasMaxLength(200) - .IsUnicode(false) - .HasColumnType("character varying(200)"); - - b.Property("HttpStatusCode") - .HasColumnType("integer"); - - b.Property("IpAddress") - .IsRequired() - .HasMaxLength(45) - .IsUnicode(false) - .HasColumnType("character varying(45)"); - - b.Property("IsHomeKitCamera") - .HasColumnType("boolean"); - - b.Property("IsProcessed") - .HasColumnType("boolean"); - - b.Property("IsReachable") - .HasColumnType("boolean"); - - b.Property("MacAddress") - .HasMaxLength(17) - .IsUnicode(false) - .HasColumnType("character varying(17)"); - - b.Property("OnvifDeviceServiceUrl") - .HasMaxLength(500) - .IsUnicode(false) - .HasColumnType("character varying(500)"); - - b.Property("OnvifHardware") - .HasMaxLength(200) - .IsUnicode(false) - .HasColumnType("character varying(200)"); - - b.Property("OnvifName") - .HasMaxLength(200) - .IsUnicode(false) - .HasColumnType("character varying(200)"); - - b.Property("OnvifPort") - .HasColumnType("integer"); - - b.PrimitiveCollection("OpenPorts") - .IsRequired() - .IsUnicode(false) - .HasColumnType("integer[]"); - - b.Property("ProbedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.Property("SiteId") - .HasColumnType("uuid"); - - b.Property("Vendor") - .HasMaxLength(100) - .IsUnicode(false) - .HasColumnType("character varying(100)"); - - b.HasKey("Id"); - - b.HasIndex("IpAddress"); - - b.HasIndex("IsProcessed"); - - b.HasIndex("SiteId"); - - b.ToTable("camera_discovery_results", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.DiscoveredStreamUrl", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.PrimitiveCollection("Codecs") - .IsRequired() - .IsUnicode(false) - .HasColumnType("text[]"); - - b.Property("DiscoveryResultId") - .HasColumnType("uuid"); - - b.Property("Height") - .HasColumnType("integer"); - - b.Property("IsAlive") - .HasColumnType("boolean"); - - b.Property("IsMainStream") - .HasColumnType("boolean"); - - b.Property("LatencyMs") - .HasColumnType("bigint"); - - b.Property("Protocol") - .IsRequired() - .HasMaxLength(20) - .IsUnicode(false) - .HasColumnType("character varying(20)"); - - b.Property("Url") - .IsRequired() - .HasMaxLength(2000) - .IsUnicode(false) - .HasColumnType("character varying(2000)"); - - b.Property("Width") - .HasColumnType("integer"); - - b.HasKey("Id"); - - b.HasIndex("DiscoveryResultId"); - - b.HasIndex("IsAlive"); - - b.HasIndex("IsMainStream"); - - b.ToTable("discovered_streams", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.Group", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("CreatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.Property("DeletedAt") - .HasColumnType("timestamp with time zone"); - - b.Property("Description") - .HasMaxLength(1000) - .HasColumnType("character varying(1000)"); - - b.Property("IsDeleted") - .HasColumnType("boolean"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(200) - .HasColumnType("character varying(200)"); - - b.Property("UpdatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.HasKey("Id"); - - b.HasIndex("IsDeleted") - .HasFilter("\"IsDeleted\" = false"); - - b.HasIndex("Name"); - - b.ToTable("groups", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.Site", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("Address") - .HasMaxLength(500) - .HasColumnType("character varying(500)"); - - b.Property("CreatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.Property("DeletedAt") - .HasColumnType("timestamp with time zone"); - - b.Property("Enabled") - .HasColumnType("boolean"); - - b.Property("IsDeleted") - .HasColumnType("boolean"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(200) - .HasColumnType("character varying(200)"); - - b.Property("RegistrationTokenHash") - .HasMaxLength(128) - .IsUnicode(false) - .HasColumnType("character varying(128)"); - - b.Property("Timezone") - .IsRequired() - .ValueGeneratedOnAdd() - .HasMaxLength(100) - .IsUnicode(false) - .HasColumnType("character varying(100)") - .HasDefaultValue("UTC"); - - b.Property("TokenExpiresAt") - .HasColumnType("timestamp with time zone"); - - b.Property("UpdatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.HasKey("Id"); - - b.HasIndex("IsDeleted") - .HasFilter("\"IsDeleted\" = false"); - - b.HasIndex("Name"); - - b.ToTable("sites", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.UserGroup", b => - { - b.Property("UserId") - .HasColumnType("uuid"); - - b.Property("GroupId") - .HasColumnType("uuid"); - - b.HasKey("UserId", "GroupId"); - - b.HasIndex("GroupId"); - - b.ToTable("user_groups", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.UserSite", b => - { - b.Property("UserId") - .HasColumnType("uuid"); - - b.Property("SiteId") - .HasColumnType("uuid"); - - b.HasKey("UserId", "SiteId"); - - b.HasIndex("SiteId"); - - b.ToTable("user_sites", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("ClaimType") - .HasColumnType("text"); - - b.Property("ClaimValue") - .HasColumnType("text"); - - b.Property("RoleId") - .HasColumnType("uuid"); - - b.HasKey("Id"); - - b.HasIndex("RoleId"); - - b.ToTable("role_claims", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("ClaimType") - .HasColumnType("text"); - - b.Property("ClaimValue") - .HasColumnType("text"); - - b.Property("UserId") - .HasColumnType("uuid"); - - b.HasKey("Id"); - - b.HasIndex("UserId"); - - b.ToTable("user_claims", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => - { - b.Property("LoginProvider") - .HasColumnType("text"); - - b.Property("ProviderKey") - .HasColumnType("text"); - - b.Property("ProviderDisplayName") - .HasColumnType("text"); - - b.Property("UserId") - .HasColumnType("uuid"); - - b.HasKey("LoginProvider", "ProviderKey"); - - b.HasIndex("UserId"); - - b.ToTable("user_logins", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => - { - b.Property("UserId") - .HasColumnType("uuid"); - - b.Property("RoleId") - .HasColumnType("uuid"); - - b.HasKey("UserId", "RoleId"); - - b.HasIndex("RoleId"); - - b.ToTable("user_roles", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => - { - b.Property("UserId") - .HasColumnType("uuid"); - - b.Property("LoginProvider") - .HasColumnType("text"); - - b.Property("Name") - .HasColumnType("text"); - - b.Property("Value") - .HasColumnType("text"); - - b.HasKey("UserId", "LoginProvider", "Name"); - - b.ToTable("user_tokens", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.Agent", b => - { - b.HasOne("Heimdall.Domain.Entities.Site", "Site") - .WithMany("Agents") - .HasForeignKey("SiteId") - .OnDelete(DeleteBehavior.Restrict) - .IsRequired(); - - b.Navigation("Site"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.AgentSetting", b => - { - b.HasOne("Heimdall.Domain.Entities.Agent", "Agent") - .WithMany() - .HasForeignKey("AgentId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Agent"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.ApiKey", b => - { - b.HasOne("Heimdall.Domain.Entities.Site", "Site") - .WithMany() - .HasForeignKey("SiteId") - .OnDelete(DeleteBehavior.Restrict); - - b.Navigation("Site"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.AuditLog", b => - { - b.HasOne("Heimdall.Domain.Entities.AppUser", "User") - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.SetNull); - - b.Navigation("User"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.Camera", b => - { - b.HasOne("Heimdall.Domain.Entities.Agent", "Agent") - .WithMany("Cameras") - .HasForeignKey("AgentId") - .OnDelete(DeleteBehavior.SetNull); - - b.HasOne("Heimdall.Domain.Entities.Site", "Site") - .WithMany("Cameras") - .HasForeignKey("SiteId") - .OnDelete(DeleteBehavior.Restrict) - .IsRequired(); - - b.Navigation("Agent"); - - b.Navigation("Site"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.CameraCredentials", b => - { - b.HasOne("Heimdall.Domain.Entities.Camera", "Camera") - .WithOne("Credentials") - .HasForeignKey("Heimdall.Domain.Entities.CameraCredentials", "CameraId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Camera"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.CameraDetectionProfile", b => - { - b.HasOne("Heimdall.Domain.Entities.Camera", "Camera") - .WithOne("DetectionProfile") - .HasForeignKey("Heimdall.Domain.Entities.CameraDetectionProfile", "CameraId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Camera"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.CameraDiscoveryResult", b => - { - b.HasOne("Heimdall.Domain.Entities.Site", "Site") - .WithMany() - .HasForeignKey("SiteId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Site"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.DiscoveredStreamUrl", b => - { - b.HasOne("Heimdall.Domain.Entities.CameraDiscoveryResult", "DiscoveryResult") - .WithMany("DiscoveredStreams") - .HasForeignKey("DiscoveryResultId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("DiscoveryResult"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.UserGroup", b => - { - b.HasOne("Heimdall.Domain.Entities.Group", "Group") - .WithMany("UserGroups") - .HasForeignKey("GroupId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("Heimdall.Domain.Entities.AppUser", "User") - .WithMany("UserGroups") - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Group"); - - b.Navigation("User"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.UserSite", b => - { - b.HasOne("Heimdall.Domain.Entities.Site", "Site") - .WithMany() - .HasForeignKey("SiteId") - .OnDelete(DeleteBehavior.Restrict) - .IsRequired(); - - b.HasOne("Heimdall.Domain.Entities.AppUser", "User") - .WithMany("UserSites") - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Site"); - - b.Navigation("User"); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => - { - b.HasOne("Heimdall.Domain.Entities.AppRole", null) - .WithMany() - .HasForeignKey("RoleId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => - { - b.HasOne("Heimdall.Domain.Entities.AppUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => - { - b.HasOne("Heimdall.Domain.Entities.AppUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => - { - b.HasOne("Heimdall.Domain.Entities.AppRole", null) - .WithMany() - .HasForeignKey("RoleId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("Heimdall.Domain.Entities.AppUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => - { - b.HasOne("Heimdall.Domain.Entities.AppUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.Agent", b => - { - b.Navigation("Cameras"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.AppUser", b => - { - b.Navigation("UserGroups"); - - b.Navigation("UserSites"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.Camera", b => - { - b.Navigation("Credentials"); - - b.Navigation("DetectionProfile"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.CameraDiscoveryResult", b => - { - b.Navigation("DiscoveredStreams"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.Group", b => - { - b.Navigation("UserGroups"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.Site", b => - { - b.Navigation("Agents"); - - b.Navigation("Cameras"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/src/Heimdall.Infrastructure/Migrations/20260719064824_AddGroups.cs b/src/Heimdall.Infrastructure/Migrations/20260719064824_AddGroups.cs deleted file mode 100644 index 54b4650..0000000 --- a/src/Heimdall.Infrastructure/Migrations/20260719064824_AddGroups.cs +++ /dev/null @@ -1,366 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace Heimdall.Infrastructure.Migrations -{ - /// - public partial class AddGroups : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.AddColumn( - name: "Capabilities", - table: "cameras", - type: "character varying(64)", - unicode: false, - maxLength: 64, - nullable: false, - defaultValue: ""); - - migrationBuilder.AddColumn( - name: "DetectedType", - table: "cameras", - type: "character varying(20)", - unicode: false, - maxLength: 20, - nullable: false, - defaultValue: ""); - - migrationBuilder.AddColumn( - name: "DiscoveryMethod", - table: "cameras", - type: "character varying(20)", - unicode: false, - maxLength: 20, - nullable: false, - defaultValue: ""); - - migrationBuilder.AddColumn( - name: "HttpPort", - table: "cameras", - type: "integer", - nullable: true); - - migrationBuilder.AddColumn( - name: "IpAddress", - table: "cameras", - type: "character varying(45)", - maxLength: 45, - nullable: true); - - migrationBuilder.AddColumn( - name: "LastDiscoveredAt", - table: "cameras", - type: "timestamp with time zone", - nullable: true); - - migrationBuilder.AddColumn( - name: "LastStreamTestAt", - table: "cameras", - type: "timestamp with time zone", - nullable: true); - - migrationBuilder.AddColumn( - name: "LastTestedCodecs", - table: "cameras", - type: "character varying(200)", - unicode: false, - maxLength: 200, - nullable: true); - - migrationBuilder.AddColumn( - name: "LastTestedHeight", - table: "cameras", - type: "integer", - nullable: true); - - migrationBuilder.AddColumn( - name: "LastTestedLatencyMs", - table: "cameras", - type: "bigint", - nullable: true); - - migrationBuilder.AddColumn( - name: "LastTestedWidth", - table: "cameras", - type: "integer", - nullable: true); - - migrationBuilder.AddColumn( - name: "MacAddress", - table: "cameras", - type: "character varying(17)", - maxLength: 17, - nullable: true); - - migrationBuilder.AddColumn( - name: "OnvifPort", - table: "cameras", - type: "integer", - nullable: true); - - migrationBuilder.AddColumn( - name: "RtspPort", - table: "cameras", - type: "integer", - nullable: true); - - migrationBuilder.AddColumn( - name: "SubRtspUrl", - table: "cameras", - type: "character varying(1000)", - unicode: false, - maxLength: 1000, - nullable: true); - - migrationBuilder.CreateTable( - name: "camera_discovery_results", - columns: table => new - { - Id = table.Column(type: "uuid", nullable: false), - SiteId = table.Column(type: "uuid", nullable: false), - IpAddress = table.Column(type: "character varying(45)", unicode: false, maxLength: 45, nullable: false), - MacAddress = table.Column(type: "character varying(17)", unicode: false, maxLength: 17, nullable: true), - Vendor = table.Column(type: "character varying(100)", unicode: false, maxLength: 100, nullable: true), - Hostname = table.Column(type: "character varying(255)", unicode: false, maxLength: 255, nullable: true), - IsReachable = table.Column(type: "boolean", nullable: false), - DetectedType = table.Column(type: "character varying(20)", unicode: false, maxLength: 20, nullable: false), - DiscoveryMethod = table.Column(type: "character varying(20)", unicode: false, maxLength: 20, nullable: false), - OpenPorts = table.Column(type: "integer[]", unicode: false, nullable: false), - OnvifDeviceServiceUrl = table.Column(type: "character varying(500)", unicode: false, maxLength: 500, nullable: true), - OnvifName = table.Column(type: "character varying(200)", unicode: false, maxLength: 200, nullable: true), - OnvifHardware = table.Column(type: "character varying(200)", unicode: false, maxLength: 200, nullable: true), - OnvifPort = table.Column(type: "integer", nullable: true), - HttpServerHeader = table.Column(type: "character varying(200)", unicode: false, maxLength: 200, nullable: true), - HttpStatusCode = table.Column(type: "integer", nullable: true), - HttpPort = table.Column(type: "integer", nullable: true), - IsHomeKitCamera = table.Column(type: "boolean", nullable: true), - HomeKitName = table.Column(type: "character varying(200)", unicode: false, maxLength: 200, nullable: true), - HomeKitDeviceId = table.Column(type: "character varying(50)", unicode: false, maxLength: 50, nullable: true), - HomeKitModel = table.Column(type: "character varying(200)", unicode: false, maxLength: 200, nullable: true), - ProbedAt = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "NOW()"), - IsProcessed = table.Column(type: "boolean", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_camera_discovery_results", x => x.Id); - table.ForeignKey( - name: "FK_camera_discovery_results_sites_SiteId", - column: x => x.SiteId, - principalTable: "sites", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "groups", - columns: table => new - { - Id = table.Column(type: "uuid", nullable: false), - Name = table.Column(type: "character varying(200)", maxLength: 200, nullable: false), - Description = table.Column(type: "character varying(1000)", maxLength: 1000, nullable: true), - CreatedAt = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "NOW()"), - UpdatedAt = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "NOW()"), - IsDeleted = table.Column(type: "boolean", nullable: false), - DeletedAt = table.Column(type: "timestamp with time zone", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_groups", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "discovered_streams", - columns: table => new - { - Id = table.Column(type: "uuid", nullable: false), - DiscoveryResultId = table.Column(type: "uuid", nullable: false), - Url = table.Column(type: "character varying(2000)", unicode: false, maxLength: 2000, nullable: false), - Protocol = table.Column(type: "character varying(20)", unicode: false, maxLength: 20, nullable: false), - Codecs = table.Column(type: "text[]", unicode: false, nullable: false), - Width = table.Column(type: "integer", nullable: false), - Height = table.Column(type: "integer", nullable: false), - LatencyMs = table.Column(type: "bigint", nullable: false), - IsMainStream = table.Column(type: "boolean", nullable: false), - IsAlive = table.Column(type: "boolean", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_discovered_streams", x => x.Id); - table.ForeignKey( - name: "FK_discovered_streams_camera_discovery_results_DiscoveryResult~", - column: x => x.DiscoveryResultId, - principalTable: "camera_discovery_results", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "user_groups", - columns: table => new - { - UserId = table.Column(type: "uuid", nullable: false), - GroupId = table.Column(type: "uuid", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_user_groups", x => new { x.UserId, x.GroupId }); - table.ForeignKey( - name: "FK_user_groups_groups_GroupId", - column: x => x.GroupId, - principalTable: "groups", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_user_groups_users_UserId", - column: x => x.UserId, - principalTable: "users", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateIndex( - name: "IX_cameras_IpAddress", - table: "cameras", - column: "IpAddress"); - - migrationBuilder.CreateIndex( - name: "IX_cameras_MacAddress", - table: "cameras", - column: "MacAddress"); - - migrationBuilder.CreateIndex( - name: "IX_camera_discovery_results_IpAddress", - table: "camera_discovery_results", - column: "IpAddress"); - - migrationBuilder.CreateIndex( - name: "IX_camera_discovery_results_IsProcessed", - table: "camera_discovery_results", - column: "IsProcessed"); - - migrationBuilder.CreateIndex( - name: "IX_camera_discovery_results_SiteId", - table: "camera_discovery_results", - column: "SiteId"); - - migrationBuilder.CreateIndex( - name: "IX_discovered_streams_DiscoveryResultId", - table: "discovered_streams", - column: "DiscoveryResultId"); - - migrationBuilder.CreateIndex( - name: "IX_discovered_streams_IsAlive", - table: "discovered_streams", - column: "IsAlive"); - - migrationBuilder.CreateIndex( - name: "IX_discovered_streams_IsMainStream", - table: "discovered_streams", - column: "IsMainStream"); - - migrationBuilder.CreateIndex( - name: "IX_groups_IsDeleted", - table: "groups", - column: "IsDeleted", - filter: "\"IsDeleted\" = false"); - - migrationBuilder.CreateIndex( - name: "IX_groups_Name", - table: "groups", - column: "Name"); - - migrationBuilder.CreateIndex( - name: "IX_user_groups_GroupId", - table: "user_groups", - column: "GroupId"); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "discovered_streams"); - - migrationBuilder.DropTable( - name: "user_groups"); - - migrationBuilder.DropTable( - name: "camera_discovery_results"); - - migrationBuilder.DropTable( - name: "groups"); - - migrationBuilder.DropIndex( - name: "IX_cameras_IpAddress", - table: "cameras"); - - migrationBuilder.DropIndex( - name: "IX_cameras_MacAddress", - table: "cameras"); - - migrationBuilder.DropColumn( - name: "Capabilities", - table: "cameras"); - - migrationBuilder.DropColumn( - name: "DetectedType", - table: "cameras"); - - migrationBuilder.DropColumn( - name: "DiscoveryMethod", - table: "cameras"); - - migrationBuilder.DropColumn( - name: "HttpPort", - table: "cameras"); - - migrationBuilder.DropColumn( - name: "IpAddress", - table: "cameras"); - - migrationBuilder.DropColumn( - name: "LastDiscoveredAt", - table: "cameras"); - - migrationBuilder.DropColumn( - name: "LastStreamTestAt", - table: "cameras"); - - migrationBuilder.DropColumn( - name: "LastTestedCodecs", - table: "cameras"); - - migrationBuilder.DropColumn( - name: "LastTestedHeight", - table: "cameras"); - - migrationBuilder.DropColumn( - name: "LastTestedLatencyMs", - table: "cameras"); - - migrationBuilder.DropColumn( - name: "LastTestedWidth", - table: "cameras"); - - migrationBuilder.DropColumn( - name: "MacAddress", - table: "cameras"); - - migrationBuilder.DropColumn( - name: "OnvifPort", - table: "cameras"); - - migrationBuilder.DropColumn( - name: "RtspPort", - table: "cameras"); - - migrationBuilder.DropColumn( - name: "SubRtspUrl", - table: "cameras"); - } - } -} diff --git a/src/Heimdall.Infrastructure/Migrations/20260719122001_AddCameraAssignments.Designer.cs b/src/Heimdall.Infrastructure/Migrations/20260719122001_AddCameraAssignments.Designer.cs deleted file mode 100644 index f6bdd1f..0000000 --- a/src/Heimdall.Infrastructure/Migrations/20260719122001_AddCameraAssignments.Designer.cs +++ /dev/null @@ -1,1383 +0,0 @@ -// -using System; -using Heimdall.Infrastructure.Data; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; - -#nullable disable - -namespace Heimdall.Infrastructure.Migrations -{ - [DbContext(typeof(AppDbContext))] - [Migration("20260719122001_AddCameraAssignments")] - partial class AddCameraAssignments - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "10.0.10") - .HasAnnotation("Relational:MaxIdentifierLength", 63); - - NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); - - modelBuilder.Entity("Heimdall.Domain.Entities.Agent", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("ApiKeyHash") - .HasMaxLength(128) - .IsUnicode(false) - .HasColumnType("character varying(128)"); - - b.Property("ApiKeyPrefix") - .HasMaxLength(8) - .IsUnicode(false) - .HasColumnType("character varying(8)"); - - b.Property("CpuCores") - .HasColumnType("integer"); - - b.Property("CreatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.Property("DeletedAt") - .HasColumnType("timestamp with time zone"); - - b.Property("GpuType") - .IsRequired() - .HasMaxLength(20) - .IsUnicode(false) - .HasColumnType("character varying(20)"); - - b.Property("HasGpu") - .HasColumnType("boolean"); - - b.Property("Hostname") - .IsRequired() - .HasMaxLength(255) - .IsUnicode(false) - .HasColumnType("character varying(255)"); - - b.Property("IsDeleted") - .HasColumnType("boolean"); - - b.Property("LastHeartbeat") - .HasColumnType("timestamp with time zone"); - - b.Property("MemoryMb") - .HasColumnType("bigint"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(200) - .IsUnicode(false) - .HasColumnType("character varying(200)"); - - b.Property("PublicIp") - .HasMaxLength(45) - .IsUnicode(false) - .HasColumnType("character varying(45)"); - - b.Property("SiteId") - .HasColumnType("uuid"); - - b.Property("Status") - .IsRequired() - .HasMaxLength(20) - .IsUnicode(false) - .HasColumnType("character varying(20)"); - - b.Property("UpdatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.Property("Version") - .IsRequired() - .HasMaxLength(50) - .IsUnicode(false) - .HasColumnType("character varying(50)"); - - b.HasKey("Id"); - - b.HasIndex("LastHeartbeat") - .HasFilter("\"Status\" = 'Online'"); - - b.HasIndex("SiteId"); - - b.ToTable("agents", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.AgentSetting", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("AgentId") - .HasColumnType("uuid") - .HasColumnName("agent_id"); - - b.Property("CreatedAt") - .HasColumnType("timestamp with time zone") - .HasColumnName("created_at"); - - b.Property("Key") - .IsRequired() - .HasMaxLength(200) - .HasColumnType("character varying(200)") - .HasColumnName("key"); - - b.Property("UpdatedAt") - .HasColumnType("timestamp with time zone") - .HasColumnName("updated_at"); - - b.Property("Value") - .IsRequired() - .HasColumnType("text") - .HasColumnName("value"); - - b.HasKey("Id"); - - b.HasIndex("AgentId", "Key") - .IsUnique(); - - b.ToTable("agent_settings", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.ApiKey", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("CreatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.Property("CreatedByUserId") - .HasColumnType("uuid"); - - b.Property("Enabled") - .HasColumnType("boolean"); - - b.Property("ExpiresAt") - .HasColumnType("timestamp with time zone"); - - b.Property("KeyHash") - .IsRequired() - .HasMaxLength(128) - .IsUnicode(false) - .HasColumnType("character varying(128)"); - - b.Property("KeyPrefix") - .IsRequired() - .HasMaxLength(8) - .IsUnicode(false) - .HasColumnType("character varying(8)"); - - b.Property("LastUsedAt") - .HasColumnType("timestamp with time zone"); - - b.Property("SiteId") - .HasColumnType("uuid"); - - b.HasKey("Id"); - - b.HasIndex("KeyHash"); - - b.HasIndex("KeyPrefix"); - - b.HasIndex("SiteId"); - - b.ToTable("api_keys", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.AppRole", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("ConcurrencyStamp") - .IsConcurrencyToken() - .HasColumnType("text"); - - b.Property("Name") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.Property("NormalizedName") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.HasKey("Id"); - - b.HasIndex("NormalizedName") - .IsUnique() - .HasDatabaseName("RoleNameIndex"); - - b.ToTable("roles", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.AppSetting", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("AllowedValues") - .HasMaxLength(2000) - .HasColumnType("character varying(2000)") - .HasColumnName("allowed_values"); - - b.Property("Category") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("character varying(100)") - .HasColumnName("category"); - - b.Property("CreatedAt") - .HasColumnType("timestamp with time zone") - .HasColumnName("created_at"); - - b.Property("Description") - .HasMaxLength(500) - .HasColumnType("character varying(500)") - .HasColumnName("description"); - - b.Property("Key") - .IsRequired() - .HasMaxLength(200) - .HasColumnType("character varying(200)") - .HasColumnName("key"); - - b.Property("UpdatedAt") - .HasColumnType("timestamp with time zone") - .HasColumnName("updated_at"); - - b.Property("Value") - .IsRequired() - .HasColumnType("text") - .HasColumnName("value"); - - b.Property("ValueType") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("character varying(50)") - .HasColumnName("value_type"); - - b.HasKey("Id"); - - b.HasIndex("Key") - .IsUnique(); - - b.ToTable("app_settings", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.AppUser", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("AccessFailedCount") - .HasColumnType("integer"); - - b.Property("ConcurrencyStamp") - .IsConcurrencyToken() - .HasColumnType("text"); - - b.Property("CreatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.Property("DisplayName") - .IsRequired() - .HasMaxLength(200) - .HasColumnType("character varying(200)"); - - b.Property("Email") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.Property("EmailConfirmed") - .HasColumnType("boolean"); - - b.Property("Language") - .IsRequired() - .ValueGeneratedOnAdd() - .HasMaxLength(10) - .IsUnicode(false) - .HasColumnType("character varying(10)") - .HasDefaultValue("fr"); - - b.Property("LockoutEnabled") - .HasColumnType("boolean"); - - b.Property("LockoutEnd") - .HasColumnType("timestamp with time zone"); - - b.Property("MustChangePassword") - .ValueGeneratedOnAdd() - .HasColumnType("boolean") - .HasDefaultValue(false); - - b.Property("NormalizedEmail") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.Property("NormalizedUserName") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.Property("PasswordHash") - .HasColumnType("text"); - - b.Property("PhoneNumber") - .HasColumnType("text"); - - b.Property("PhoneNumberConfirmed") - .HasColumnType("boolean"); - - b.Property("SecurityStamp") - .HasColumnType("text"); - - b.Property("Theme") - .ValueGeneratedOnAdd() - .HasMaxLength(20) - .IsUnicode(false) - .HasColumnType("character varying(20)") - .HasDefaultValue("Auto"); - - b.Property("TwoFactorEnabled") - .HasColumnType("boolean"); - - b.Property("UserName") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.HasKey("Id"); - - b.HasIndex("NormalizedEmail") - .HasDatabaseName("EmailIndex"); - - b.HasIndex("NormalizedUserName") - .IsUnique() - .HasDatabaseName("UserNameIndex"); - - b.ToTable("users", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.AuditLog", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("Action") - .IsRequired() - .HasMaxLength(100) - .IsUnicode(false) - .HasColumnType("character varying(100)"); - - b.Property("IpAddress") - .HasMaxLength(45) - .IsUnicode(false) - .HasColumnType("character varying(45)"); - - b.Property("NewValue") - .HasColumnType("text"); - - b.Property("OldValue") - .HasColumnType("text"); - - b.Property("ResourceId") - .HasMaxLength(100) - .IsUnicode(false) - .HasColumnType("character varying(100)"); - - b.Property("ResourceType") - .IsRequired() - .HasMaxLength(100) - .IsUnicode(false) - .HasColumnType("character varying(100)"); - - b.Property("Timestamp") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.Property("UserId") - .HasColumnType("uuid"); - - b.HasKey("Id"); - - b.HasIndex("Timestamp") - .IsDescending(); - - b.HasIndex("UserId"); - - b.HasIndex("ResourceType", "ResourceId", "Timestamp") - .IsDescending(false, false, true); - - b.ToTable("audit_logs", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.Camera", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("AgentId") - .HasColumnType("uuid"); - - b.Property("Capabilities") - .IsRequired() - .HasMaxLength(64) - .IsUnicode(false) - .HasColumnType("character varying(64)"); - - b.Property("CreatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.Property("DeletedAt") - .HasColumnType("timestamp with time zone"); - - b.Property("DetectedType") - .IsRequired() - .HasMaxLength(20) - .IsUnicode(false) - .HasColumnType("character varying(20)"); - - b.Property("DiscoveryMethod") - .IsRequired() - .HasMaxLength(20) - .IsUnicode(false) - .HasColumnType("character varying(20)"); - - b.Property("HasAudio") - .HasColumnType("boolean"); - - b.Property("HasMotionDetection") - .HasColumnType("boolean"); - - b.Property("HasPtz") - .HasColumnType("boolean"); - - b.Property("HttpPort") - .HasColumnType("integer"); - - b.Property("IpAddress") - .HasMaxLength(45) - .HasColumnType("character varying(45)"); - - b.Property("IsDeleted") - .HasColumnType("boolean"); - - b.Property("LastDiscoveredAt") - .HasColumnType("timestamp with time zone"); - - b.Property("LastStreamTestAt") - .HasColumnType("timestamp with time zone"); - - b.Property("LastTestedCodecs") - .HasMaxLength(200) - .IsUnicode(false) - .HasColumnType("character varying(200)"); - - b.Property("LastTestedHeight") - .HasColumnType("integer"); - - b.Property("LastTestedLatencyMs") - .HasColumnType("bigint"); - - b.Property("LastTestedWidth") - .HasColumnType("integer"); - - b.Property("MacAddress") - .HasMaxLength(17) - .HasColumnType("character varying(17)"); - - b.Property("Manufacturer") - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("Model") - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(200) - .IsUnicode(false) - .HasColumnType("character varying(200)"); - - b.Property("OnvifPort") - .HasColumnType("integer"); - - b.Property("RtspPort") - .HasColumnType("integer"); - - b.Property("RtspUrl") - .HasMaxLength(1000) - .IsUnicode(false) - .HasColumnType("character varying(1000)"); - - b.Property("SiteId") - .HasColumnType("uuid"); - - b.Property("Status") - .IsRequired() - .HasMaxLength(20) - .IsUnicode(false) - .HasColumnType("character varying(20)"); - - b.Property("SubRtspUrl") - .HasMaxLength(1000) - .IsUnicode(false) - .HasColumnType("character varying(1000)"); - - b.Property("UpdatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.HasKey("Id"); - - b.HasIndex("AgentId"); - - b.HasIndex("IpAddress"); - - b.HasIndex("MacAddress"); - - b.HasIndex("SiteId"); - - b.ToTable("cameras", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.CameraAssignment", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("AgentId") - .HasColumnType("uuid"); - - b.Property("AssignedAt") - .HasColumnType("timestamp with time zone"); - - b.Property("CameraId") - .HasColumnType("uuid"); - - b.Property("Reason") - .IsRequired() - .HasMaxLength(50) - .IsUnicode(false) - .HasColumnType("character varying(50)"); - - b.Property("ReleasedAt") - .HasColumnType("timestamp with time zone"); - - b.HasKey("Id"); - - b.HasIndex("AssignedAt"); - - b.HasIndex("AgentId", "ReleasedAt") - .HasFilter("\"ReleasedAt\" IS NULL"); - - b.HasIndex("CameraId", "ReleasedAt") - .IsUnique() - .HasFilter("\"ReleasedAt\" IS NULL"); - - b.ToTable("camera_assignments", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.CameraCredentials", b => - { - b.Property("CameraId") - .HasColumnType("uuid"); - - b.Property("CreatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.Property("OnvifPassword") - .IsRequired() - .HasMaxLength(500) - .IsUnicode(false) - .HasColumnType("character varying(500)"); - - b.Property("OnvifUsername") - .IsRequired() - .ValueGeneratedOnAdd() - .HasMaxLength(100) - .IsUnicode(false) - .HasColumnType("character varying(100)") - .HasDefaultValue("admin"); - - b.Property("RtspPassword") - .IsRequired() - .HasMaxLength(500) - .IsUnicode(false) - .HasColumnType("character varying(500)"); - - b.Property("RtspUsername") - .IsRequired() - .HasMaxLength(100) - .IsUnicode(false) - .HasColumnType("character varying(100)"); - - b.Property("UpdatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.HasKey("CameraId"); - - b.ToTable("camera_credentials", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.CameraDetectionProfile", b => - { - b.Property("CameraId") - .HasColumnType("uuid"); - - b.Property("ActiveIntervalMs") - .HasColumnType("integer"); - - b.Property("AnimalCooldownSec") - .HasColumnType("integer"); - - b.Property("DetectAnimal") - .HasColumnType("boolean"); - - b.Property("DetectMotion") - .HasColumnType("boolean"); - - b.Property("DetectPackage") - .HasColumnType("boolean"); - - b.Property("DetectPerson") - .HasColumnType("boolean"); - - b.Property("DetectVehicle") - .HasColumnType("boolean"); - - b.Property("FaceRecognition") - .HasColumnType("boolean"); - - b.Property("IdleIntervalMs") - .HasColumnType("integer"); - - b.Property("IoUThreshold") - .HasColumnType("double precision"); - - b.Property("LicensePlateRecognition") - .HasColumnType("boolean"); - - b.Property("MaxEventsPerMinute") - .HasColumnType("integer"); - - b.Property("MinConfidence") - .ValueGeneratedOnAdd() - .HasColumnType("double precision") - .HasDefaultValue(0.40000000000000002); - - b.Property("MotionIntervalMs") - .HasColumnType("integer"); - - b.Property("MotionThreshold") - .HasColumnType("double precision"); - - b.Property("PersonCooldownSec") - .HasColumnType("integer"); - - b.Property("RequireMotionForAI") - .HasColumnType("boolean"); - - b.Property("VehicleCooldownSec") - .HasColumnType("integer"); - - b.Property("YoloModel") - .IsRequired() - .ValueGeneratedOnAdd() - .HasMaxLength(50) - .IsUnicode(false) - .HasColumnType("character varying(50)") - .HasDefaultValue("yolov8n"); - - b.HasKey("CameraId"); - - b.ToTable("camera_detection_profiles", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.CameraDiscoveryResult", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("DetectedType") - .IsRequired() - .HasMaxLength(20) - .IsUnicode(false) - .HasColumnType("character varying(20)"); - - b.Property("DiscoveryMethod") - .IsRequired() - .HasMaxLength(20) - .IsUnicode(false) - .HasColumnType("character varying(20)"); - - b.Property("HomeKitDeviceId") - .HasMaxLength(50) - .IsUnicode(false) - .HasColumnType("character varying(50)"); - - b.Property("HomeKitModel") - .HasMaxLength(200) - .IsUnicode(false) - .HasColumnType("character varying(200)"); - - b.Property("HomeKitName") - .HasMaxLength(200) - .IsUnicode(false) - .HasColumnType("character varying(200)"); - - b.Property("Hostname") - .HasMaxLength(255) - .IsUnicode(false) - .HasColumnType("character varying(255)"); - - b.Property("HttpPort") - .HasColumnType("integer"); - - b.Property("HttpServerHeader") - .HasMaxLength(200) - .IsUnicode(false) - .HasColumnType("character varying(200)"); - - b.Property("HttpStatusCode") - .HasColumnType("integer"); - - b.Property("IpAddress") - .IsRequired() - .HasMaxLength(45) - .IsUnicode(false) - .HasColumnType("character varying(45)"); - - b.Property("IsHomeKitCamera") - .HasColumnType("boolean"); - - b.Property("IsProcessed") - .HasColumnType("boolean"); - - b.Property("IsReachable") - .HasColumnType("boolean"); - - b.Property("MacAddress") - .HasMaxLength(17) - .IsUnicode(false) - .HasColumnType("character varying(17)"); - - b.Property("OnvifDeviceServiceUrl") - .HasMaxLength(500) - .IsUnicode(false) - .HasColumnType("character varying(500)"); - - b.Property("OnvifHardware") - .HasMaxLength(200) - .IsUnicode(false) - .HasColumnType("character varying(200)"); - - b.Property("OnvifName") - .HasMaxLength(200) - .IsUnicode(false) - .HasColumnType("character varying(200)"); - - b.Property("OnvifPort") - .HasColumnType("integer"); - - b.PrimitiveCollection("OpenPorts") - .IsRequired() - .IsUnicode(false) - .HasColumnType("integer[]"); - - b.Property("ProbedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.Property("SiteId") - .HasColumnType("uuid"); - - b.Property("Vendor") - .HasMaxLength(100) - .IsUnicode(false) - .HasColumnType("character varying(100)"); - - b.HasKey("Id"); - - b.HasIndex("IpAddress"); - - b.HasIndex("IsProcessed"); - - b.HasIndex("SiteId"); - - b.ToTable("camera_discovery_results", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.DiscoveredStreamUrl", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.PrimitiveCollection("Codecs") - .IsRequired() - .IsUnicode(false) - .HasColumnType("text[]"); - - b.Property("DiscoveryResultId") - .HasColumnType("uuid"); - - b.Property("Height") - .HasColumnType("integer"); - - b.Property("IsAlive") - .HasColumnType("boolean"); - - b.Property("IsMainStream") - .HasColumnType("boolean"); - - b.Property("LatencyMs") - .HasColumnType("bigint"); - - b.Property("Protocol") - .IsRequired() - .HasMaxLength(20) - .IsUnicode(false) - .HasColumnType("character varying(20)"); - - b.Property("Url") - .IsRequired() - .HasMaxLength(2000) - .IsUnicode(false) - .HasColumnType("character varying(2000)"); - - b.Property("Width") - .HasColumnType("integer"); - - b.HasKey("Id"); - - b.HasIndex("DiscoveryResultId"); - - b.HasIndex("IsAlive"); - - b.HasIndex("IsMainStream"); - - b.ToTable("discovered_streams", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.Group", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("CreatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.Property("DeletedAt") - .HasColumnType("timestamp with time zone"); - - b.Property("Description") - .HasMaxLength(1000) - .HasColumnType("character varying(1000)"); - - b.Property("IsDeleted") - .HasColumnType("boolean"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(200) - .HasColumnType("character varying(200)"); - - b.Property("UpdatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.HasKey("Id"); - - b.HasIndex("IsDeleted") - .HasFilter("\"IsDeleted\" = false"); - - b.HasIndex("Name"); - - b.ToTable("groups", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.Site", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("Address") - .HasMaxLength(500) - .HasColumnType("character varying(500)"); - - b.Property("CreatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.Property("DeletedAt") - .HasColumnType("timestamp with time zone"); - - b.Property("Enabled") - .HasColumnType("boolean"); - - b.Property("IsDeleted") - .HasColumnType("boolean"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(200) - .HasColumnType("character varying(200)"); - - b.Property("RegistrationTokenHash") - .HasMaxLength(128) - .IsUnicode(false) - .HasColumnType("character varying(128)"); - - b.Property("Timezone") - .IsRequired() - .ValueGeneratedOnAdd() - .HasMaxLength(100) - .IsUnicode(false) - .HasColumnType("character varying(100)") - .HasDefaultValue("UTC"); - - b.Property("TokenExpiresAt") - .HasColumnType("timestamp with time zone"); - - b.Property("UpdatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.HasKey("Id"); - - b.HasIndex("IsDeleted") - .HasFilter("\"IsDeleted\" = false"); - - b.HasIndex("Name"); - - b.ToTable("sites", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.UserGroup", b => - { - b.Property("UserId") - .HasColumnType("uuid"); - - b.Property("GroupId") - .HasColumnType("uuid"); - - b.HasKey("UserId", "GroupId"); - - b.HasIndex("GroupId"); - - b.ToTable("user_groups", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.UserSite", b => - { - b.Property("UserId") - .HasColumnType("uuid"); - - b.Property("SiteId") - .HasColumnType("uuid"); - - b.HasKey("UserId", "SiteId"); - - b.HasIndex("SiteId"); - - b.ToTable("user_sites", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("ClaimType") - .HasColumnType("text"); - - b.Property("ClaimValue") - .HasColumnType("text"); - - b.Property("RoleId") - .HasColumnType("uuid"); - - b.HasKey("Id"); - - b.HasIndex("RoleId"); - - b.ToTable("role_claims", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("ClaimType") - .HasColumnType("text"); - - b.Property("ClaimValue") - .HasColumnType("text"); - - b.Property("UserId") - .HasColumnType("uuid"); - - b.HasKey("Id"); - - b.HasIndex("UserId"); - - b.ToTable("user_claims", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => - { - b.Property("LoginProvider") - .HasColumnType("text"); - - b.Property("ProviderKey") - .HasColumnType("text"); - - b.Property("ProviderDisplayName") - .HasColumnType("text"); - - b.Property("UserId") - .HasColumnType("uuid"); - - b.HasKey("LoginProvider", "ProviderKey"); - - b.HasIndex("UserId"); - - b.ToTable("user_logins", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => - { - b.Property("UserId") - .HasColumnType("uuid"); - - b.Property("RoleId") - .HasColumnType("uuid"); - - b.HasKey("UserId", "RoleId"); - - b.HasIndex("RoleId"); - - b.ToTable("user_roles", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => - { - b.Property("UserId") - .HasColumnType("uuid"); - - b.Property("LoginProvider") - .HasColumnType("text"); - - b.Property("Name") - .HasColumnType("text"); - - b.Property("Value") - .HasColumnType("text"); - - b.HasKey("UserId", "LoginProvider", "Name"); - - b.ToTable("user_tokens", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.Agent", b => - { - b.HasOne("Heimdall.Domain.Entities.Site", "Site") - .WithMany("Agents") - .HasForeignKey("SiteId") - .OnDelete(DeleteBehavior.Restrict) - .IsRequired(); - - b.Navigation("Site"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.AgentSetting", b => - { - b.HasOne("Heimdall.Domain.Entities.Agent", "Agent") - .WithMany() - .HasForeignKey("AgentId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Agent"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.ApiKey", b => - { - b.HasOne("Heimdall.Domain.Entities.Site", "Site") - .WithMany() - .HasForeignKey("SiteId") - .OnDelete(DeleteBehavior.Restrict); - - b.Navigation("Site"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.AuditLog", b => - { - b.HasOne("Heimdall.Domain.Entities.AppUser", "User") - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.SetNull); - - b.Navigation("User"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.Camera", b => - { - b.HasOne("Heimdall.Domain.Entities.Agent", "Agent") - .WithMany("Cameras") - .HasForeignKey("AgentId") - .OnDelete(DeleteBehavior.SetNull); - - b.HasOne("Heimdall.Domain.Entities.Site", "Site") - .WithMany("Cameras") - .HasForeignKey("SiteId") - .OnDelete(DeleteBehavior.Restrict) - .IsRequired(); - - b.Navigation("Agent"); - - b.Navigation("Site"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.CameraAssignment", b => - { - b.HasOne("Heimdall.Domain.Entities.Agent", "Agent") - .WithMany() - .HasForeignKey("AgentId") - .OnDelete(DeleteBehavior.Restrict) - .IsRequired(); - - b.HasOne("Heimdall.Domain.Entities.Camera", "Camera") - .WithMany() - .HasForeignKey("CameraId") - .OnDelete(DeleteBehavior.Restrict) - .IsRequired(); - - b.Navigation("Agent"); - - b.Navigation("Camera"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.CameraCredentials", b => - { - b.HasOne("Heimdall.Domain.Entities.Camera", "Camera") - .WithOne("Credentials") - .HasForeignKey("Heimdall.Domain.Entities.CameraCredentials", "CameraId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Camera"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.CameraDetectionProfile", b => - { - b.HasOne("Heimdall.Domain.Entities.Camera", "Camera") - .WithOne("DetectionProfile") - .HasForeignKey("Heimdall.Domain.Entities.CameraDetectionProfile", "CameraId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Camera"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.CameraDiscoveryResult", b => - { - b.HasOne("Heimdall.Domain.Entities.Site", "Site") - .WithMany() - .HasForeignKey("SiteId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Site"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.DiscoveredStreamUrl", b => - { - b.HasOne("Heimdall.Domain.Entities.CameraDiscoveryResult", "DiscoveryResult") - .WithMany("DiscoveredStreams") - .HasForeignKey("DiscoveryResultId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("DiscoveryResult"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.UserGroup", b => - { - b.HasOne("Heimdall.Domain.Entities.Group", "Group") - .WithMany("UserGroups") - .HasForeignKey("GroupId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("Heimdall.Domain.Entities.AppUser", "User") - .WithMany("UserGroups") - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Group"); - - b.Navigation("User"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.UserSite", b => - { - b.HasOne("Heimdall.Domain.Entities.Site", "Site") - .WithMany() - .HasForeignKey("SiteId") - .OnDelete(DeleteBehavior.Restrict) - .IsRequired(); - - b.HasOne("Heimdall.Domain.Entities.AppUser", "User") - .WithMany("UserSites") - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Site"); - - b.Navigation("User"); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => - { - b.HasOne("Heimdall.Domain.Entities.AppRole", null) - .WithMany() - .HasForeignKey("RoleId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => - { - b.HasOne("Heimdall.Domain.Entities.AppUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => - { - b.HasOne("Heimdall.Domain.Entities.AppUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => - { - b.HasOne("Heimdall.Domain.Entities.AppRole", null) - .WithMany() - .HasForeignKey("RoleId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("Heimdall.Domain.Entities.AppUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => - { - b.HasOne("Heimdall.Domain.Entities.AppUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.Agent", b => - { - b.Navigation("Cameras"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.AppUser", b => - { - b.Navigation("UserGroups"); - - b.Navigation("UserSites"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.Camera", b => - { - b.Navigation("Credentials"); - - b.Navigation("DetectionProfile"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.CameraDiscoveryResult", b => - { - b.Navigation("DiscoveredStreams"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.Group", b => - { - b.Navigation("UserGroups"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.Site", b => - { - b.Navigation("Agents"); - - b.Navigation("Cameras"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/src/Heimdall.Infrastructure/Migrations/20260719122001_AddCameraAssignments.cs b/src/Heimdall.Infrastructure/Migrations/20260719122001_AddCameraAssignments.cs deleted file mode 100644 index ce2c3c3..0000000 --- a/src/Heimdall.Infrastructure/Migrations/20260719122001_AddCameraAssignments.cs +++ /dev/null @@ -1,68 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace Heimdall.Infrastructure.Migrations -{ - /// - public partial class AddCameraAssignments : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "camera_assignments", - columns: table => new - { - Id = table.Column(type: "uuid", nullable: false), - CameraId = table.Column(type: "uuid", nullable: false), - AgentId = table.Column(type: "uuid", nullable: false), - Reason = table.Column(type: "character varying(50)", unicode: false, maxLength: 50, nullable: false), - AssignedAt = table.Column(type: "timestamp with time zone", nullable: false), - ReleasedAt = table.Column(type: "timestamp with time zone", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_camera_assignments", x => x.Id); - table.ForeignKey( - name: "FK_camera_assignments_agents_AgentId", - column: x => x.AgentId, - principalTable: "agents", - principalColumn: "Id", - onDelete: ReferentialAction.Restrict); - table.ForeignKey( - name: "FK_camera_assignments_cameras_CameraId", - column: x => x.CameraId, - principalTable: "cameras", - principalColumn: "Id", - onDelete: ReferentialAction.Restrict); - }); - - migrationBuilder.CreateIndex( - name: "IX_camera_assignments_AgentId_ReleasedAt", - table: "camera_assignments", - columns: new[] { "AgentId", "ReleasedAt" }, - filter: "\"ReleasedAt\" IS NULL"); - - migrationBuilder.CreateIndex( - name: "IX_camera_assignments_AssignedAt", - table: "camera_assignments", - column: "AssignedAt"); - - migrationBuilder.CreateIndex( - name: "IX_camera_assignments_CameraId_ReleasedAt", - table: "camera_assignments", - columns: new[] { "CameraId", "ReleasedAt" }, - unique: true, - filter: "\"ReleasedAt\" IS NULL"); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "camera_assignments"); - } - } -} diff --git a/src/Heimdall.Infrastructure/Migrations/20260719125356_AddCameraEvents.Designer.cs b/src/Heimdall.Infrastructure/Migrations/20260719125356_AddCameraEvents.Designer.cs deleted file mode 100644 index 202b76b..0000000 --- a/src/Heimdall.Infrastructure/Migrations/20260719125356_AddCameraEvents.Designer.cs +++ /dev/null @@ -1,1457 +0,0 @@ -// -using System; -using Heimdall.Infrastructure.Data; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; - -#nullable disable - -namespace Heimdall.Infrastructure.Migrations -{ - [DbContext(typeof(AppDbContext))] - [Migration("20260719125356_AddCameraEvents")] - partial class AddCameraEvents - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "10.0.10") - .HasAnnotation("Relational:MaxIdentifierLength", 63); - - NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); - - modelBuilder.Entity("Heimdall.Domain.Entities.Agent", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("ApiKeyHash") - .HasMaxLength(128) - .IsUnicode(false) - .HasColumnType("character varying(128)"); - - b.Property("ApiKeyPrefix") - .HasMaxLength(8) - .IsUnicode(false) - .HasColumnType("character varying(8)"); - - b.Property("CpuCores") - .HasColumnType("integer"); - - b.Property("CreatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.Property("DeletedAt") - .HasColumnType("timestamp with time zone"); - - b.Property("GpuType") - .IsRequired() - .HasMaxLength(20) - .IsUnicode(false) - .HasColumnType("character varying(20)"); - - b.Property("HasGpu") - .HasColumnType("boolean"); - - b.Property("Hostname") - .IsRequired() - .HasMaxLength(255) - .IsUnicode(false) - .HasColumnType("character varying(255)"); - - b.Property("IsDeleted") - .HasColumnType("boolean"); - - b.Property("LastHeartbeat") - .HasColumnType("timestamp with time zone"); - - b.Property("MemoryMb") - .HasColumnType("bigint"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(200) - .IsUnicode(false) - .HasColumnType("character varying(200)"); - - b.Property("PublicIp") - .HasMaxLength(45) - .IsUnicode(false) - .HasColumnType("character varying(45)"); - - b.Property("SiteId") - .HasColumnType("uuid"); - - b.Property("Status") - .IsRequired() - .HasMaxLength(20) - .IsUnicode(false) - .HasColumnType("character varying(20)"); - - b.Property("UpdatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.Property("Version") - .IsRequired() - .HasMaxLength(50) - .IsUnicode(false) - .HasColumnType("character varying(50)"); - - b.HasKey("Id"); - - b.HasIndex("LastHeartbeat") - .HasFilter("\"Status\" = 'Online'"); - - b.HasIndex("SiteId"); - - b.ToTable("agents", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.AgentSetting", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("AgentId") - .HasColumnType("uuid") - .HasColumnName("agent_id"); - - b.Property("CreatedAt") - .HasColumnType("timestamp with time zone") - .HasColumnName("created_at"); - - b.Property("Key") - .IsRequired() - .HasMaxLength(200) - .HasColumnType("character varying(200)") - .HasColumnName("key"); - - b.Property("UpdatedAt") - .HasColumnType("timestamp with time zone") - .HasColumnName("updated_at"); - - b.Property("Value") - .IsRequired() - .HasColumnType("text") - .HasColumnName("value"); - - b.HasKey("Id"); - - b.HasIndex("AgentId", "Key") - .IsUnique(); - - b.ToTable("agent_settings", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.ApiKey", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("CreatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.Property("CreatedByUserId") - .HasColumnType("uuid"); - - b.Property("Enabled") - .HasColumnType("boolean"); - - b.Property("ExpiresAt") - .HasColumnType("timestamp with time zone"); - - b.Property("KeyHash") - .IsRequired() - .HasMaxLength(128) - .IsUnicode(false) - .HasColumnType("character varying(128)"); - - b.Property("KeyPrefix") - .IsRequired() - .HasMaxLength(8) - .IsUnicode(false) - .HasColumnType("character varying(8)"); - - b.Property("LastUsedAt") - .HasColumnType("timestamp with time zone"); - - b.Property("SiteId") - .HasColumnType("uuid"); - - b.HasKey("Id"); - - b.HasIndex("KeyHash"); - - b.HasIndex("KeyPrefix"); - - b.HasIndex("SiteId"); - - b.ToTable("api_keys", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.AppRole", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("ConcurrencyStamp") - .IsConcurrencyToken() - .HasColumnType("text"); - - b.Property("Name") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.Property("NormalizedName") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.HasKey("Id"); - - b.HasIndex("NormalizedName") - .IsUnique() - .HasDatabaseName("RoleNameIndex"); - - b.ToTable("roles", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.AppSetting", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("AllowedValues") - .HasMaxLength(2000) - .HasColumnType("character varying(2000)") - .HasColumnName("allowed_values"); - - b.Property("Category") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("character varying(100)") - .HasColumnName("category"); - - b.Property("CreatedAt") - .HasColumnType("timestamp with time zone") - .HasColumnName("created_at"); - - b.Property("Description") - .HasMaxLength(500) - .HasColumnType("character varying(500)") - .HasColumnName("description"); - - b.Property("Key") - .IsRequired() - .HasMaxLength(200) - .HasColumnType("character varying(200)") - .HasColumnName("key"); - - b.Property("UpdatedAt") - .HasColumnType("timestamp with time zone") - .HasColumnName("updated_at"); - - b.Property("Value") - .IsRequired() - .HasColumnType("text") - .HasColumnName("value"); - - b.Property("ValueType") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("character varying(50)") - .HasColumnName("value_type"); - - b.HasKey("Id"); - - b.HasIndex("Key") - .IsUnique(); - - b.ToTable("app_settings", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.AppUser", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("AccessFailedCount") - .HasColumnType("integer"); - - b.Property("ConcurrencyStamp") - .IsConcurrencyToken() - .HasColumnType("text"); - - b.Property("CreatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.Property("DisplayName") - .IsRequired() - .HasMaxLength(200) - .HasColumnType("character varying(200)"); - - b.Property("Email") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.Property("EmailConfirmed") - .HasColumnType("boolean"); - - b.Property("Language") - .IsRequired() - .ValueGeneratedOnAdd() - .HasMaxLength(10) - .IsUnicode(false) - .HasColumnType("character varying(10)") - .HasDefaultValue("fr"); - - b.Property("LockoutEnabled") - .HasColumnType("boolean"); - - b.Property("LockoutEnd") - .HasColumnType("timestamp with time zone"); - - b.Property("MustChangePassword") - .ValueGeneratedOnAdd() - .HasColumnType("boolean") - .HasDefaultValue(false); - - b.Property("NormalizedEmail") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.Property("NormalizedUserName") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.Property("PasswordHash") - .HasColumnType("text"); - - b.Property("PhoneNumber") - .HasColumnType("text"); - - b.Property("PhoneNumberConfirmed") - .HasColumnType("boolean"); - - b.Property("SecurityStamp") - .HasColumnType("text"); - - b.Property("Theme") - .ValueGeneratedOnAdd() - .HasMaxLength(20) - .IsUnicode(false) - .HasColumnType("character varying(20)") - .HasDefaultValue("Auto"); - - b.Property("TwoFactorEnabled") - .HasColumnType("boolean"); - - b.Property("UserName") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.HasKey("Id"); - - b.HasIndex("NormalizedEmail") - .HasDatabaseName("EmailIndex"); - - b.HasIndex("NormalizedUserName") - .IsUnique() - .HasDatabaseName("UserNameIndex"); - - b.ToTable("users", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.AuditLog", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("Action") - .IsRequired() - .HasMaxLength(100) - .IsUnicode(false) - .HasColumnType("character varying(100)"); - - b.Property("IpAddress") - .HasMaxLength(45) - .IsUnicode(false) - .HasColumnType("character varying(45)"); - - b.Property("NewValue") - .HasColumnType("text"); - - b.Property("OldValue") - .HasColumnType("text"); - - b.Property("ResourceId") - .HasMaxLength(100) - .IsUnicode(false) - .HasColumnType("character varying(100)"); - - b.Property("ResourceType") - .IsRequired() - .HasMaxLength(100) - .IsUnicode(false) - .HasColumnType("character varying(100)"); - - b.Property("Timestamp") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.Property("UserId") - .HasColumnType("uuid"); - - b.HasKey("Id"); - - b.HasIndex("Timestamp") - .IsDescending(); - - b.HasIndex("UserId"); - - b.HasIndex("ResourceType", "ResourceId", "Timestamp") - .IsDescending(false, false, true); - - b.ToTable("audit_logs", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.Camera", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("AgentId") - .HasColumnType("uuid"); - - b.Property("Capabilities") - .IsRequired() - .HasMaxLength(64) - .IsUnicode(false) - .HasColumnType("character varying(64)"); - - b.Property("CreatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.Property("DeletedAt") - .HasColumnType("timestamp with time zone"); - - b.Property("DetectedType") - .IsRequired() - .HasMaxLength(20) - .IsUnicode(false) - .HasColumnType("character varying(20)"); - - b.Property("DiscoveryMethod") - .IsRequired() - .HasMaxLength(20) - .IsUnicode(false) - .HasColumnType("character varying(20)"); - - b.Property("HasAudio") - .HasColumnType("boolean"); - - b.Property("HasMotionDetection") - .HasColumnType("boolean"); - - b.Property("HasPtz") - .HasColumnType("boolean"); - - b.Property("HttpPort") - .HasColumnType("integer"); - - b.Property("IpAddress") - .HasMaxLength(45) - .HasColumnType("character varying(45)"); - - b.Property("IsDeleted") - .HasColumnType("boolean"); - - b.Property("LastDiscoveredAt") - .HasColumnType("timestamp with time zone"); - - b.Property("LastStreamTestAt") - .HasColumnType("timestamp with time zone"); - - b.Property("LastTestedCodecs") - .HasMaxLength(200) - .IsUnicode(false) - .HasColumnType("character varying(200)"); - - b.Property("LastTestedHeight") - .HasColumnType("integer"); - - b.Property("LastTestedLatencyMs") - .HasColumnType("bigint"); - - b.Property("LastTestedWidth") - .HasColumnType("integer"); - - b.Property("MacAddress") - .HasMaxLength(17) - .HasColumnType("character varying(17)"); - - b.Property("Manufacturer") - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("Model") - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(200) - .IsUnicode(false) - .HasColumnType("character varying(200)"); - - b.Property("OnvifPort") - .HasColumnType("integer"); - - b.Property("RtspPort") - .HasColumnType("integer"); - - b.Property("RtspUrl") - .HasMaxLength(1000) - .IsUnicode(false) - .HasColumnType("character varying(1000)"); - - b.Property("SiteId") - .HasColumnType("uuid"); - - b.Property("Status") - .IsRequired() - .HasMaxLength(20) - .IsUnicode(false) - .HasColumnType("character varying(20)"); - - b.Property("SubRtspUrl") - .HasMaxLength(1000) - .IsUnicode(false) - .HasColumnType("character varying(1000)"); - - b.Property("UpdatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.HasKey("Id"); - - b.HasIndex("AgentId"); - - b.HasIndex("IpAddress"); - - b.HasIndex("MacAddress"); - - b.HasIndex("SiteId"); - - b.ToTable("cameras", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.CameraAssignment", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("AgentId") - .HasColumnType("uuid"); - - b.Property("AssignedAt") - .HasColumnType("timestamp with time zone"); - - b.Property("CameraId") - .HasColumnType("uuid"); - - b.Property("Reason") - .IsRequired() - .HasMaxLength(50) - .IsUnicode(false) - .HasColumnType("character varying(50)"); - - b.Property("ReleasedAt") - .HasColumnType("timestamp with time zone"); - - b.HasKey("Id"); - - b.HasIndex("AssignedAt"); - - b.HasIndex("AgentId", "ReleasedAt") - .HasFilter("\"ReleasedAt\" IS NULL"); - - b.HasIndex("CameraId", "ReleasedAt") - .IsUnique() - .HasFilter("\"ReleasedAt\" IS NULL"); - - b.ToTable("camera_assignments", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.CameraCredentials", b => - { - b.Property("CameraId") - .HasColumnType("uuid"); - - b.Property("CreatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.Property("OnvifPassword") - .IsRequired() - .HasMaxLength(500) - .IsUnicode(false) - .HasColumnType("character varying(500)"); - - b.Property("OnvifUsername") - .IsRequired() - .ValueGeneratedOnAdd() - .HasMaxLength(100) - .IsUnicode(false) - .HasColumnType("character varying(100)") - .HasDefaultValue("admin"); - - b.Property("RtspPassword") - .IsRequired() - .HasMaxLength(500) - .IsUnicode(false) - .HasColumnType("character varying(500)"); - - b.Property("RtspUsername") - .IsRequired() - .HasMaxLength(100) - .IsUnicode(false) - .HasColumnType("character varying(100)"); - - b.Property("UpdatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.HasKey("CameraId"); - - b.ToTable("camera_credentials", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.CameraDetectionProfile", b => - { - b.Property("CameraId") - .HasColumnType("uuid"); - - b.Property("ActiveIntervalMs") - .HasColumnType("integer"); - - b.Property("AnimalCooldownSec") - .HasColumnType("integer"); - - b.Property("DetectAnimal") - .HasColumnType("boolean"); - - b.Property("DetectMotion") - .HasColumnType("boolean"); - - b.Property("DetectPackage") - .HasColumnType("boolean"); - - b.Property("DetectPerson") - .HasColumnType("boolean"); - - b.Property("DetectVehicle") - .HasColumnType("boolean"); - - b.Property("FaceRecognition") - .HasColumnType("boolean"); - - b.Property("IdleIntervalMs") - .HasColumnType("integer"); - - b.Property("IoUThreshold") - .HasColumnType("double precision"); - - b.Property("LicensePlateRecognition") - .HasColumnType("boolean"); - - b.Property("MaxEventsPerMinute") - .HasColumnType("integer"); - - b.Property("MinConfidence") - .ValueGeneratedOnAdd() - .HasColumnType("double precision") - .HasDefaultValue(0.40000000000000002); - - b.Property("MotionIntervalMs") - .HasColumnType("integer"); - - b.Property("MotionThreshold") - .HasColumnType("double precision"); - - b.Property("PersonCooldownSec") - .HasColumnType("integer"); - - b.Property("RequireMotionForAI") - .HasColumnType("boolean"); - - b.Property("VehicleCooldownSec") - .HasColumnType("integer"); - - b.Property("YoloModel") - .IsRequired() - .ValueGeneratedOnAdd() - .HasMaxLength(50) - .IsUnicode(false) - .HasColumnType("character varying(50)") - .HasDefaultValue("yolov8n"); - - b.HasKey("CameraId"); - - b.ToTable("camera_detection_profiles", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.CameraDiscoveryResult", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("DetectedType") - .IsRequired() - .HasMaxLength(20) - .IsUnicode(false) - .HasColumnType("character varying(20)"); - - b.Property("DiscoveryMethod") - .IsRequired() - .HasMaxLength(20) - .IsUnicode(false) - .HasColumnType("character varying(20)"); - - b.Property("HomeKitDeviceId") - .HasMaxLength(50) - .IsUnicode(false) - .HasColumnType("character varying(50)"); - - b.Property("HomeKitModel") - .HasMaxLength(200) - .IsUnicode(false) - .HasColumnType("character varying(200)"); - - b.Property("HomeKitName") - .HasMaxLength(200) - .IsUnicode(false) - .HasColumnType("character varying(200)"); - - b.Property("Hostname") - .HasMaxLength(255) - .IsUnicode(false) - .HasColumnType("character varying(255)"); - - b.Property("HttpPort") - .HasColumnType("integer"); - - b.Property("HttpServerHeader") - .HasMaxLength(200) - .IsUnicode(false) - .HasColumnType("character varying(200)"); - - b.Property("HttpStatusCode") - .HasColumnType("integer"); - - b.Property("IpAddress") - .IsRequired() - .HasMaxLength(45) - .IsUnicode(false) - .HasColumnType("character varying(45)"); - - b.Property("IsHomeKitCamera") - .HasColumnType("boolean"); - - b.Property("IsProcessed") - .HasColumnType("boolean"); - - b.Property("IsReachable") - .HasColumnType("boolean"); - - b.Property("MacAddress") - .HasMaxLength(17) - .IsUnicode(false) - .HasColumnType("character varying(17)"); - - b.Property("OnvifDeviceServiceUrl") - .HasMaxLength(500) - .IsUnicode(false) - .HasColumnType("character varying(500)"); - - b.Property("OnvifHardware") - .HasMaxLength(200) - .IsUnicode(false) - .HasColumnType("character varying(200)"); - - b.Property("OnvifName") - .HasMaxLength(200) - .IsUnicode(false) - .HasColumnType("character varying(200)"); - - b.Property("OnvifPort") - .HasColumnType("integer"); - - b.PrimitiveCollection("OpenPorts") - .IsRequired() - .IsUnicode(false) - .HasColumnType("integer[]"); - - b.Property("ProbedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.Property("SiteId") - .HasColumnType("uuid"); - - b.Property("Vendor") - .HasMaxLength(100) - .IsUnicode(false) - .HasColumnType("character varying(100)"); - - b.HasKey("Id"); - - b.HasIndex("IpAddress"); - - b.HasIndex("IsProcessed"); - - b.HasIndex("SiteId"); - - b.ToTable("camera_discovery_results", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.CameraEvent", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("AgentId") - .HasColumnType("uuid"); - - b.Property("CameraId") - .HasColumnType("uuid"); - - b.Property("Confidence") - .ValueGeneratedOnAdd() - .HasColumnType("double precision") - .HasDefaultValue(0.0); - - b.Property("CreatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.Property("Label") - .HasMaxLength(200) - .IsUnicode(false) - .HasColumnType("character varying(200)"); - - b.Property("MetadataJson") - .HasColumnType("jsonb"); - - b.Property("OccurredAt") - .HasColumnType("timestamp with time zone"); - - b.Property("SnapshotThumbUrl") - .HasMaxLength(2000) - .IsUnicode(false) - .HasColumnType("character varying(2000)"); - - b.Property("SnapshotUrl") - .HasMaxLength(2000) - .IsUnicode(false) - .HasColumnType("character varying(2000)"); - - b.Property("Type") - .HasColumnType("integer"); - - b.Property("UpdatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.HasKey("Id"); - - b.HasIndex("OccurredAt"); - - b.HasIndex("CameraId", "OccurredAt") - .IsDescending(false, true); - - b.HasIndex("CameraId", "Type"); - - b.ToTable("camera_events", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.DiscoveredStreamUrl", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.PrimitiveCollection("Codecs") - .IsRequired() - .IsUnicode(false) - .HasColumnType("text[]"); - - b.Property("DiscoveryResultId") - .HasColumnType("uuid"); - - b.Property("Height") - .HasColumnType("integer"); - - b.Property("IsAlive") - .HasColumnType("boolean"); - - b.Property("IsMainStream") - .HasColumnType("boolean"); - - b.Property("LatencyMs") - .HasColumnType("bigint"); - - b.Property("Protocol") - .IsRequired() - .HasMaxLength(20) - .IsUnicode(false) - .HasColumnType("character varying(20)"); - - b.Property("Url") - .IsRequired() - .HasMaxLength(2000) - .IsUnicode(false) - .HasColumnType("character varying(2000)"); - - b.Property("Width") - .HasColumnType("integer"); - - b.HasKey("Id"); - - b.HasIndex("DiscoveryResultId"); - - b.HasIndex("IsAlive"); - - b.HasIndex("IsMainStream"); - - b.ToTable("discovered_streams", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.Group", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("CreatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.Property("DeletedAt") - .HasColumnType("timestamp with time zone"); - - b.Property("Description") - .HasMaxLength(1000) - .HasColumnType("character varying(1000)"); - - b.Property("IsDeleted") - .HasColumnType("boolean"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(200) - .HasColumnType("character varying(200)"); - - b.Property("UpdatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.HasKey("Id"); - - b.HasIndex("IsDeleted") - .HasFilter("\"IsDeleted\" = false"); - - b.HasIndex("Name"); - - b.ToTable("groups", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.Site", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("Address") - .HasMaxLength(500) - .HasColumnType("character varying(500)"); - - b.Property("CreatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.Property("DeletedAt") - .HasColumnType("timestamp with time zone"); - - b.Property("Enabled") - .HasColumnType("boolean"); - - b.Property("IsDeleted") - .HasColumnType("boolean"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(200) - .HasColumnType("character varying(200)"); - - b.Property("RegistrationTokenHash") - .HasMaxLength(128) - .IsUnicode(false) - .HasColumnType("character varying(128)"); - - b.Property("Timezone") - .IsRequired() - .ValueGeneratedOnAdd() - .HasMaxLength(100) - .IsUnicode(false) - .HasColumnType("character varying(100)") - .HasDefaultValue("UTC"); - - b.Property("TokenExpiresAt") - .HasColumnType("timestamp with time zone"); - - b.Property("UpdatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.HasKey("Id"); - - b.HasIndex("IsDeleted") - .HasFilter("\"IsDeleted\" = false"); - - b.HasIndex("Name"); - - b.ToTable("sites", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.UserGroup", b => - { - b.Property("UserId") - .HasColumnType("uuid"); - - b.Property("GroupId") - .HasColumnType("uuid"); - - b.HasKey("UserId", "GroupId"); - - b.HasIndex("GroupId"); - - b.ToTable("user_groups", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.UserSite", b => - { - b.Property("UserId") - .HasColumnType("uuid"); - - b.Property("SiteId") - .HasColumnType("uuid"); - - b.HasKey("UserId", "SiteId"); - - b.HasIndex("SiteId"); - - b.ToTable("user_sites", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("ClaimType") - .HasColumnType("text"); - - b.Property("ClaimValue") - .HasColumnType("text"); - - b.Property("RoleId") - .HasColumnType("uuid"); - - b.HasKey("Id"); - - b.HasIndex("RoleId"); - - b.ToTable("role_claims", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("ClaimType") - .HasColumnType("text"); - - b.Property("ClaimValue") - .HasColumnType("text"); - - b.Property("UserId") - .HasColumnType("uuid"); - - b.HasKey("Id"); - - b.HasIndex("UserId"); - - b.ToTable("user_claims", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => - { - b.Property("LoginProvider") - .HasColumnType("text"); - - b.Property("ProviderKey") - .HasColumnType("text"); - - b.Property("ProviderDisplayName") - .HasColumnType("text"); - - b.Property("UserId") - .HasColumnType("uuid"); - - b.HasKey("LoginProvider", "ProviderKey"); - - b.HasIndex("UserId"); - - b.ToTable("user_logins", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => - { - b.Property("UserId") - .HasColumnType("uuid"); - - b.Property("RoleId") - .HasColumnType("uuid"); - - b.HasKey("UserId", "RoleId"); - - b.HasIndex("RoleId"); - - b.ToTable("user_roles", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => - { - b.Property("UserId") - .HasColumnType("uuid"); - - b.Property("LoginProvider") - .HasColumnType("text"); - - b.Property("Name") - .HasColumnType("text"); - - b.Property("Value") - .HasColumnType("text"); - - b.HasKey("UserId", "LoginProvider", "Name"); - - b.ToTable("user_tokens", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.Agent", b => - { - b.HasOne("Heimdall.Domain.Entities.Site", "Site") - .WithMany("Agents") - .HasForeignKey("SiteId") - .OnDelete(DeleteBehavior.Restrict) - .IsRequired(); - - b.Navigation("Site"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.AgentSetting", b => - { - b.HasOne("Heimdall.Domain.Entities.Agent", "Agent") - .WithMany() - .HasForeignKey("AgentId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Agent"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.ApiKey", b => - { - b.HasOne("Heimdall.Domain.Entities.Site", "Site") - .WithMany() - .HasForeignKey("SiteId") - .OnDelete(DeleteBehavior.Restrict); - - b.Navigation("Site"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.AuditLog", b => - { - b.HasOne("Heimdall.Domain.Entities.AppUser", "User") - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.SetNull); - - b.Navigation("User"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.Camera", b => - { - b.HasOne("Heimdall.Domain.Entities.Agent", "Agent") - .WithMany("Cameras") - .HasForeignKey("AgentId") - .OnDelete(DeleteBehavior.SetNull); - - b.HasOne("Heimdall.Domain.Entities.Site", "Site") - .WithMany("Cameras") - .HasForeignKey("SiteId") - .OnDelete(DeleteBehavior.Restrict) - .IsRequired(); - - b.Navigation("Agent"); - - b.Navigation("Site"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.CameraAssignment", b => - { - b.HasOne("Heimdall.Domain.Entities.Agent", "Agent") - .WithMany() - .HasForeignKey("AgentId") - .OnDelete(DeleteBehavior.Restrict) - .IsRequired(); - - b.HasOne("Heimdall.Domain.Entities.Camera", "Camera") - .WithMany() - .HasForeignKey("CameraId") - .OnDelete(DeleteBehavior.Restrict) - .IsRequired(); - - b.Navigation("Agent"); - - b.Navigation("Camera"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.CameraCredentials", b => - { - b.HasOne("Heimdall.Domain.Entities.Camera", "Camera") - .WithOne("Credentials") - .HasForeignKey("Heimdall.Domain.Entities.CameraCredentials", "CameraId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Camera"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.CameraDetectionProfile", b => - { - b.HasOne("Heimdall.Domain.Entities.Camera", "Camera") - .WithOne("DetectionProfile") - .HasForeignKey("Heimdall.Domain.Entities.CameraDetectionProfile", "CameraId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Camera"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.CameraDiscoveryResult", b => - { - b.HasOne("Heimdall.Domain.Entities.Site", "Site") - .WithMany() - .HasForeignKey("SiteId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Site"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.CameraEvent", b => - { - b.HasOne("Heimdall.Domain.Entities.Camera", "Camera") - .WithMany() - .HasForeignKey("CameraId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Camera"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.DiscoveredStreamUrl", b => - { - b.HasOne("Heimdall.Domain.Entities.CameraDiscoveryResult", "DiscoveryResult") - .WithMany("DiscoveredStreams") - .HasForeignKey("DiscoveryResultId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("DiscoveryResult"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.UserGroup", b => - { - b.HasOne("Heimdall.Domain.Entities.Group", "Group") - .WithMany("UserGroups") - .HasForeignKey("GroupId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("Heimdall.Domain.Entities.AppUser", "User") - .WithMany("UserGroups") - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Group"); - - b.Navigation("User"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.UserSite", b => - { - b.HasOne("Heimdall.Domain.Entities.Site", "Site") - .WithMany() - .HasForeignKey("SiteId") - .OnDelete(DeleteBehavior.Restrict) - .IsRequired(); - - b.HasOne("Heimdall.Domain.Entities.AppUser", "User") - .WithMany("UserSites") - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Site"); - - b.Navigation("User"); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => - { - b.HasOne("Heimdall.Domain.Entities.AppRole", null) - .WithMany() - .HasForeignKey("RoleId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => - { - b.HasOne("Heimdall.Domain.Entities.AppUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => - { - b.HasOne("Heimdall.Domain.Entities.AppUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => - { - b.HasOne("Heimdall.Domain.Entities.AppRole", null) - .WithMany() - .HasForeignKey("RoleId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("Heimdall.Domain.Entities.AppUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => - { - b.HasOne("Heimdall.Domain.Entities.AppUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.Agent", b => - { - b.Navigation("Cameras"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.AppUser", b => - { - b.Navigation("UserGroups"); - - b.Navigation("UserSites"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.Camera", b => - { - b.Navigation("Credentials"); - - b.Navigation("DetectionProfile"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.CameraDiscoveryResult", b => - { - b.Navigation("DiscoveredStreams"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.Group", b => - { - b.Navigation("UserGroups"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.Site", b => - { - b.Navigation("Agents"); - - b.Navigation("Cameras"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/src/Heimdall.Infrastructure/Migrations/20260719125356_AddCameraEvents.cs b/src/Heimdall.Infrastructure/Migrations/20260719125356_AddCameraEvents.cs deleted file mode 100644 index caa2b8e..0000000 --- a/src/Heimdall.Infrastructure/Migrations/20260719125356_AddCameraEvents.cs +++ /dev/null @@ -1,66 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace Heimdall.Infrastructure.Migrations -{ - /// - public partial class AddCameraEvents : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "camera_events", - columns: table => new - { - Id = table.Column(type: "uuid", nullable: false), - CameraId = table.Column(type: "uuid", nullable: false), - AgentId = table.Column(type: "uuid", nullable: true), - Type = table.Column(type: "integer", nullable: false), - Confidence = table.Column(type: "double precision", nullable: false, defaultValue: 0.0), - Label = table.Column(type: "character varying(200)", unicode: false, maxLength: 200, nullable: true), - SnapshotUrl = table.Column(type: "character varying(2000)", unicode: false, maxLength: 2000, nullable: true), - SnapshotThumbUrl = table.Column(type: "character varying(2000)", unicode: false, maxLength: 2000, nullable: true), - MetadataJson = table.Column(type: "jsonb", nullable: true), - OccurredAt = table.Column(type: "timestamp with time zone", nullable: false), - CreatedAt = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "NOW()"), - UpdatedAt = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "NOW()") - }, - constraints: table => - { - table.PrimaryKey("PK_camera_events", x => x.Id); - table.ForeignKey( - name: "FK_camera_events_cameras_CameraId", - column: x => x.CameraId, - principalTable: "cameras", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateIndex( - name: "IX_camera_events_CameraId_OccurredAt", - table: "camera_events", - columns: new[] { "CameraId", "OccurredAt" }, - descending: new[] { false, true }); - - migrationBuilder.CreateIndex( - name: "IX_camera_events_CameraId_Type", - table: "camera_events", - columns: new[] { "CameraId", "Type" }); - - migrationBuilder.CreateIndex( - name: "IX_camera_events_OccurredAt", - table: "camera_events", - column: "OccurredAt"); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "camera_events"); - } - } -} diff --git a/src/Heimdall.Infrastructure/Migrations/20260719152833_AddPersonsAndKnownFaces.cs b/src/Heimdall.Infrastructure/Migrations/20260719152833_AddPersonsAndKnownFaces.cs deleted file mode 100644 index d09beba..0000000 --- a/src/Heimdall.Infrastructure/Migrations/20260719152833_AddPersonsAndKnownFaces.cs +++ /dev/null @@ -1,84 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace Heimdall.Infrastructure.Migrations -{ - /// - public partial class AddPersonsAndKnownFaces : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "persons", - columns: table => new - { - Id = table.Column(type: "uuid", nullable: false), - DisplayName = table.Column(type: "character varying(200)", maxLength: 200, nullable: false), - Notes = table.Column(type: "character varying(2000)", maxLength: 2000, nullable: true), - PhotoUrl = table.Column(type: "character varying(2000)", unicode: false, maxLength: 2000, nullable: true), - Category = table.Column(type: "character varying(50)", unicode: false, maxLength: 50, nullable: true), - IsWatchlisted = table.Column(type: "boolean", nullable: false), - CreatedAt = table.Column(type: "timestamp with time zone", nullable: false), - UpdatedAt = table.Column(type: "timestamp with time zone", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_persons", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "known_faces", - columns: table => new - { - Id = table.Column(type: "uuid", nullable: false), - PersonId = table.Column(type: "uuid", nullable: false), - ThumbnailUrl = table.Column(type: "character varying(2000)", unicode: false, maxLength: 2000, nullable: true), - Embedding = table.Column(type: "jsonb", nullable: false), - SourceEventId = table.Column(type: "character varying(100)", unicode: false, maxLength: 100, nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_known_faces", x => x.Id); - table.ForeignKey( - name: "FK_known_faces_persons_PersonId", - column: x => x.PersonId, - principalTable: "persons", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateIndex( - name: "IX_known_faces_PersonId", - table: "known_faces", - column: "PersonId"); - - migrationBuilder.CreateIndex( - name: "IX_persons_Category", - table: "persons", - column: "Category"); - - migrationBuilder.CreateIndex( - name: "IX_persons_DisplayName", - table: "persons", - column: "DisplayName"); - - migrationBuilder.CreateIndex( - name: "IX_persons_IsWatchlisted", - table: "persons", - column: "IsWatchlisted"); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "known_faces"); - - migrationBuilder.DropTable( - name: "persons"); - } - } -} diff --git a/src/Heimdall.Infrastructure/Migrations/20260719195445_AddCameraDiscoveryFields.Designer.cs b/src/Heimdall.Infrastructure/Migrations/20260719195445_AddCameraDiscoveryFields.Designer.cs deleted file mode 100644 index e9c8c6b..0000000 --- a/src/Heimdall.Infrastructure/Migrations/20260719195445_AddCameraDiscoveryFields.Designer.cs +++ /dev/null @@ -1,1548 +0,0 @@ -// -using System; -using Heimdall.Infrastructure.Data; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; - -#nullable disable - -namespace Heimdall.Infrastructure.Migrations -{ - [DbContext(typeof(AppDbContext))] - [Migration("20260719195445_AddCameraDiscoveryFields")] - partial class AddCameraDiscoveryFields - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "10.0.10") - .HasAnnotation("Relational:MaxIdentifierLength", 63); - - NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); - - modelBuilder.Entity("Heimdall.Domain.Entities.Agent", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("ApiKeyHash") - .HasMaxLength(128) - .IsUnicode(false) - .HasColumnType("character varying(128)"); - - b.Property("ApiKeyPrefix") - .HasMaxLength(8) - .IsUnicode(false) - .HasColumnType("character varying(8)"); - - b.Property("CpuCores") - .HasColumnType("integer"); - - b.Property("CreatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.Property("DeletedAt") - .HasColumnType("timestamp with time zone"); - - b.Property("GpuType") - .IsRequired() - .HasMaxLength(20) - .IsUnicode(false) - .HasColumnType("character varying(20)"); - - b.Property("HasGpu") - .HasColumnType("boolean"); - - b.Property("Hostname") - .IsRequired() - .HasMaxLength(255) - .IsUnicode(false) - .HasColumnType("character varying(255)"); - - b.Property("IsDeleted") - .HasColumnType("boolean"); - - b.Property("LastHeartbeat") - .HasColumnType("timestamp with time zone"); - - b.Property("MemoryMb") - .HasColumnType("bigint"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(200) - .IsUnicode(false) - .HasColumnType("character varying(200)"); - - b.Property("PublicIp") - .HasMaxLength(45) - .IsUnicode(false) - .HasColumnType("character varying(45)"); - - b.Property("SiteId") - .HasColumnType("uuid"); - - b.Property("Status") - .IsRequired() - .HasMaxLength(20) - .IsUnicode(false) - .HasColumnType("character varying(20)"); - - b.Property("UpdatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.Property("Version") - .IsRequired() - .HasMaxLength(50) - .IsUnicode(false) - .HasColumnType("character varying(50)"); - - b.HasKey("Id"); - - b.HasIndex("LastHeartbeat") - .HasFilter("\"Status\" = 'Online'"); - - b.HasIndex("SiteId"); - - b.ToTable("agents", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.AgentSetting", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("AgentId") - .HasColumnType("uuid") - .HasColumnName("agent_id"); - - b.Property("CreatedAt") - .HasColumnType("timestamp with time zone") - .HasColumnName("created_at"); - - b.Property("Key") - .IsRequired() - .HasMaxLength(200) - .HasColumnType("character varying(200)") - .HasColumnName("key"); - - b.Property("UpdatedAt") - .HasColumnType("timestamp with time zone") - .HasColumnName("updated_at"); - - b.Property("Value") - .IsRequired() - .HasColumnType("text") - .HasColumnName("value"); - - b.HasKey("Id"); - - b.HasIndex("AgentId", "Key") - .IsUnique(); - - b.ToTable("agent_settings", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.ApiKey", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("CreatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.Property("CreatedByUserId") - .HasColumnType("uuid"); - - b.Property("Enabled") - .HasColumnType("boolean"); - - b.Property("ExpiresAt") - .HasColumnType("timestamp with time zone"); - - b.Property("KeyHash") - .IsRequired() - .HasMaxLength(128) - .IsUnicode(false) - .HasColumnType("character varying(128)"); - - b.Property("KeyPrefix") - .IsRequired() - .HasMaxLength(8) - .IsUnicode(false) - .HasColumnType("character varying(8)"); - - b.Property("LastUsedAt") - .HasColumnType("timestamp with time zone"); - - b.Property("SiteId") - .HasColumnType("uuid"); - - b.HasKey("Id"); - - b.HasIndex("KeyHash"); - - b.HasIndex("KeyPrefix"); - - b.HasIndex("SiteId"); - - b.ToTable("api_keys", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.AppRole", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("ConcurrencyStamp") - .IsConcurrencyToken() - .HasColumnType("text"); - - b.Property("Name") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.Property("NormalizedName") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.HasKey("Id"); - - b.HasIndex("NormalizedName") - .IsUnique() - .HasDatabaseName("RoleNameIndex"); - - b.ToTable("roles", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.AppSetting", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("AllowedValues") - .HasMaxLength(2000) - .HasColumnType("character varying(2000)") - .HasColumnName("allowed_values"); - - b.Property("Category") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("character varying(100)") - .HasColumnName("category"); - - b.Property("CreatedAt") - .HasColumnType("timestamp with time zone") - .HasColumnName("created_at"); - - b.Property("Description") - .HasMaxLength(500) - .HasColumnType("character varying(500)") - .HasColumnName("description"); - - b.Property("Key") - .IsRequired() - .HasMaxLength(200) - .HasColumnType("character varying(200)") - .HasColumnName("key"); - - b.Property("UpdatedAt") - .HasColumnType("timestamp with time zone") - .HasColumnName("updated_at"); - - b.Property("Value") - .IsRequired() - .HasColumnType("text") - .HasColumnName("value"); - - b.Property("ValueType") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("character varying(50)") - .HasColumnName("value_type"); - - b.HasKey("Id"); - - b.HasIndex("Key") - .IsUnique(); - - b.ToTable("app_settings", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.AppUser", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("AccessFailedCount") - .HasColumnType("integer"); - - b.Property("ConcurrencyStamp") - .IsConcurrencyToken() - .HasColumnType("text"); - - b.Property("CreatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.Property("DisplayName") - .IsRequired() - .HasMaxLength(200) - .HasColumnType("character varying(200)"); - - b.Property("Email") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.Property("EmailConfirmed") - .HasColumnType("boolean"); - - b.Property("Language") - .IsRequired() - .ValueGeneratedOnAdd() - .HasMaxLength(10) - .IsUnicode(false) - .HasColumnType("character varying(10)") - .HasDefaultValue("fr"); - - b.Property("LockoutEnabled") - .HasColumnType("boolean"); - - b.Property("LockoutEnd") - .HasColumnType("timestamp with time zone"); - - b.Property("MustChangePassword") - .ValueGeneratedOnAdd() - .HasColumnType("boolean") - .HasDefaultValue(false); - - b.Property("NormalizedEmail") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.Property("NormalizedUserName") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.Property("PasswordHash") - .HasColumnType("text"); - - b.Property("PhoneNumber") - .HasColumnType("text"); - - b.Property("PhoneNumberConfirmed") - .HasColumnType("boolean"); - - b.Property("SecurityStamp") - .HasColumnType("text"); - - b.Property("Theme") - .ValueGeneratedOnAdd() - .HasMaxLength(20) - .IsUnicode(false) - .HasColumnType("character varying(20)") - .HasDefaultValue("Auto"); - - b.Property("TwoFactorEnabled") - .HasColumnType("boolean"); - - b.Property("UserName") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.HasKey("Id"); - - b.HasIndex("NormalizedEmail") - .HasDatabaseName("EmailIndex"); - - b.HasIndex("NormalizedUserName") - .IsUnique() - .HasDatabaseName("UserNameIndex"); - - b.ToTable("users", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.AuditLog", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("Action") - .IsRequired() - .HasMaxLength(100) - .IsUnicode(false) - .HasColumnType("character varying(100)"); - - b.Property("IpAddress") - .HasMaxLength(45) - .IsUnicode(false) - .HasColumnType("character varying(45)"); - - b.Property("NewValue") - .HasColumnType("text"); - - b.Property("OldValue") - .HasColumnType("text"); - - b.Property("ResourceId") - .HasMaxLength(100) - .IsUnicode(false) - .HasColumnType("character varying(100)"); - - b.Property("ResourceType") - .IsRequired() - .HasMaxLength(100) - .IsUnicode(false) - .HasColumnType("character varying(100)"); - - b.Property("Timestamp") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.Property("UserId") - .HasColumnType("uuid"); - - b.HasKey("Id"); - - b.HasIndex("Timestamp") - .IsDescending(); - - b.HasIndex("UserId"); - - b.HasIndex("ResourceType", "ResourceId", "Timestamp") - .IsDescending(false, false, true); - - b.ToTable("audit_logs", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.Camera", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("AgentId") - .HasColumnType("uuid"); - - b.Property("Capabilities") - .IsRequired() - .HasMaxLength(64) - .IsUnicode(false) - .HasColumnType("character varying(64)"); - - b.Property("CreatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.Property("DeletedAt") - .HasColumnType("timestamp with time zone"); - - b.Property("DetectedType") - .IsRequired() - .HasMaxLength(20) - .IsUnicode(false) - .HasColumnType("character varying(20)"); - - b.Property("DiscoveryMethod") - .IsRequired() - .HasMaxLength(20) - .IsUnicode(false) - .HasColumnType("character varying(20)"); - - b.Property("HasAudio") - .HasColumnType("boolean"); - - b.Property("HasMotionDetection") - .HasColumnType("boolean"); - - b.Property("HasPtz") - .HasColumnType("boolean"); - - b.Property("HttpPort") - .HasColumnType("integer"); - - b.Property("IpAddress") - .HasMaxLength(45) - .HasColumnType("character varying(45)"); - - b.Property("IsDeleted") - .HasColumnType("boolean"); - - b.Property("LastDiscoveredAt") - .HasColumnType("timestamp with time zone"); - - b.Property("LastStreamTestAt") - .HasColumnType("timestamp with time zone"); - - b.Property("LastTestedCodecs") - .HasMaxLength(200) - .IsUnicode(false) - .HasColumnType("character varying(200)"); - - b.Property("LastTestedHeight") - .HasColumnType("integer"); - - b.Property("LastTestedLatencyMs") - .HasColumnType("bigint"); - - b.Property("LastTestedWidth") - .HasColumnType("integer"); - - b.Property("MacAddress") - .HasMaxLength(17) - .HasColumnType("character varying(17)"); - - b.Property("Manufacturer") - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("Model") - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(200) - .IsUnicode(false) - .HasColumnType("character varying(200)"); - - b.Property("OnvifPort") - .HasColumnType("integer"); - - b.Property("RtspPort") - .HasColumnType("integer"); - - b.Property("RtspUrl") - .HasMaxLength(1000) - .IsUnicode(false) - .HasColumnType("character varying(1000)"); - - b.Property("SiteId") - .HasColumnType("uuid"); - - b.Property("Status") - .IsRequired() - .HasMaxLength(20) - .IsUnicode(false) - .HasColumnType("character varying(20)"); - - b.Property("SubRtspUrl") - .HasMaxLength(1000) - .IsUnicode(false) - .HasColumnType("character varying(1000)"); - - b.Property("UpdatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.HasKey("Id"); - - b.HasIndex("AgentId"); - - b.HasIndex("IpAddress"); - - b.HasIndex("MacAddress"); - - b.HasIndex("SiteId"); - - b.ToTable("cameras", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.CameraAssignment", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("AgentId") - .HasColumnType("uuid"); - - b.Property("AssignedAt") - .HasColumnType("timestamp with time zone"); - - b.Property("CameraId") - .HasColumnType("uuid"); - - b.Property("Reason") - .IsRequired() - .HasMaxLength(50) - .IsUnicode(false) - .HasColumnType("character varying(50)"); - - b.Property("ReleasedAt") - .HasColumnType("timestamp with time zone"); - - b.HasKey("Id"); - - b.HasIndex("AssignedAt"); - - b.HasIndex("AgentId", "ReleasedAt") - .HasFilter("\"ReleasedAt\" IS NULL"); - - b.HasIndex("CameraId", "ReleasedAt") - .IsUnique() - .HasFilter("\"ReleasedAt\" IS NULL"); - - b.ToTable("camera_assignments", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.CameraCredentials", b => - { - b.Property("CameraId") - .HasColumnType("uuid"); - - b.Property("CreatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.Property("OnvifPassword") - .IsRequired() - .HasMaxLength(500) - .IsUnicode(false) - .HasColumnType("character varying(500)"); - - b.Property("OnvifUsername") - .IsRequired() - .ValueGeneratedOnAdd() - .HasMaxLength(100) - .IsUnicode(false) - .HasColumnType("character varying(100)") - .HasDefaultValue("admin"); - - b.Property("RtspPassword") - .IsRequired() - .HasMaxLength(500) - .IsUnicode(false) - .HasColumnType("character varying(500)"); - - b.Property("RtspUsername") - .IsRequired() - .HasMaxLength(100) - .IsUnicode(false) - .HasColumnType("character varying(100)"); - - b.Property("UpdatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.HasKey("CameraId"); - - b.ToTable("camera_credentials", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.CameraDetectionProfile", b => - { - b.Property("CameraId") - .HasColumnType("uuid"); - - b.Property("ActiveIntervalMs") - .HasColumnType("integer"); - - b.Property("AnimalCooldownSec") - .HasColumnType("integer"); - - b.Property("DetectAnimal") - .HasColumnType("boolean"); - - b.Property("DetectMotion") - .HasColumnType("boolean"); - - b.Property("DetectPackage") - .HasColumnType("boolean"); - - b.Property("DetectPerson") - .HasColumnType("boolean"); - - b.Property("DetectVehicle") - .HasColumnType("boolean"); - - b.Property("FaceRecognition") - .HasColumnType("boolean"); - - b.Property("IdleIntervalMs") - .HasColumnType("integer"); - - b.Property("IoUThreshold") - .HasColumnType("double precision"); - - b.Property("LicensePlateRecognition") - .HasColumnType("boolean"); - - b.Property("MaxEventsPerMinute") - .HasColumnType("integer"); - - b.Property("MinConfidence") - .ValueGeneratedOnAdd() - .HasColumnType("double precision") - .HasDefaultValue(0.40000000000000002); - - b.Property("MotionIntervalMs") - .HasColumnType("integer"); - - b.Property("MotionThreshold") - .HasColumnType("double precision"); - - b.Property("PersonCooldownSec") - .HasColumnType("integer"); - - b.Property("RequireMotionForAI") - .HasColumnType("boolean"); - - b.Property("VehicleCooldownSec") - .HasColumnType("integer"); - - b.Property("YoloModel") - .IsRequired() - .ValueGeneratedOnAdd() - .HasMaxLength(50) - .IsUnicode(false) - .HasColumnType("character varying(50)") - .HasDefaultValue("yolov8n"); - - b.HasKey("CameraId"); - - b.ToTable("camera_detection_profiles", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.CameraDiscoveryResult", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("DetectedType") - .IsRequired() - .HasMaxLength(20) - .IsUnicode(false) - .HasColumnType("character varying(20)"); - - b.Property("DiscoveryMethod") - .IsRequired() - .HasMaxLength(20) - .IsUnicode(false) - .HasColumnType("character varying(20)"); - - b.Property("HomeKitDeviceId") - .HasMaxLength(50) - .IsUnicode(false) - .HasColumnType("character varying(50)"); - - b.Property("HomeKitModel") - .HasMaxLength(200) - .IsUnicode(false) - .HasColumnType("character varying(200)"); - - b.Property("HomeKitName") - .HasMaxLength(200) - .IsUnicode(false) - .HasColumnType("character varying(200)"); - - b.Property("Hostname") - .HasMaxLength(255) - .IsUnicode(false) - .HasColumnType("character varying(255)"); - - b.Property("HttpPort") - .HasColumnType("integer"); - - b.Property("HttpServerHeader") - .HasMaxLength(200) - .IsUnicode(false) - .HasColumnType("character varying(200)"); - - b.Property("HttpStatusCode") - .HasColumnType("integer"); - - b.Property("IpAddress") - .IsRequired() - .HasMaxLength(45) - .IsUnicode(false) - .HasColumnType("character varying(45)"); - - b.Property("IsHomeKitCamera") - .HasColumnType("boolean"); - - b.Property("IsProcessed") - .HasColumnType("boolean"); - - b.Property("IsReachable") - .HasColumnType("boolean"); - - b.Property("MacAddress") - .HasMaxLength(17) - .IsUnicode(false) - .HasColumnType("character varying(17)"); - - b.Property("OnvifDeviceServiceUrl") - .HasMaxLength(500) - .IsUnicode(false) - .HasColumnType("character varying(500)"); - - b.Property("OnvifHardware") - .HasMaxLength(200) - .IsUnicode(false) - .HasColumnType("character varying(200)"); - - b.Property("OnvifName") - .HasMaxLength(200) - .IsUnicode(false) - .HasColumnType("character varying(200)"); - - b.Property("OnvifPort") - .HasColumnType("integer"); - - b.PrimitiveCollection("OpenPorts") - .IsRequired() - .IsUnicode(false) - .HasColumnType("integer[]"); - - b.Property("ProbedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.Property("SiteId") - .HasColumnType("uuid"); - - b.Property("Vendor") - .HasMaxLength(100) - .IsUnicode(false) - .HasColumnType("character varying(100)"); - - b.HasKey("Id"); - - b.HasIndex("IpAddress"); - - b.HasIndex("IsProcessed"); - - b.HasIndex("SiteId"); - - b.ToTable("camera_discovery_results", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.CameraEvent", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("AgentId") - .HasColumnType("uuid"); - - b.Property("CameraId") - .HasColumnType("uuid"); - - b.Property("Confidence") - .ValueGeneratedOnAdd() - .HasColumnType("double precision") - .HasDefaultValue(0.0); - - b.Property("CreatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.Property("Label") - .HasMaxLength(200) - .IsUnicode(false) - .HasColumnType("character varying(200)"); - - b.Property("MetadataJson") - .HasColumnType("jsonb"); - - b.Property("OccurredAt") - .HasColumnType("timestamp with time zone"); - - b.Property("SnapshotThumbUrl") - .HasMaxLength(2000) - .IsUnicode(false) - .HasColumnType("character varying(2000)"); - - b.Property("SnapshotUrl") - .HasMaxLength(2000) - .IsUnicode(false) - .HasColumnType("character varying(2000)"); - - b.Property("Type") - .HasColumnType("integer"); - - b.Property("UpdatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.HasKey("Id"); - - b.HasIndex("OccurredAt"); - - b.HasIndex("CameraId", "OccurredAt") - .IsDescending(false, true); - - b.HasIndex("CameraId", "Type"); - - b.ToTable("camera_events", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.DiscoveredStreamUrl", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.PrimitiveCollection("Codecs") - .IsRequired() - .IsUnicode(false) - .HasColumnType("text[]"); - - b.Property("DiscoveryResultId") - .HasColumnType("uuid"); - - b.Property("Height") - .HasColumnType("integer"); - - b.Property("IsAlive") - .HasColumnType("boolean"); - - b.Property("IsMainStream") - .HasColumnType("boolean"); - - b.Property("LatencyMs") - .HasColumnType("bigint"); - - b.Property("Protocol") - .IsRequired() - .HasMaxLength(20) - .IsUnicode(false) - .HasColumnType("character varying(20)"); - - b.Property("Url") - .IsRequired() - .HasMaxLength(2000) - .IsUnicode(false) - .HasColumnType("character varying(2000)"); - - b.Property("Width") - .HasColumnType("integer"); - - b.HasKey("Id"); - - b.HasIndex("DiscoveryResultId"); - - b.HasIndex("IsAlive"); - - b.HasIndex("IsMainStream"); - - b.ToTable("discovered_streams", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.Group", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("CreatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.Property("DeletedAt") - .HasColumnType("timestamp with time zone"); - - b.Property("Description") - .HasMaxLength(1000) - .HasColumnType("character varying(1000)"); - - b.Property("IsDeleted") - .HasColumnType("boolean"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(200) - .HasColumnType("character varying(200)"); - - b.Property("UpdatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.HasKey("Id"); - - b.HasIndex("IsDeleted") - .HasFilter("\"IsDeleted\" = false"); - - b.HasIndex("Name"); - - b.ToTable("groups", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.KnownFace", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("Embedding") - .IsRequired() - .HasColumnType("jsonb"); - - b.Property("PersonId") - .HasColumnType("uuid"); - - b.Property("SourceEventId") - .HasMaxLength(100) - .IsUnicode(false) - .HasColumnType("character varying(100)"); - - b.Property("ThumbnailUrl") - .HasMaxLength(2000) - .IsUnicode(false) - .HasColumnType("character varying(2000)"); - - b.HasKey("Id"); - - b.HasIndex("PersonId"); - - b.ToTable("known_faces", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.Person", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("Category") - .HasMaxLength(50) - .IsUnicode(false) - .HasColumnType("character varying(50)"); - - b.Property("CreatedAt") - .HasColumnType("timestamp with time zone"); - - b.Property("DisplayName") - .IsRequired() - .HasMaxLength(200) - .HasColumnType("character varying(200)"); - - b.Property("IsWatchlisted") - .HasColumnType("boolean"); - - b.Property("Notes") - .HasMaxLength(2000) - .HasColumnType("character varying(2000)"); - - b.Property("PhotoUrl") - .HasMaxLength(2000) - .IsUnicode(false) - .HasColumnType("character varying(2000)"); - - b.Property("UpdatedAt") - .HasColumnType("timestamp with time zone"); - - b.HasKey("Id"); - - b.HasIndex("Category"); - - b.HasIndex("DisplayName"); - - b.HasIndex("IsWatchlisted"); - - b.ToTable("persons", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.Site", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("Address") - .HasMaxLength(500) - .HasColumnType("character varying(500)"); - - b.Property("CreatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.Property("DeletedAt") - .HasColumnType("timestamp with time zone"); - - b.Property("Enabled") - .HasColumnType("boolean"); - - b.Property("IsDeleted") - .HasColumnType("boolean"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(200) - .HasColumnType("character varying(200)"); - - b.Property("RegistrationTokenHash") - .HasMaxLength(128) - .IsUnicode(false) - .HasColumnType("character varying(128)"); - - b.Property("Timezone") - .IsRequired() - .ValueGeneratedOnAdd() - .HasMaxLength(100) - .IsUnicode(false) - .HasColumnType("character varying(100)") - .HasDefaultValue("UTC"); - - b.Property("TokenExpiresAt") - .HasColumnType("timestamp with time zone"); - - b.Property("UpdatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("NOW()"); - - b.HasKey("Id"); - - b.HasIndex("IsDeleted") - .HasFilter("\"IsDeleted\" = false"); - - b.HasIndex("Name"); - - b.ToTable("sites", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.UserGroup", b => - { - b.Property("UserId") - .HasColumnType("uuid"); - - b.Property("GroupId") - .HasColumnType("uuid"); - - b.HasKey("UserId", "GroupId"); - - b.HasIndex("GroupId"); - - b.ToTable("user_groups", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.UserSite", b => - { - b.Property("UserId") - .HasColumnType("uuid"); - - b.Property("SiteId") - .HasColumnType("uuid"); - - b.HasKey("UserId", "SiteId"); - - b.HasIndex("SiteId"); - - b.ToTable("user_sites", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("ClaimType") - .HasColumnType("text"); - - b.Property("ClaimValue") - .HasColumnType("text"); - - b.Property("RoleId") - .HasColumnType("uuid"); - - b.HasKey("Id"); - - b.HasIndex("RoleId"); - - b.ToTable("role_claims", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("ClaimType") - .HasColumnType("text"); - - b.Property("ClaimValue") - .HasColumnType("text"); - - b.Property("UserId") - .HasColumnType("uuid"); - - b.HasKey("Id"); - - b.HasIndex("UserId"); - - b.ToTable("user_claims", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => - { - b.Property("LoginProvider") - .HasColumnType("text"); - - b.Property("ProviderKey") - .HasColumnType("text"); - - b.Property("ProviderDisplayName") - .HasColumnType("text"); - - b.Property("UserId") - .HasColumnType("uuid"); - - b.HasKey("LoginProvider", "ProviderKey"); - - b.HasIndex("UserId"); - - b.ToTable("user_logins", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => - { - b.Property("UserId") - .HasColumnType("uuid"); - - b.Property("RoleId") - .HasColumnType("uuid"); - - b.HasKey("UserId", "RoleId"); - - b.HasIndex("RoleId"); - - b.ToTable("user_roles", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => - { - b.Property("UserId") - .HasColumnType("uuid"); - - b.Property("LoginProvider") - .HasColumnType("text"); - - b.Property("Name") - .HasColumnType("text"); - - b.Property("Value") - .HasColumnType("text"); - - b.HasKey("UserId", "LoginProvider", "Name"); - - b.ToTable("user_tokens", (string)null); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.Agent", b => - { - b.HasOne("Heimdall.Domain.Entities.Site", "Site") - .WithMany("Agents") - .HasForeignKey("SiteId") - .OnDelete(DeleteBehavior.Restrict) - .IsRequired(); - - b.Navigation("Site"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.AgentSetting", b => - { - b.HasOne("Heimdall.Domain.Entities.Agent", "Agent") - .WithMany() - .HasForeignKey("AgentId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Agent"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.ApiKey", b => - { - b.HasOne("Heimdall.Domain.Entities.Site", "Site") - .WithMany() - .HasForeignKey("SiteId") - .OnDelete(DeleteBehavior.Restrict); - - b.Navigation("Site"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.AuditLog", b => - { - b.HasOne("Heimdall.Domain.Entities.AppUser", "User") - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.SetNull); - - b.Navigation("User"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.Camera", b => - { - b.HasOne("Heimdall.Domain.Entities.Agent", "Agent") - .WithMany("Cameras") - .HasForeignKey("AgentId") - .OnDelete(DeleteBehavior.SetNull); - - b.HasOne("Heimdall.Domain.Entities.Site", "Site") - .WithMany("Cameras") - .HasForeignKey("SiteId") - .OnDelete(DeleteBehavior.Restrict) - .IsRequired(); - - b.Navigation("Agent"); - - b.Navigation("Site"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.CameraAssignment", b => - { - b.HasOne("Heimdall.Domain.Entities.Agent", "Agent") - .WithMany() - .HasForeignKey("AgentId") - .OnDelete(DeleteBehavior.Restrict) - .IsRequired(); - - b.HasOne("Heimdall.Domain.Entities.Camera", "Camera") - .WithMany() - .HasForeignKey("CameraId") - .OnDelete(DeleteBehavior.Restrict) - .IsRequired(); - - b.Navigation("Agent"); - - b.Navigation("Camera"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.CameraCredentials", b => - { - b.HasOne("Heimdall.Domain.Entities.Camera", "Camera") - .WithOne("Credentials") - .HasForeignKey("Heimdall.Domain.Entities.CameraCredentials", "CameraId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Camera"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.CameraDetectionProfile", b => - { - b.HasOne("Heimdall.Domain.Entities.Camera", "Camera") - .WithOne("DetectionProfile") - .HasForeignKey("Heimdall.Domain.Entities.CameraDetectionProfile", "CameraId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Camera"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.CameraDiscoveryResult", b => - { - b.HasOne("Heimdall.Domain.Entities.Site", "Site") - .WithMany() - .HasForeignKey("SiteId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Site"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.CameraEvent", b => - { - b.HasOne("Heimdall.Domain.Entities.Camera", "Camera") - .WithMany() - .HasForeignKey("CameraId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Camera"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.DiscoveredStreamUrl", b => - { - b.HasOne("Heimdall.Domain.Entities.CameraDiscoveryResult", "DiscoveryResult") - .WithMany("DiscoveredStreams") - .HasForeignKey("DiscoveryResultId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("DiscoveryResult"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.KnownFace", b => - { - b.HasOne("Heimdall.Domain.Entities.Person", "Person") - .WithMany("Faces") - .HasForeignKey("PersonId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Person"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.UserGroup", b => - { - b.HasOne("Heimdall.Domain.Entities.Group", "Group") - .WithMany("UserGroups") - .HasForeignKey("GroupId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("Heimdall.Domain.Entities.AppUser", "User") - .WithMany("UserGroups") - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Group"); - - b.Navigation("User"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.UserSite", b => - { - b.HasOne("Heimdall.Domain.Entities.Site", "Site") - .WithMany() - .HasForeignKey("SiteId") - .OnDelete(DeleteBehavior.Restrict) - .IsRequired(); - - b.HasOne("Heimdall.Domain.Entities.AppUser", "User") - .WithMany("UserSites") - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Site"); - - b.Navigation("User"); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => - { - b.HasOne("Heimdall.Domain.Entities.AppRole", null) - .WithMany() - .HasForeignKey("RoleId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => - { - b.HasOne("Heimdall.Domain.Entities.AppUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => - { - b.HasOne("Heimdall.Domain.Entities.AppUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => - { - b.HasOne("Heimdall.Domain.Entities.AppRole", null) - .WithMany() - .HasForeignKey("RoleId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("Heimdall.Domain.Entities.AppUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => - { - b.HasOne("Heimdall.Domain.Entities.AppUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.Agent", b => - { - b.Navigation("Cameras"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.AppUser", b => - { - b.Navigation("UserGroups"); - - b.Navigation("UserSites"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.Camera", b => - { - b.Navigation("Credentials"); - - b.Navigation("DetectionProfile"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.CameraDiscoveryResult", b => - { - b.Navigation("DiscoveredStreams"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.Group", b => - { - b.Navigation("UserGroups"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.Person", b => - { - b.Navigation("Faces"); - }); - - modelBuilder.Entity("Heimdall.Domain.Entities.Site", b => - { - b.Navigation("Agents"); - - b.Navigation("Cameras"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/src/Heimdall.Infrastructure/Migrations/20260719195445_AddCameraDiscoveryFields.cs b/src/Heimdall.Infrastructure/Migrations/20260719195445_AddCameraDiscoveryFields.cs deleted file mode 100644 index d812516..0000000 --- a/src/Heimdall.Infrastructure/Migrations/20260719195445_AddCameraDiscoveryFields.cs +++ /dev/null @@ -1,202 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace Heimdall.Infrastructure.Migrations -{ - /// - public partial class AddCameraDiscoveryFields : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.AddColumn( - name: "Capabilities", - table: "cameras", - type: "character varying(64)", - unicode: false, - maxLength: 64, - nullable: false, - defaultValue: "None"); - - migrationBuilder.AddColumn( - name: "DetectedType", - table: "cameras", - type: "character varying(20)", - unicode: false, - maxLength: 20, - nullable: false, - defaultValue: "Standard"); - - migrationBuilder.AddColumn( - name: "DiscoveryMethod", - table: "cameras", - type: "character varying(20)", - unicode: false, - maxLength: 20, - nullable: false, - defaultValue: "Manual"); - - migrationBuilder.AddColumn( - name: "HttpPort", - table: "cameras", - type: "integer", - nullable: true); - - migrationBuilder.AddColumn( - name: "IpAddress", - table: "cameras", - type: "character varying(45)", - maxLength: 45, - nullable: true); - - migrationBuilder.AddColumn( - name: "LastDiscoveredAt", - table: "cameras", - type: "timestamp with time zone", - nullable: true); - - migrationBuilder.AddColumn( - name: "LastStreamTestAt", - table: "cameras", - type: "timestamp with time zone", - nullable: true); - - migrationBuilder.AddColumn( - name: "LastTestedCodecs", - table: "cameras", - type: "character varying(200)", - unicode: false, - maxLength: 200, - nullable: true); - - migrationBuilder.AddColumn( - name: "LastTestedHeight", - table: "cameras", - type: "integer", - nullable: true); - - migrationBuilder.AddColumn( - name: "LastTestedLatencyMs", - table: "cameras", - type: "bigint", - nullable: true); - - migrationBuilder.AddColumn( - name: "LastTestedWidth", - table: "cameras", - type: "integer", - nullable: true); - - migrationBuilder.AddColumn( - name: "MacAddress", - table: "cameras", - type: "character varying(17)", - maxLength: 17, - nullable: true); - - migrationBuilder.AddColumn( - name: "OnvifPort", - table: "cameras", - type: "integer", - nullable: true); - - migrationBuilder.AddColumn( - name: "RtspPort", - table: "cameras", - type: "integer", - nullable: true); - - migrationBuilder.AddColumn( - name: "SubRtspUrl", - table: "cameras", - type: "character varying(1000)", - unicode: false, - maxLength: 1000, - nullable: true); - - migrationBuilder.CreateIndex( - name: "IX_cameras_IpAddress", - table: "cameras", - column: "IpAddress"); - - migrationBuilder.CreateIndex( - name: "IX_cameras_MacAddress", - table: "cameras", - column: "MacAddress"); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropIndex( - name: "IX_cameras_IpAddress", - table: "cameras"); - - migrationBuilder.DropIndex( - name: "IX_cameras_MacAddress", - table: "cameras"); - - migrationBuilder.DropColumn( - name: "Capabilities", - table: "cameras"); - - migrationBuilder.DropColumn( - name: "DetectedType", - table: "cameras"); - - migrationBuilder.DropColumn( - name: "DiscoveryMethod", - table: "cameras"); - - migrationBuilder.DropColumn( - name: "HttpPort", - table: "cameras"); - - migrationBuilder.DropColumn( - name: "IpAddress", - table: "cameras"); - - migrationBuilder.DropColumn( - name: "LastDiscoveredAt", - table: "cameras"); - - migrationBuilder.DropColumn( - name: "LastStreamTestAt", - table: "cameras"); - - migrationBuilder.DropColumn( - name: "LastTestedCodecs", - table: "cameras"); - - migrationBuilder.DropColumn( - name: "LastTestedHeight", - table: "cameras"); - - migrationBuilder.DropColumn( - name: "LastTestedLatencyMs", - table: "cameras"); - - migrationBuilder.DropColumn( - name: "LastTestedWidth", - table: "cameras"); - - migrationBuilder.DropColumn( - name: "MacAddress", - table: "cameras"); - - migrationBuilder.DropColumn( - name: "OnvifPort", - table: "cameras"); - - migrationBuilder.DropColumn( - name: "RtspPort", - table: "cameras"); - - migrationBuilder.DropColumn( - name: "SubRtspUrl", - table: "cameras"); - } - } -} diff --git a/src/Heimdall.Infrastructure/Migrations/20260719152833_AddPersonsAndKnownFaces.Designer.cs b/src/Heimdall.Infrastructure/Migrations/20260720094830_InitialCreate.Designer.cs similarity index 99% rename from src/Heimdall.Infrastructure/Migrations/20260719152833_AddPersonsAndKnownFaces.Designer.cs rename to src/Heimdall.Infrastructure/Migrations/20260720094830_InitialCreate.Designer.cs index 90cb097..ace27c1 100644 --- a/src/Heimdall.Infrastructure/Migrations/20260719152833_AddPersonsAndKnownFaces.Designer.cs +++ b/src/Heimdall.Infrastructure/Migrations/20260720094830_InitialCreate.Designer.cs @@ -12,15 +12,15 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; namespace Heimdall.Infrastructure.Migrations { [DbContext(typeof(AppDbContext))] - [Migration("20260719152833_AddPersonsAndKnownFaces")] - partial class AddPersonsAndKnownFaces + [Migration("20260720094830_InitialCreate")] + partial class InitialCreate { /// protected override void BuildTargetModel(ModelBuilder modelBuilder) { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("ProductVersion", "10.0.10") + .HasAnnotation("ProductVersion", "10.0.8") .HasAnnotation("Relational:MaxIdentifierLength", 63); NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); diff --git a/src/Heimdall.Infrastructure/Migrations/20260716204205_InitialCreate.cs b/src/Heimdall.Infrastructure/Migrations/20260720094830_InitialCreate.cs similarity index 51% rename from src/Heimdall.Infrastructure/Migrations/20260716204205_InitialCreate.cs rename to src/Heimdall.Infrastructure/Migrations/20260720094830_InitialCreate.cs index 0ff46fb..31fb7b0 100644 --- a/src/Heimdall.Infrastructure/Migrations/20260716204205_InitialCreate.cs +++ b/src/Heimdall.Infrastructure/Migrations/20260720094830_InitialCreate.cs @@ -13,22 +13,57 @@ namespace Heimdall.Infrastructure.Migrations protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.CreateTable( - name: "audit_logs", + name: "app_settings", columns: table => new { Id = table.Column(type: "uuid", nullable: false), - UserId = table.Column(type: "uuid", nullable: true), - Action = table.Column(type: "character varying(100)", maxLength: 100, nullable: false), - ResourceType = table.Column(type: "character varying(100)", maxLength: 100, nullable: false), - ResourceId = table.Column(type: "character varying(100)", maxLength: 100, nullable: true), - OldValue = table.Column(type: "text", nullable: true), - NewValue = table.Column(type: "text", nullable: true), - IpAddress = table.Column(type: "character varying(45)", maxLength: 45, nullable: true), - Timestamp = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "NOW()") + key = table.Column(type: "character varying(200)", maxLength: 200, nullable: false), + value = table.Column(type: "text", nullable: false), + description = table.Column(type: "character varying(500)", maxLength: 500, nullable: true), + category = table.Column(type: "character varying(100)", maxLength: 100, nullable: false), + value_type = table.Column(type: "character varying(50)", maxLength: 50, nullable: false), + allowed_values = table.Column(type: "character varying(2000)", maxLength: 2000, nullable: true), + created_at = table.Column(type: "timestamp with time zone", nullable: false), + updated_at = table.Column(type: "timestamp with time zone", nullable: false) }, constraints: table => { - table.PrimaryKey("PK_audit_logs", x => x.Id); + table.PrimaryKey("PK_app_settings", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "groups", + columns: table => new + { + Id = table.Column(type: "uuid", nullable: false), + Name = table.Column(type: "character varying(200)", maxLength: 200, nullable: false), + Description = table.Column(type: "character varying(1000)", maxLength: 1000, nullable: true), + CreatedAt = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "NOW()"), + UpdatedAt = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "NOW()"), + IsDeleted = table.Column(type: "boolean", nullable: false), + DeletedAt = table.Column(type: "timestamp with time zone", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_groups", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "persons", + columns: table => new + { + Id = table.Column(type: "uuid", nullable: false), + DisplayName = table.Column(type: "character varying(200)", maxLength: 200, nullable: false), + Notes = table.Column(type: "character varying(2000)", maxLength: 2000, nullable: true), + PhotoUrl = table.Column(type: "character varying(2000)", unicode: false, maxLength: 2000, nullable: true), + Category = table.Column(type: "character varying(50)", unicode: false, maxLength: 50, nullable: true), + IsWatchlisted = table.Column(type: "boolean", nullable: false), + CreatedAt = table.Column(type: "timestamp with time zone", nullable: false), + UpdatedAt = table.Column(type: "timestamp with time zone", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_persons", x => x.Id); }); migrationBuilder.CreateTable( @@ -52,9 +87,9 @@ namespace Heimdall.Infrastructure.Migrations Id = table.Column(type: "uuid", nullable: false), Name = table.Column(type: "character varying(200)", maxLength: 200, nullable: false), Address = table.Column(type: "character varying(500)", maxLength: 500, nullable: true), - Timezone = table.Column(type: "character varying(100)", maxLength: 100, nullable: false, defaultValue: "UTC"), + Timezone = table.Column(type: "character varying(100)", unicode: false, maxLength: 100, nullable: false, defaultValue: "UTC"), Enabled = table.Column(type: "boolean", nullable: false), - RegistrationTokenHash = table.Column(type: "character varying(128)", maxLength: 128, nullable: true), + RegistrationTokenHash = table.Column(type: "character varying(128)", unicode: false, maxLength: 128, nullable: true), TokenExpiresAt = table.Column(type: "timestamp with time zone", nullable: true), CreatedAt = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "NOW()"), UpdatedAt = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "NOW()"), @@ -72,9 +107,10 @@ namespace Heimdall.Infrastructure.Migrations { Id = table.Column(type: "uuid", nullable: false), DisplayName = table.Column(type: "character varying(200)", maxLength: 200, nullable: false), - Theme = table.Column(type: "character varying(20)", maxLength: 20, nullable: true, defaultValue: "Auto"), - Language = table.Column(type: "character varying(10)", maxLength: 10, nullable: false, defaultValue: "fr"), + Theme = table.Column(type: "character varying(20)", unicode: false, maxLength: 20, nullable: true, defaultValue: "Auto"), + Language = table.Column(type: "character varying(10)", unicode: false, maxLength: 10, nullable: false, defaultValue: "fr"), CreatedAt = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "NOW()"), + MustChangePassword = table.Column(type: "boolean", nullable: false, defaultValue: false), UserName = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), NormalizedUserName = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), Email = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), @@ -95,6 +131,27 @@ namespace Heimdall.Infrastructure.Migrations table.PrimaryKey("PK_users", x => x.Id); }); + migrationBuilder.CreateTable( + name: "known_faces", + columns: table => new + { + Id = table.Column(type: "uuid", nullable: false), + PersonId = table.Column(type: "uuid", nullable: false), + ThumbnailUrl = table.Column(type: "character varying(2000)", unicode: false, maxLength: 2000, nullable: true), + Embedding = table.Column(type: "jsonb", nullable: false), + SourceEventId = table.Column(type: "character varying(100)", unicode: false, maxLength: 100, nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_known_faces", x => x.Id); + table.ForeignKey( + name: "FK_known_faces_persons_PersonId", + column: x => x.PersonId, + principalTable: "persons", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + migrationBuilder.CreateTable( name: "role_claims", columns: table => new @@ -122,18 +179,18 @@ namespace Heimdall.Infrastructure.Migrations { Id = table.Column(type: "uuid", nullable: false), SiteId = table.Column(type: "uuid", nullable: false), - Name = table.Column(type: "character varying(200)", maxLength: 200, nullable: false), - Hostname = table.Column(type: "character varying(255)", maxLength: 255, nullable: false), - Version = table.Column(type: "character varying(50)", maxLength: 50, nullable: false), - Status = table.Column(type: "character varying(20)", maxLength: 20, nullable: false), + Name = table.Column(type: "character varying(200)", unicode: false, maxLength: 200, nullable: false), + Hostname = table.Column(type: "character varying(255)", unicode: false, maxLength: 255, nullable: false), + Version = table.Column(type: "character varying(50)", unicode: false, maxLength: 50, nullable: false), + Status = table.Column(type: "character varying(20)", unicode: false, maxLength: 20, nullable: false), LastHeartbeat = table.Column(type: "timestamp with time zone", nullable: true), - PublicIp = table.Column(type: "character varying(45)", maxLength: 45, nullable: true), - ApiKeyHash = table.Column(type: "character varying(128)", maxLength: 128, nullable: true), - ApiKeyPrefix = table.Column(type: "character varying(8)", maxLength: 8, nullable: true), + PublicIp = table.Column(type: "character varying(45)", unicode: false, maxLength: 45, nullable: true), + ApiKeyHash = table.Column(type: "character varying(128)", unicode: false, maxLength: 128, nullable: true), + ApiKeyPrefix = table.Column(type: "character varying(8)", unicode: false, maxLength: 8, nullable: true), HasGpu = table.Column(type: "boolean", nullable: false), CpuCores = table.Column(type: "integer", nullable: false), MemoryMb = table.Column(type: "bigint", nullable: false), - GpuType = table.Column(type: "character varying(20)", maxLength: 20, nullable: false), + GpuType = table.Column(type: "character varying(20)", unicode: false, maxLength: 20, nullable: false), CreatedAt = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "NOW()"), UpdatedAt = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "NOW()"), IsDeleted = table.Column(type: "boolean", nullable: false), @@ -155,8 +212,8 @@ namespace Heimdall.Infrastructure.Migrations columns: table => new { Id = table.Column(type: "uuid", nullable: false), - KeyHash = table.Column(type: "character varying(128)", maxLength: 128, nullable: false), - KeyPrefix = table.Column(type: "character varying(8)", maxLength: 8, nullable: false), + KeyHash = table.Column(type: "character varying(128)", unicode: false, maxLength: 128, nullable: false), + KeyPrefix = table.Column(type: "character varying(8)", unicode: false, maxLength: 8, nullable: false), SiteId = table.Column(type: "uuid", nullable: true), CreatedByUserId = table.Column(type: "uuid", nullable: true), CreatedAt = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "NOW()"), @@ -175,6 +232,70 @@ namespace Heimdall.Infrastructure.Migrations onDelete: ReferentialAction.Restrict); }); + migrationBuilder.CreateTable( + name: "camera_discovery_results", + columns: table => new + { + Id = table.Column(type: "uuid", nullable: false), + SiteId = table.Column(type: "uuid", nullable: false), + IpAddress = table.Column(type: "character varying(45)", unicode: false, maxLength: 45, nullable: false), + MacAddress = table.Column(type: "character varying(17)", unicode: false, maxLength: 17, nullable: true), + Vendor = table.Column(type: "character varying(100)", unicode: false, maxLength: 100, nullable: true), + Hostname = table.Column(type: "character varying(255)", unicode: false, maxLength: 255, nullable: true), + IsReachable = table.Column(type: "boolean", nullable: false), + DetectedType = table.Column(type: "character varying(20)", unicode: false, maxLength: 20, nullable: false), + DiscoveryMethod = table.Column(type: "character varying(20)", unicode: false, maxLength: 20, nullable: false), + OpenPorts = table.Column(type: "integer[]", unicode: false, nullable: false), + OnvifDeviceServiceUrl = table.Column(type: "character varying(500)", unicode: false, maxLength: 500, nullable: true), + OnvifName = table.Column(type: "character varying(200)", unicode: false, maxLength: 200, nullable: true), + OnvifHardware = table.Column(type: "character varying(200)", unicode: false, maxLength: 200, nullable: true), + OnvifPort = table.Column(type: "integer", nullable: true), + HttpServerHeader = table.Column(type: "character varying(200)", unicode: false, maxLength: 200, nullable: true), + HttpStatusCode = table.Column(type: "integer", nullable: true), + HttpPort = table.Column(type: "integer", nullable: true), + IsHomeKitCamera = table.Column(type: "boolean", nullable: true), + HomeKitName = table.Column(type: "character varying(200)", unicode: false, maxLength: 200, nullable: true), + HomeKitDeviceId = table.Column(type: "character varying(50)", unicode: false, maxLength: 50, nullable: true), + HomeKitModel = table.Column(type: "character varying(200)", unicode: false, maxLength: 200, nullable: true), + ProbedAt = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "NOW()"), + IsProcessed = table.Column(type: "boolean", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_camera_discovery_results", x => x.Id); + table.ForeignKey( + name: "FK_camera_discovery_results_sites_SiteId", + column: x => x.SiteId, + principalTable: "sites", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "audit_logs", + columns: table => new + { + Id = table.Column(type: "uuid", nullable: false), + UserId = table.Column(type: "uuid", nullable: true), + Action = table.Column(type: "character varying(100)", unicode: false, maxLength: 100, nullable: false), + ResourceType = table.Column(type: "character varying(100)", unicode: false, maxLength: 100, nullable: false), + ResourceId = table.Column(type: "character varying(100)", unicode: false, maxLength: 100, nullable: true), + OldValue = table.Column(type: "text", nullable: true), + NewValue = table.Column(type: "text", nullable: true), + IpAddress = table.Column(type: "character varying(45)", unicode: false, maxLength: 45, nullable: true), + Timestamp = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "NOW()") + }, + constraints: table => + { + table.PrimaryKey("PK_audit_logs", x => x.Id); + table.ForeignKey( + name: "FK_audit_logs_users_UserId", + column: x => x.UserId, + principalTable: "users", + principalColumn: "Id", + onDelete: ReferentialAction.SetNull); + }); + migrationBuilder.CreateTable( name: "user_claims", columns: table => new @@ -196,6 +317,30 @@ namespace Heimdall.Infrastructure.Migrations onDelete: ReferentialAction.Cascade); }); + migrationBuilder.CreateTable( + name: "user_groups", + columns: table => new + { + UserId = table.Column(type: "uuid", nullable: false), + GroupId = table.Column(type: "uuid", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_user_groups", x => new { x.UserId, x.GroupId }); + table.ForeignKey( + name: "FK_user_groups_groups_GroupId", + column: x => x.GroupId, + principalTable: "groups", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_user_groups_users_UserId", + column: x => x.UserId, + principalTable: "users", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + migrationBuilder.CreateTable( name: "user_logins", columns: table => new @@ -284,6 +429,28 @@ namespace Heimdall.Infrastructure.Migrations onDelete: ReferentialAction.Cascade); }); + migrationBuilder.CreateTable( + name: "agent_settings", + columns: table => new + { + Id = table.Column(type: "uuid", nullable: false), + agent_id = table.Column(type: "uuid", nullable: false), + key = table.Column(type: "character varying(200)", maxLength: 200, nullable: false), + value = table.Column(type: "text", nullable: false), + created_at = table.Column(type: "timestamp with time zone", nullable: false), + updated_at = table.Column(type: "timestamp with time zone", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_agent_settings", x => x.Id); + table.ForeignKey( + name: "FK_agent_settings_agents_agent_id", + column: x => x.agent_id, + principalTable: "agents", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + migrationBuilder.CreateTable( name: "cameras", columns: table => new @@ -291,11 +458,26 @@ namespace Heimdall.Infrastructure.Migrations Id = table.Column(type: "uuid", nullable: false), SiteId = table.Column(type: "uuid", nullable: false), AgentId = table.Column(type: "uuid", nullable: true), - Name = table.Column(type: "character varying(200)", maxLength: 200, nullable: false), + Name = table.Column(type: "character varying(200)", unicode: false, maxLength: 200, nullable: false), Manufacturer = table.Column(type: "character varying(100)", maxLength: 100, nullable: true), Model = table.Column(type: "character varying(100)", maxLength: 100, nullable: true), - RtspUrl = table.Column(type: "character varying(1000)", maxLength: 1000, nullable: true), - Status = table.Column(type: "character varying(20)", maxLength: 20, nullable: false), + RtspUrl = table.Column(type: "character varying(1000)", unicode: false, maxLength: 1000, nullable: true), + Status = table.Column(type: "character varying(20)", unicode: false, maxLength: 20, nullable: false), + DiscoveryMethod = table.Column(type: "character varying(20)", unicode: false, maxLength: 20, nullable: false), + DetectedType = table.Column(type: "character varying(20)", unicode: false, maxLength: 20, nullable: false), + IpAddress = table.Column(type: "character varying(45)", maxLength: 45, nullable: true), + MacAddress = table.Column(type: "character varying(17)", maxLength: 17, nullable: true), + RtspPort = table.Column(type: "integer", nullable: true), + HttpPort = table.Column(type: "integer", nullable: true), + OnvifPort = table.Column(type: "integer", nullable: true), + Capabilities = table.Column(type: "character varying(64)", unicode: false, maxLength: 64, nullable: false), + LastDiscoveredAt = table.Column(type: "timestamp with time zone", nullable: true), + SubRtspUrl = table.Column(type: "character varying(1000)", unicode: false, maxLength: 1000, nullable: true), + LastTestedCodecs = table.Column(type: "character varying(200)", unicode: false, maxLength: 200, nullable: true), + LastTestedWidth = table.Column(type: "integer", nullable: true), + LastTestedHeight = table.Column(type: "integer", nullable: true), + LastTestedLatencyMs = table.Column(type: "bigint", nullable: true), + LastStreamTestAt = table.Column(type: "timestamp with time zone", nullable: true), HasPtz = table.Column(type: "boolean", nullable: false), HasAudio = table.Column(type: "boolean", nullable: false), HasMotionDetection = table.Column(type: "boolean", nullable: false), @@ -321,15 +503,69 @@ namespace Heimdall.Infrastructure.Migrations onDelete: ReferentialAction.Restrict); }); + migrationBuilder.CreateTable( + name: "discovered_streams", + columns: table => new + { + Id = table.Column(type: "uuid", nullable: false), + DiscoveryResultId = table.Column(type: "uuid", nullable: false), + Url = table.Column(type: "character varying(2000)", unicode: false, maxLength: 2000, nullable: false), + Protocol = table.Column(type: "character varying(20)", unicode: false, maxLength: 20, nullable: false), + Codecs = table.Column(type: "text[]", unicode: false, nullable: false), + Width = table.Column(type: "integer", nullable: false), + Height = table.Column(type: "integer", nullable: false), + LatencyMs = table.Column(type: "bigint", nullable: false), + IsMainStream = table.Column(type: "boolean", nullable: false), + IsAlive = table.Column(type: "boolean", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_discovered_streams", x => x.Id); + table.ForeignKey( + name: "FK_discovered_streams_camera_discovery_results_DiscoveryResult~", + column: x => x.DiscoveryResultId, + principalTable: "camera_discovery_results", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "camera_assignments", + columns: table => new + { + Id = table.Column(type: "uuid", nullable: false), + CameraId = table.Column(type: "uuid", nullable: false), + AgentId = table.Column(type: "uuid", nullable: false), + Reason = table.Column(type: "character varying(50)", unicode: false, maxLength: 50, nullable: false), + AssignedAt = table.Column(type: "timestamp with time zone", nullable: false), + ReleasedAt = table.Column(type: "timestamp with time zone", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_camera_assignments", x => x.Id); + table.ForeignKey( + name: "FK_camera_assignments_agents_AgentId", + column: x => x.AgentId, + principalTable: "agents", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + table.ForeignKey( + name: "FK_camera_assignments_cameras_CameraId", + column: x => x.CameraId, + principalTable: "cameras", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + }); + migrationBuilder.CreateTable( name: "camera_credentials", columns: table => new { CameraId = table.Column(type: "uuid", nullable: false), - OnvifUsername = table.Column(type: "character varying(100)", maxLength: 100, nullable: false, defaultValue: "admin"), - OnvifPassword = table.Column(type: "character varying(500)", maxLength: 500, nullable: false), - RtspUsername = table.Column(type: "character varying(100)", maxLength: 100, nullable: false), - RtspPassword = table.Column(type: "character varying(500)", maxLength: 500, nullable: false), + OnvifUsername = table.Column(type: "character varying(100)", unicode: false, maxLength: 100, nullable: false, defaultValue: "admin"), + OnvifPassword = table.Column(type: "character varying(500)", unicode: false, maxLength: 500, nullable: false), + RtspUsername = table.Column(type: "character varying(100)", unicode: false, maxLength: 100, nullable: false), + RtspPassword = table.Column(type: "character varying(500)", unicode: false, maxLength: 500, nullable: false), CreatedAt = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "NOW()"), UpdatedAt = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "NOW()") }, @@ -360,7 +596,7 @@ namespace Heimdall.Infrastructure.Migrations MotionIntervalMs = table.Column(type: "integer", nullable: false), ActiveIntervalMs = table.Column(type: "integer", nullable: false), MotionThreshold = table.Column(type: "double precision", nullable: false), - YoloModel = table.Column(type: "character varying(50)", maxLength: 50, nullable: false, defaultValue: "yolov8n"), + YoloModel = table.Column(type: "character varying(50)", unicode: false, maxLength: 50, nullable: false, defaultValue: "yolov8n"), MinConfidence = table.Column(type: "double precision", nullable: false, defaultValue: 0.40000000000000002), RequireMotionForAI = table.Column(type: "boolean", nullable: false), IoUThreshold = table.Column(type: "double precision", nullable: false), @@ -380,6 +616,40 @@ namespace Heimdall.Infrastructure.Migrations onDelete: ReferentialAction.Cascade); }); + migrationBuilder.CreateTable( + name: "camera_events", + columns: table => new + { + Id = table.Column(type: "uuid", nullable: false), + CameraId = table.Column(type: "uuid", nullable: false), + AgentId = table.Column(type: "uuid", nullable: true), + Type = table.Column(type: "integer", nullable: false), + Confidence = table.Column(type: "double precision", nullable: false, defaultValue: 0.0), + Label = table.Column(type: "character varying(200)", unicode: false, maxLength: 200, nullable: true), + SnapshotUrl = table.Column(type: "character varying(2000)", unicode: false, maxLength: 2000, nullable: true), + SnapshotThumbUrl = table.Column(type: "character varying(2000)", unicode: false, maxLength: 2000, nullable: true), + MetadataJson = table.Column(type: "jsonb", nullable: true), + OccurredAt = table.Column(type: "timestamp with time zone", nullable: false), + CreatedAt = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "NOW()"), + UpdatedAt = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "NOW()") + }, + constraints: table => + { + table.PrimaryKey("PK_camera_events", x => x.Id); + table.ForeignKey( + name: "FK_camera_events_cameras_CameraId", + column: x => x.CameraId, + principalTable: "cameras", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_agent_settings_agent_id_key", + table: "agent_settings", + columns: new[] { "agent_id", "key" }, + unique: true); + migrationBuilder.CreateIndex( name: "IX_agents_LastHeartbeat", table: "agents", @@ -406,6 +676,12 @@ namespace Heimdall.Infrastructure.Migrations table: "api_keys", column: "SiteId"); + migrationBuilder.CreateIndex( + name: "IX_app_settings_key", + table: "app_settings", + column: "key", + unique: true); + migrationBuilder.CreateIndex( name: "IX_audit_logs_ResourceType_ResourceId_Timestamp", table: "audit_logs", @@ -423,16 +699,121 @@ namespace Heimdall.Infrastructure.Migrations table: "audit_logs", column: "UserId"); + migrationBuilder.CreateIndex( + name: "IX_camera_assignments_AgentId_ReleasedAt", + table: "camera_assignments", + columns: new[] { "AgentId", "ReleasedAt" }, + filter: "\"ReleasedAt\" IS NULL"); + + migrationBuilder.CreateIndex( + name: "IX_camera_assignments_AssignedAt", + table: "camera_assignments", + column: "AssignedAt"); + + migrationBuilder.CreateIndex( + name: "IX_camera_assignments_CameraId_ReleasedAt", + table: "camera_assignments", + columns: new[] { "CameraId", "ReleasedAt" }, + unique: true, + filter: "\"ReleasedAt\" IS NULL"); + + migrationBuilder.CreateIndex( + name: "IX_camera_discovery_results_IpAddress", + table: "camera_discovery_results", + column: "IpAddress"); + + migrationBuilder.CreateIndex( + name: "IX_camera_discovery_results_IsProcessed", + table: "camera_discovery_results", + column: "IsProcessed"); + + migrationBuilder.CreateIndex( + name: "IX_camera_discovery_results_SiteId", + table: "camera_discovery_results", + column: "SiteId"); + + migrationBuilder.CreateIndex( + name: "IX_camera_events_CameraId_OccurredAt", + table: "camera_events", + columns: new[] { "CameraId", "OccurredAt" }, + descending: new[] { false, true }); + + migrationBuilder.CreateIndex( + name: "IX_camera_events_CameraId_Type", + table: "camera_events", + columns: new[] { "CameraId", "Type" }); + + migrationBuilder.CreateIndex( + name: "IX_camera_events_OccurredAt", + table: "camera_events", + column: "OccurredAt"); + migrationBuilder.CreateIndex( name: "IX_cameras_AgentId", table: "cameras", column: "AgentId"); + migrationBuilder.CreateIndex( + name: "IX_cameras_IpAddress", + table: "cameras", + column: "IpAddress"); + + migrationBuilder.CreateIndex( + name: "IX_cameras_MacAddress", + table: "cameras", + column: "MacAddress"); + migrationBuilder.CreateIndex( name: "IX_cameras_SiteId", table: "cameras", column: "SiteId"); + migrationBuilder.CreateIndex( + name: "IX_discovered_streams_DiscoveryResultId", + table: "discovered_streams", + column: "DiscoveryResultId"); + + migrationBuilder.CreateIndex( + name: "IX_discovered_streams_IsAlive", + table: "discovered_streams", + column: "IsAlive"); + + migrationBuilder.CreateIndex( + name: "IX_discovered_streams_IsMainStream", + table: "discovered_streams", + column: "IsMainStream"); + + migrationBuilder.CreateIndex( + name: "IX_groups_IsDeleted", + table: "groups", + column: "IsDeleted", + filter: "\"IsDeleted\" = false"); + + migrationBuilder.CreateIndex( + name: "IX_groups_Name", + table: "groups", + column: "Name"); + + migrationBuilder.CreateIndex( + name: "IX_known_faces_PersonId", + table: "known_faces", + column: "PersonId"); + + migrationBuilder.CreateIndex( + name: "IX_persons_Category", + table: "persons", + column: "Category"); + + migrationBuilder.CreateIndex( + name: "IX_persons_DisplayName", + table: "persons", + column: "DisplayName"); + + migrationBuilder.CreateIndex( + name: "IX_persons_IsWatchlisted", + table: "persons", + column: "IsWatchlisted"); + migrationBuilder.CreateIndex( name: "IX_role_claims_RoleId", table: "role_claims", @@ -460,6 +841,11 @@ namespace Heimdall.Infrastructure.Migrations table: "user_claims", column: "UserId"); + migrationBuilder.CreateIndex( + name: "IX_user_groups_GroupId", + table: "user_groups", + column: "GroupId"); + migrationBuilder.CreateIndex( name: "IX_user_logins_UserId", table: "user_logins", @@ -490,24 +876,45 @@ namespace Heimdall.Infrastructure.Migrations /// protected override void Down(MigrationBuilder migrationBuilder) { + migrationBuilder.DropTable( + name: "agent_settings"); + migrationBuilder.DropTable( name: "api_keys"); + migrationBuilder.DropTable( + name: "app_settings"); + migrationBuilder.DropTable( name: "audit_logs"); + migrationBuilder.DropTable( + name: "camera_assignments"); + migrationBuilder.DropTable( name: "camera_credentials"); migrationBuilder.DropTable( name: "camera_detection_profiles"); + migrationBuilder.DropTable( + name: "camera_events"); + + migrationBuilder.DropTable( + name: "discovered_streams"); + + migrationBuilder.DropTable( + name: "known_faces"); + migrationBuilder.DropTable( name: "role_claims"); migrationBuilder.DropTable( name: "user_claims"); + migrationBuilder.DropTable( + name: "user_groups"); + migrationBuilder.DropTable( name: "user_logins"); @@ -523,6 +930,15 @@ namespace Heimdall.Infrastructure.Migrations migrationBuilder.DropTable( name: "cameras"); + migrationBuilder.DropTable( + name: "camera_discovery_results"); + + migrationBuilder.DropTable( + name: "persons"); + + migrationBuilder.DropTable( + name: "groups"); + migrationBuilder.DropTable( name: "roles"); diff --git a/src/Heimdall.Infrastructure/Migrations/AppDbContextModelSnapshot.cs b/src/Heimdall.Infrastructure/Migrations/AppDbContextModelSnapshot.cs index b981d02..a7674c5 100644 --- a/src/Heimdall.Infrastructure/Migrations/AppDbContextModelSnapshot.cs +++ b/src/Heimdall.Infrastructure/Migrations/AppDbContextModelSnapshot.cs @@ -17,7 +17,7 @@ namespace Heimdall.Infrastructure.Migrations { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("ProductVersion", "10.0.10") + .HasAnnotation("ProductVersion", "10.0.8") .HasAnnotation("Relational:MaxIdentifierLength", 63); NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); diff --git a/src/Heimdall.Infrastructure/Security/JwtService.cs b/src/Heimdall.Infrastructure/Security/JwtService.cs index f4df232..45d84e3 100644 --- a/src/Heimdall.Infrastructure/Security/JwtService.cs +++ b/src/Heimdall.Infrastructure/Security/JwtService.cs @@ -4,6 +4,7 @@ using System.Security.Cryptography; using System.Text; using Heimdall.Domain.Entities; using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Logging; using Microsoft.IdentityModel.Tokens; namespace Heimdall.Infrastructure.Security; @@ -19,10 +20,12 @@ public interface IJwtService public class JwtService : IJwtService { private readonly IConfiguration _configuration; + private readonly ILogger _logger; - public JwtService(IConfiguration configuration) + public JwtService(IConfiguration configuration, ILogger logger) { _configuration = configuration; + _logger = logger; } public (string token, DateTime expiresAt) GenerateAccessToken(AppUser user, IList roles, IList permissions) @@ -67,10 +70,11 @@ public class JwtService : IJwtService public ClaimsPrincipal? ValidateRefreshToken(string refreshToken) { - var key = new SymmetricSecurityKey( - Encoding.UTF8.GetBytes(_configuration["Jwt:RefreshKey"] - ?? _configuration["Jwt:Key"] - ?? throw new InvalidOperationException("JWT key is not configured"))); + var refreshKeyValue = _configuration["Jwt:RefreshKey"] + ?? throw new InvalidOperationException( + "Jwt:RefreshKey is not configured. " + + "It must be set separately from Jwt:Key (security requirement)."); + var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(refreshKeyValue)); try { @@ -87,8 +91,13 @@ public class JwtService : IJwtService ClockSkew = TimeSpan.Zero }, out _); } - catch + catch (Exception ex) when (ex is SecurityTokenExpiredException + or SecurityTokenInvalidSignatureException + or SecurityTokenInvalidIssuerException + or ArgumentException) { + _logger.LogWarning("Refresh token validation failed: {ExceptionType} — {Message}", + ex.GetType().Name, ex.Message); return null; } } @@ -101,8 +110,9 @@ public class JwtService : IJwtService var jwtToken = handler.ReadJwtToken(token); return jwtToken.Subject; } - catch + catch (Exception ex) when (ex is ArgumentException) { + _logger.LogWarning("Failed to read expired token: {Message}", ex.Message); return null; } } diff --git a/src/Heimdall.Infrastructure/Services/AgentService.cs b/src/Heimdall.Infrastructure/Services/AgentService.cs index 42124ba..2f56b59 100644 --- a/src/Heimdall.Infrastructure/Services/AgentService.cs +++ b/src/Heimdall.Infrastructure/Services/AgentService.cs @@ -106,11 +106,10 @@ public class AgentService : IAgentService var items = await query .Skip((page - 1) * pageSize) .Take(pageSize) - .Select(a => MapResponse(a)) .ToListAsync(ct); return ServiceResult>.Success( - new PagedResult(items, total, page, pageSize)); + new PagedResult(items.Select(a => MapResponse(a)).ToList(), total, page, pageSize)); } public async Task>> ListAllAsync( @@ -122,11 +121,10 @@ public class AgentService : IAgentService var items = await query .Skip((page - 1) * pageSize) .Take(pageSize) - .Select(a => MapResponse(a)) .ToListAsync(ct); return ServiceResult>.Success( - new PagedResult(items, total, page, pageSize)); + new PagedResult(items.Select(a => MapResponse(a)).ToList(), total, page, pageSize)); } private static AgentResponse MapResponse(Agent a) => new( diff --git a/src/Heimdall.Infrastructure/Services/AuthService.cs b/src/Heimdall.Infrastructure/Services/AuthService.cs index 5c355f0..6fca1a6 100644 --- a/src/Heimdall.Infrastructure/Services/AuthService.cs +++ b/src/Heimdall.Infrastructure/Services/AuthService.cs @@ -64,7 +64,7 @@ public class AuthService : IAuthService return await GenerateAuthResponseAsync(firstUser, ct); } - // ── Public registration enabled? ───────────────────────────────── + // ── Public registration enabled? (disabled by default) ──────────── var publicRegistrationSetting = await _db.AppSettings .FirstOrDefaultAsync(s => s.Key == AuthSettings.PublicRegistrationEnabled, ct); if (publicRegistrationSetting is not null && diff --git a/src/Heimdall.Infrastructure/Services/CameraService.cs b/src/Heimdall.Infrastructure/Services/CameraService.cs index ddd5139..3eba7b1 100644 --- a/src/Heimdall.Infrastructure/Services/CameraService.cs +++ b/src/Heimdall.Infrastructure/Services/CameraService.cs @@ -65,7 +65,7 @@ public class CameraService : ICameraService if (camera is null) return ServiceResult.NotFound("Camera not found"); - camera.Update(request.Name, null, null, request.RtspUrl); + camera.Update(request.Name, request.Manufacturer, request.Model, request.RtspUrl); if (request.Status.HasValue) camera.SetStatus(request.Status.Value); diff --git a/src/Heimdall.Infrastructure/Services/SnapshotService.cs b/src/Heimdall.Infrastructure/Services/SnapshotService.cs index 88ba29e..b982826 100644 --- a/src/Heimdall.Infrastructure/Services/SnapshotService.cs +++ b/src/Heimdall.Infrastructure/Services/SnapshotService.cs @@ -83,18 +83,9 @@ public sealed class SnapshotService : ISnapshotService private async Task PutObjectAsync(string key, byte[] data, string contentType, CancellationToken ct) { - var timestamp = DateTime.UtcNow; - var host = new Uri(_endpoint).Host; - - using var request = new HttpRequestMessage(HttpMethod.Put, $"{_endpoint}/{_bucket}/{key}") - { - Content = new ByteArrayContent(data) - }; - request.Content.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse(contentType); - - await SignRequestAsync(request, key, "PUT", timestamp, data.Length, contentType, ct); - // Retry S3 upload with exponential backoff (transient errors) + // NOTE: Each retry creates a fresh request with a fresh AWS Signature V4 timestamp + // to avoid RequestTimeTooSkewed errors on retries that span clock boundaries. var maxRetries = 3; HttpResponseMessage? response = null; for (int attempt = 1; attempt <= maxRetries; attempt++) @@ -102,8 +93,14 @@ public sealed class SnapshotService : ISnapshotService if (attempt > 1) await Task.Delay(TimeSpan.FromMilliseconds(100 * attempt), ct); response?.Dispose(); + // Create a brand-new request for each attempt with a fresh timestamp + var request = new HttpRequestMessage(HttpMethod.Put, $"{_endpoint}/{_bucket}/{key}"); + var timestamp = DateTime.UtcNow; request.Content = new ByteArrayContent(data); request.Content.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse(contentType); + + await SignRequestAsync(request, key, "PUT", timestamp, data.Length, contentType, ct); + response = await _httpClient.SendAsync(request, ct); if (response.IsSuccessStatusCode) break; diff --git a/src/Heimdall.Infrastructure/Services/StatsService.cs b/src/Heimdall.Infrastructure/Services/StatsService.cs index 9330718..df9453c 100644 --- a/src/Heimdall.Infrastructure/Services/StatsService.cs +++ b/src/Heimdall.Infrastructure/Services/StatsService.cs @@ -15,15 +15,25 @@ public class StatsService : IStatsService public async Task> GetStatsAsync(CancellationToken ct) { - var totalSites = await _db.Sites.CountAsync(ct); - var totalCameras = await _db.Cameras.CountAsync(ct); - var totalAgents = await _db.Agents.CountAsync(ct); - var onlineAgents = await _db.Agents.CountAsync(a => a.Status == AgentStatus.Online, ct); - var activeSites = await _db.Sites.CountAsync(s => s.Enabled, ct); - var camerasOnline = await _db.Cameras.CountAsync(c => c.Status == CameraStatus.Online, ct); + // Run all 7 count queries in parallel to minimize round-trip latency + var totalSitesTask = _db.Sites.CountAsync(ct); + var totalCamerasTask = _db.Cameras.CountAsync(ct); + var totalAgentsTask = _db.Agents.CountAsync(ct); + var onlineAgentsTask = _db.Agents.CountAsync(a => a.Status == AgentStatus.Online, ct); + var activeSitesTask = _db.Sites.CountAsync(s => s.Enabled, ct); + var camerasOnlineTask = _db.Cameras.CountAsync(c => c.Status == CameraStatus.Online, ct); + var totalUsersTask = _db.Users.CountAsync(ct); - // TotalUsers from Identity - var totalUsers = await _db.Users.CountAsync(ct); + await Task.WhenAll(totalSitesTask, totalCamerasTask, totalAgentsTask, + onlineAgentsTask, activeSitesTask, camerasOnlineTask, totalUsersTask); + + var totalSites = await totalSitesTask; + var totalCameras = await totalCamerasTask; + var totalAgents = await totalAgentsTask; + var onlineAgents = await onlineAgentsTask; + var activeSites = await activeSitesTask; + var camerasOnline = await camerasOnlineTask; + var totalUsers = await totalUsersTask; return ServiceResult.Success(new StatsResponse( totalSites, diff --git a/src/Heimdall.Web/Components/App.razor b/src/Heimdall.Web/Components/App.razor index 590a06b..27b1f2c 100644 --- a/src/Heimdall.Web/Components/App.razor +++ b/src/Heimdall.Web/Components/App.razor @@ -15,7 +15,29 @@ - + + + + + +
+
+
+ +

Une erreur est survenue

+

L'application a rencontré une erreur. Recharger la page pour réessayer.

+
+
+
+
+
+ +
+

Une erreur réseau est survenue. Tentative de reconnexion...

+ Reconnecter + Ignorer +
+ diff --git a/src/Heimdall.Web/Components/Pages/Admin/AllAgentsPage.razor b/src/Heimdall.Web/Components/Pages/Admin/AllAgentsPage.razor index 4d66e53..651ccde 100644 --- a/src/Heimdall.Web/Components/Pages/Admin/AllAgentsPage.razor +++ b/src/Heimdall.Web/Components/Pages/Admin/AllAgentsPage.razor @@ -130,7 +130,7 @@ else await Task.WhenAll(agentsTask, statsTask); - var result = agentsTask.Result; + var result = await agentsTask; if (result is not null) { _agents = result.Items; @@ -138,7 +138,7 @@ else _totalPages = Math.Max(1, (int)Math.Ceiling(result.TotalCount / (double)result.PageSize)); } - _agentStats = statsTask.Result; + _agentStats = await statsTask; } catch (Exception ex) { diff --git a/src/Heimdall.Web/Components/Pages/Admin/ClaimsPage.razor b/src/Heimdall.Web/Components/Pages/Admin/ClaimsPage.razor index 34b0aac..14bad26 100644 --- a/src/Heimdall.Web/Components/Pages/Admin/ClaimsPage.razor +++ b/src/Heimdall.Web/Components/Pages/Admin/ClaimsPage.razor @@ -84,8 +84,8 @@ else await Task.WhenAll(permissionsTask, rolesTask); - _permissions = permissionsTask.Result; - _roles = rolesTask.Result; + _permissions = await permissionsTask; + _roles = await rolesTask; _groupedPermissions = _permissions .GroupBy(p => string.IsNullOrEmpty(p.Category) ? "General" : p.Category) diff --git a/src/Heimdall.Web/Components/Pages/Error.razor b/src/Heimdall.Web/Components/Pages/Error.razor new file mode 100644 index 0000000..5c5e004 --- /dev/null +++ b/src/Heimdall.Web/Components/Pages/Error.razor @@ -0,0 +1,36 @@ +@page "/Error" +@layout MudBlazorLayout +@inject NavigationManager Navigation + +
+
+
+
+ +
+

Une erreur est survenue

+

Une erreur inattendue s'est produite. Veuillez réessayer.

+
+ +
+ + Retour au tableau de bord + +
+ + @if (Environment.IsDevelopment()) + { + + Consultez les logs serveur pour plus de détails sur cette erreur. + + } +
+
+ +@code { + [Inject] private IWebHostEnvironment Environment { get; set; } = null!; +} diff --git a/src/Heimdall.Web/Components/Pages/Login.razor b/src/Heimdall.Web/Components/Pages/Login.razor index 3b1d736..41e85a3 100644 --- a/src/Heimdall.Web/Components/Pages/Login.razor +++ b/src/Heimdall.Web/Components/Pages/Login.razor @@ -108,10 +108,10 @@ // Create middleware-level auth cookie so the ASP.NET Core // middleware recognizes the user on subsequent requests. - if (result.User is not null) + if (!string.IsNullOrEmpty(result.AccessToken)) { await AuthHelper.SignInAsync(JsRuntime, - AuthHelper.CreateSignInPayload(result.User)); + AuthHelper.CreateSignInPayload(result.AccessToken)); } Snackbar.Add("Connexion réussie", Severity.Success); diff --git a/src/Heimdall.Web/Components/Pages/Register.razor b/src/Heimdall.Web/Components/Pages/Register.razor index 8a33ca6..14f23d5 100644 --- a/src/Heimdall.Web/Components/Pages/Register.razor +++ b/src/Heimdall.Web/Components/Pages/Register.razor @@ -98,10 +98,10 @@ await AuthStateProvider.NotifyLoginAsync(result); // Create middleware-level auth cookie - if (result.User is not null) + if (!string.IsNullOrEmpty(result.AccessToken)) { await AuthHelper.SignInAsync(JsRuntime, - AuthHelper.CreateSignInPayload(result.User)); + AuthHelper.CreateSignInPayload(result.AccessToken)); } Snackbar.Add("Compte créé avec succès", Severity.Success); diff --git a/src/Heimdall.Web/Program.cs b/src/Heimdall.Web/Program.cs index c8db2b8..36c5f10 100644 --- a/src/Heimdall.Web/Program.cs +++ b/src/Heimdall.Web/Program.cs @@ -1,4 +1,6 @@ +using System.IdentityModel.Tokens.Jwt; using System.Security.Claims; +using System.Text; using Heimdall.Infrastructure.Security; using Heimdall.Web.Components; using Heimdall.Web.Services; @@ -6,6 +8,7 @@ using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Authentication.Cookies; using Microsoft.AspNetCore.Antiforgery; using Microsoft.AspNetCore.Components.Authorization; +using Microsoft.IdentityModel.Tokens; using MudBlazor.Services; // ── Sentry (GlitchTip) — DSN from env var only ─────────────────── @@ -111,42 +114,79 @@ app.MapRazorComponents() .AddInteractiveServerRenderMode(); // ── Cookie auth endpoints (called from Blazor via JS fetch) ─────── -// /_auth/signin — Creates an authentication cookie after successful API login +// /_auth/signin — Validates the JWT access token and creates an auth cookie // /_auth/signout — Clears the authentication cookie on logout +// +// IMPORTANT: The JWT is validated server-side — never trust client-supplied claims. + +var jwtKey = builder.Configuration["Jwt:Key"] + ?? Environment.GetEnvironmentVariable("JWT__KEY") + ?? throw new InvalidOperationException("JWT:Key is not configured"); +var jwtIssuer = builder.Configuration["Jwt:Issuer"] ?? Environment.GetEnvironmentVariable("JWT__ISSUER") ?? "heimdall"; +var jwtAudience = builder.Configuration["Jwt:Audience"] ?? Environment.GetEnvironmentVariable("JWT__AUDIENCE") ?? "heimdall-api"; app.MapPost("/_auth/signin", async (HttpContext httpContext, SignInRequest request, IAntiforgery antiforgery) => { if (!await antiforgery.IsRequestValidAsync(httpContext)) return Results.BadRequest(new { error = "Invalid anti-forgery token" }); - if (string.IsNullOrEmpty(request.Id) || string.IsNullOrEmpty(request.Email)) - return Results.BadRequest(new { error = "Id and Email are required" }); + if (string.IsNullOrEmpty(request.AccessToken)) + return Results.BadRequest(new { error = "AccessToken is required" }); - var claims = new List + // Validate the JWT server-side — extract claims from the validated token, not from client + try { - new(ClaimTypes.NameIdentifier, request.Id), - new(ClaimTypes.Email, request.Email), - new(ClaimTypes.Name, request.DisplayName ?? request.Email), - }; + var handler = new JwtSecurityTokenHandler(); + var validationParams = new TokenValidationParameters + { + ValidateIssuerSigningKey = true, + IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(jwtKey)), + ValidateIssuer = true, + ValidIssuer = jwtIssuer, + ValidateAudience = true, + ValidAudience = jwtAudience, + ValidateLifetime = true, + ClockSkew = TimeSpan.Zero + }; - if (request.Roles is not null) - { - foreach (var role in request.Roles) - claims.Add(new Claim(ClaimTypes.Role, role)); + var principal = handler.ValidateToken(request.AccessToken, validationParams, out _); - // Resolve permissions from roles (same mapping as JWT token generation) - var permissions = request.Roles - .SelectMany(r => AppPermissions.RolePermissions.TryGetValue(r, out var perms) ? perms : []) - .Distinct(); - foreach (var permission in permissions) - claims.Add(new Claim("permission", permission)); + // Extract claims from the validated JWT only + var userId = principal.FindFirst(ClaimTypes.NameIdentifier)?.Value; + var email = principal.FindFirst(ClaimTypes.Email)?.Value; + var displayName = principal.FindFirst(ClaimTypes.Name)?.Value; + + if (string.IsNullOrEmpty(userId) || string.IsNullOrEmpty(email)) + return Results.BadRequest(new { error = "Invalid token: missing user claims" }); + + // Re-build claims identity from validated token claims (never from client body) + var claims = new List + { + new(ClaimTypes.NameIdentifier, userId), + new(ClaimTypes.Email, email), + new(ClaimTypes.Name, displayName ?? email), + }; + + foreach (var role in principal.FindAll(ClaimTypes.Role)) + claims.Add(new Claim(ClaimTypes.Role, role.Value)); + + foreach (var permission in principal.FindAll("permission")) + claims.Add(new Claim("permission", permission.Value)); + + var identity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme); + var cookiePrincipal = new ClaimsPrincipal(identity); + + await httpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, cookiePrincipal); + return Results.Ok(); + } + catch (SecurityTokenExpiredException) + { + return Results.Unauthorized(); + } + catch (Exception ex) + { + return Results.BadRequest(new { error = $"Token validation failed: {ex.Message}" }); } - - var identity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme); - var principal = new ClaimsPrincipal(identity); - - await httpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, principal); - return Results.Ok(); }); app.MapPost("/_auth/signout", async (HttpContext httpContext, IAntiforgery antiforgery) => @@ -163,7 +203,4 @@ app.Run(); // ─── DTO for the cookie sign-in request ─────────────────────────── internal sealed record SignInRequest( - string Id, - string Email, - string? DisplayName, - IList? Roles); + string AccessToken); diff --git a/src/Heimdall.Web/Services/AuthHelper.cs b/src/Heimdall.Web/Services/AuthHelper.cs index c57e8b8..55595aa 100644 --- a/src/Heimdall.Web/Services/AuthHelper.cs +++ b/src/Heimdall.Web/Services/AuthHelper.cs @@ -11,12 +11,9 @@ internal static class AuthHelper await jsRuntime.InvokeVoidAsync("heimdallAuth.signIn", user); } - /// Creates a sign-in payload object from a user response. - public static object CreateSignInPayload(UserInfo user) => new + /// Creates a sign-in payload object with the JWT access token. + public static object CreateSignInPayload(string accessToken) => new { - id = user.Id.ToString(), - email = user.Email, - displayName = user.DisplayName, - roles = user.Roles + accessToken }; } diff --git a/src/Heimdall.Web/Services/HeimdallApiClient.cs b/src/Heimdall.Web/Services/HeimdallApiClient.cs index e18d107..efcf6bf 100644 --- a/src/Heimdall.Web/Services/HeimdallApiClient.cs +++ b/src/Heimdall.Web/Services/HeimdallApiClient.cs @@ -269,11 +269,12 @@ public class HeimdallApiClient return await client.GetFromJsonAsync($"api/cameras/{id}", Json); } - public async Task UpdateCameraAsync(Guid id, string name, string? rtspUrl, string? status) + public async Task UpdateCameraAsync(Guid id, string name, string? rtspUrl, string? status, + string? manufacturer = null, string? model = null) { var client = CreateClient(); var response = await client.PutAsJsonAsync($"api/cameras/{id}", - new { name, rtspUrl, status }, Json); + new { name, rtspUrl, status, manufacturer, model }, Json); return response.IsSuccessStatusCode; } diff --git a/src/Heimdall.Workers/Program.cs b/src/Heimdall.Workers/Program.cs index 275fe7f..e80b286 100644 --- a/src/Heimdall.Workers/Program.cs +++ b/src/Heimdall.Workers/Program.cs @@ -27,7 +27,10 @@ if (!string.IsNullOrEmpty(sentryDsn)) var connectionString = Environment.GetEnvironmentVariable("DATABASE_URL") ?? builder.Configuration.GetConnectionString("Default") - ?? "Host=localhost;Port=5432;Database=heimdall;Username=heimdall;Password=heimdall"; + ?? throw new InvalidOperationException( + "DATABASE_URL is not configured. Set the DATABASE_URL environment variable " + + "or configure a Default connection string in appsettings.json. " + + "Example: Host=host;Port=5432;Database=heimdall;Username=user;Password=password"); // ── Infrastructure ──────────────────────────────────────────────── builder.Services.AddInfrastructure(builder.Configuration, diff --git a/tests/Heimdall.Infrastructure.Tests/CameraAssignmentServiceTests.cs b/tests/Heimdall.Infrastructure.Tests/CameraAssignmentServiceTests.cs index f418832..ace3011 100644 --- a/tests/Heimdall.Infrastructure.Tests/CameraAssignmentServiceTests.cs +++ b/tests/Heimdall.Infrastructure.Tests/CameraAssignmentServiceTests.cs @@ -165,11 +165,9 @@ public class CameraAssignmentServiceTests { private static readonly Heimdall.Infrastructure.Data.Interceptors.AuditInterceptor Audit = new(); - private static readonly Heimdall.Infrastructure.Data.Interceptors.SoftDeleteInterceptor SoftDelete - = new(); - public AppDbContext CreateDbContext() => new(opts, Audit, SoftDelete); + public AppDbContext CreateDbContext() => new(opts, Audit); public Task CreateDbContextAsync(CancellationToken ct = default) - => Task.FromResult(new AppDbContext(opts, Audit, SoftDelete)); + => Task.FromResult(new AppDbContext(opts, Audit)); } } diff --git a/tests/Heimdall.Infrastructure.Tests/CameraEventServiceTests.cs b/tests/Heimdall.Infrastructure.Tests/CameraEventServiceTests.cs index 7b21b9b..aead998 100644 --- a/tests/Heimdall.Infrastructure.Tests/CameraEventServiceTests.cs +++ b/tests/Heimdall.Infrastructure.Tests/CameraEventServiceTests.cs @@ -188,11 +188,9 @@ public class CameraEventServiceTests { private static readonly Heimdall.Infrastructure.Data.Interceptors.AuditInterceptor Audit = new(); - private static readonly Heimdall.Infrastructure.Data.Interceptors.SoftDeleteInterceptor SoftDelete - = new(); - public AppDbContext CreateDbContext() => new(opts, Audit, SoftDelete); + public AppDbContext CreateDbContext() => new(opts, Audit); public Task CreateDbContextAsync(CancellationToken ct = default) - => Task.FromResult(new AppDbContext(opts, Audit, SoftDelete)); + => Task.FromResult(new AppDbContext(opts, Audit)); } } diff --git a/tests/Heimdall.IntegrationTests/Controllers/AuthControllerTests.cs b/tests/Heimdall.IntegrationTests/Controllers/AuthControllerTests.cs index 9ed1d36..435ec34 100644 --- a/tests/Heimdall.IntegrationTests/Controllers/AuthControllerTests.cs +++ b/tests/Heimdall.IntegrationTests/Controllers/AuthControllerTests.cs @@ -1,3 +1,4 @@ +using System.Net.Http.Headers; using System.Net.Http.Json; using Heimdall.IntegrationTests.Factories; using Shouldly; @@ -7,15 +8,69 @@ namespace Heimdall.IntegrationTests.Controllers; public class AuthControllerTests : IClassFixture { private readonly HttpClient _client; + private static readonly SemaphoreSlim _seedLock = new(1, 1); + private static bool _seeded; public AuthControllerTests(HeimdallWebApplicationFactory factory) { _client = factory.CreateClient(); } + /// + /// Seeds the public registration setting so non-first-user registrations work. + /// Registers the first admin user and creates the AppSetting via the API. + /// Runs once per test class (factory is shared). + /// + private async Task EnsurePublicRegistrationAsync() + { + if (_seeded) return; + await _seedLock.WaitAsync(); + try + { + if (_seeded) return; + + // First registration is auto-admin (no prior users in the InMemory DB) + var adminEmail = $"admin-{Guid.NewGuid()}@heimdall.test"; + var regResponse = await _client.PostAsJsonAsync("api/auth/register", new + { + email = adminEmail, + password = "TestPassword123!", + displayName = "Admin" + }); + regResponse.StatusCode.ShouldBe(System.Net.HttpStatusCode.OK); + + // Extract access token from the registration response + var authResult = await regResponse.Content.ReadFromJsonAsync(); + authResult.ShouldNotBeNull(); + + // Use admin token to create the public registration setting + var request = new HttpRequestMessage(HttpMethod.Post, "api/settings") + { + Content = JsonContent.Create(new + { + key = "auth.public-registration.enabled", + value = "true", + valueType = "boolean", + category = "Auth", + description = "Enable public registration" + }) + }; + request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", authResult.AccessToken); + var settingResponse = await _client.SendAsync(request); + + _seeded = true; + } + finally + { + _seedLock.Release(); + } + } + [Fact] public async Task Register_ValidRequest_ReturnsOk() { + await EnsurePublicRegistrationAsync(); + var response = await _client.PostAsJsonAsync("api/auth/register", new { email = $"test-{Guid.NewGuid()}@heimdall.test", @@ -29,6 +84,8 @@ public class AuthControllerTests : IClassFixture [Fact] public async Task Register_DuplicateEmail_ReturnsConflict() { + await EnsurePublicRegistrationAsync(); + var email = $"dup-{Guid.NewGuid()}@heimdall.test"; var first = await _client.PostAsJsonAsync("api/auth/register", new @@ -52,6 +109,8 @@ public class AuthControllerTests : IClassFixture [Fact] public async Task Login_ValidCredentials_ReturnsOk() { + await EnsurePublicRegistrationAsync(); + var email = $"login-{Guid.NewGuid()}@heimdall.test"; await _client.PostAsJsonAsync("api/auth/register", new { @@ -72,6 +131,8 @@ public class AuthControllerTests : IClassFixture [Fact] public async Task Login_InvalidPassword_ReturnsUnauthorized() { + await EnsurePublicRegistrationAsync(); + var email = $"badpwd-{Guid.NewGuid()}@heimdall.test"; await _client.PostAsJsonAsync("api/auth/register", new { @@ -88,4 +149,14 @@ public class AuthControllerTests : IClassFixture response.StatusCode.ShouldBe(System.Net.HttpStatusCode.Unauthorized); } + + /// DTO matching the API auth response for extracting the access token. + private sealed record AuthTestResponse( + string AccessToken, + string RefreshToken, + DateTime ExpiresAt, + bool Requires2fa, + UserInfo? User); + + private sealed record UserInfo(Guid Id, string Email, string DisplayName, IList? Roles); } diff --git a/tests/Heimdall.IntegrationTests/Controllers/SettingsControllerTests.cs b/tests/Heimdall.IntegrationTests/Controllers/SettingsControllerTests.cs index b47643e..55634a8 100644 --- a/tests/Heimdall.IntegrationTests/Controllers/SettingsControllerTests.cs +++ b/tests/Heimdall.IntegrationTests/Controllers/SettingsControllerTests.cs @@ -71,6 +71,9 @@ public class SettingsControllerTests : IClassFixture RegisterViewerAsync() { + // Ensure public registration is enabled (seed via an admin) + await EnsurePublicRegistrationAsync(); + var email = $"viewer-{Guid.NewGuid()}@heimdall.test"; var client = _factory.CreateClient(); var response = await client.PostAsJsonAsync("api/auth/register", new @@ -83,6 +86,42 @@ public class SettingsControllerTests : IClassFixtureSeeds the public registration setting via admin API (runs once per test class).
+ private async Task EnsurePublicRegistrationAsync() + { + if (_seeded) return; + lock (_seedLock) { if (_seeded) return; } + + var client = _factory.CreateClient(); + + // First registration is auto-admin (no prior users in the InMemory DB) + var adminEmail = $"seed-admin-{Guid.NewGuid()}@heimdall.test"; + var regResponse = await client.PostAsJsonAsync("api/auth/register-admin", new + { + email = adminEmail, + password = "AdminPwd123!", + displayName = "Seed Admin" + }); + var content = await regResponse.Content.ReadFromJsonAsync(JsonOptions); + var token = content.GetProperty("accessToken").GetString()!; + + // Use admin token to create the public registration setting + var adminClient = _factory.CreateClient(); + adminClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token); + await adminClient.PostAsJsonAsync("api/settings", new + { + key = "auth.public-registration.enabled", + value = "true", + valueType = "boolean", + category = "Auth" + }); + + _seeded = true; + } + /// /// Create a site + agent and return the agent ID. /// diff --git a/tests/Heimdall.IntegrationTests/Heimdall.IntegrationTests.csproj b/tests/Heimdall.IntegrationTests/Heimdall.IntegrationTests.csproj index 7cf658e..709c167 100644 --- a/tests/Heimdall.IntegrationTests/Heimdall.IntegrationTests.csproj +++ b/tests/Heimdall.IntegrationTests/Heimdall.IntegrationTests.csproj @@ -9,8 +9,8 @@ - - + +