diff --git a/Data.SeaHavenIndustries/Auth/ApplicationDbContext.cs b/Data.SeaHavenIndustries/Auth/ApplicationDbContext.cs index c8b2369..342aa88 100644 --- a/Data.SeaHavenIndustries/Auth/ApplicationDbContext.cs +++ b/Data.SeaHavenIndustries/Auth/ApplicationDbContext.cs @@ -136,6 +136,24 @@ namespace Data.SeaHavenIndustries .HasForeignKey(w => w.PrimaryDispatchId) .OnDelete(DeleteBehavior.Restrict); + builder.Entity() + .HasOne(w => w.Account) + .WithMany() + .HasForeignKey(w => w.AccountId) + .OnDelete(DeleteBehavior.Restrict); + + builder.Entity() + .HasIndex(w => w.AccountId); + + builder.Entity() + .HasOne(u => u.Account) + .WithMany() + .HasForeignKey(u => u.AccountId) + .OnDelete(DeleteBehavior.Restrict); + + builder.Entity() + .HasIndex(u => u.AccountId); + builder.Entity() .HasIndex(c => c.NormalizedName) .IsUnique(); @@ -284,6 +302,10 @@ namespace Data.SeaHavenIndustries public string? Initials { get; set; } public string? Color { get; set; } public int? Type { get; set; } // 1 for users 0 for admin + /// Optional CRM account membership for server-derived media scope (SH-221). + public int? AccountId { get; set; } + [ForeignKey(nameof(AccountId))] + public virtual Accounts? Account { get; set; } public ICollection