using Microsoft.EntityFrameworkCore; namespace TheCr3w.Shared.Data; public class TheCr3wDbContext : DbContext { public TheCr3wDbContext(DbContextOptions options) : base(options) { } public DbSet Applications => Set(); public DbSet ApplicationPlatforms => Set(); public DbSet Releases => Set(); public DbSet InstallationReports => Set(); public DbSet ErrorReports => Set(); public DbSet DeploymentManifests => Set(); public DbSet DeploymentApprovals => Set(); public DbSet AuditEvents => Set(); public DbSet ExternalServers => Set(); protected override void OnModelCreating(ModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); // Złożony klucz główny dla application_platforms (app_id, platform) modelBuilder.Entity() .HasKey(ap => new { ap.AppId, ap.Platform }); modelBuilder.Entity() .HasOne(ap => ap.Application) .WithMany(a => a.Platforms) .HasForeignKey(ap => ap.AppId) .OnDelete(DeleteBehavior.Cascade); modelBuilder.Entity() .HasOne(r => r.Application) .WithMany(a => a.Releases) .HasForeignKey(r => r.AppId) .OnDelete(DeleteBehavior.Restrict); // Indeksy wydajnościowe modelBuilder.Entity() .HasIndex(r => new { r.AppId, r.Platform, r.Architecture, r.Channel, r.Status, r.VersionCode }); modelBuilder.Entity() .HasIndex(a => new { a.ResourceType, a.ResourceId }); modelBuilder.Entity() .HasIndex(a => a.CreatedAt); modelBuilder.Entity() .HasIndex(m => new { m.EnvironmentId, m.Status }); } }