From f9d34b1d61c3877c64828e23a0090f49c7418928 Mon Sep 17 00:00:00 2001 From: Jake Mannens Date: Fri, 29 Sep 2023 19:00:16 +1000 Subject: Updated DB schema --- HBContext.cs | 23 +++++++++++++++++++---- LocalPrincipal.cs | 9 ++++++--- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/HBContext.cs b/HBContext.cs index 705efe4..2e78b5a 100644 --- a/HBContext.cs +++ b/HBContext.cs @@ -9,6 +9,10 @@ enum HBObjectId { IngestTag = -2, } +enum LocalPrincipalId { + AdminUser = -1 +} + public static class HBObjectGuid { public static readonly Guid NsfwTag = new("EBDAD4F8-455A-4351-8017-1D4854D6FA38"); public static readonly Guid IngestTag = new("EA212801-5BCC-4C0E-814F-FB9D30DB58BC"); @@ -51,6 +55,10 @@ public class HBContext : DbContext { modelBuilder.Entity().ToTable("UploadedFiles"); modelBuilder.Entity().ToTable("SecurityPrincipals"); + modelBuilder.Entity() + .Property(o => o.Owner) + .HasDefaultValue(new SecurityIdentifier(WellKnownSidType.WorldSid)); + // Seed internal tag definitions // These should NEVER change modelBuilder.Entity().HasData(new TagDefinition[] { @@ -71,9 +79,10 @@ public class HBContext : DbContext { // Seed initial admin user modelBuilder.Entity().HasData(new LocalUser[] { new() { - Name = "admin", - Sid = new SecurityIdentifier("S-1-5-18"), - PasswordHash = LocalPrincipalProvider.HashPassword("admin") + LocalPrincipalId = (int) LocalPrincipalId.AdminUser, + Name = "admin", + Sid = new SecurityIdentifier("S-1-5-18"), + PasswordHash = LocalPrincipalProvider.HashPassword("admin") } }); @@ -81,12 +90,18 @@ public class HBContext : DbContext { // additional configuration, as seen below. modelBuilder.Entity() .HasMany(e => e.ImplicitTags) - .WithMany(); + .WithMany() + .UsingEntity(e => e.ToTable("ImplicitTags")); modelBuilder.Entity() .HasOne(m => m.CurrentUploadedFile) .WithOne() .HasForeignKey("CurrentUploadedFileId"); + + modelBuilder.Entity() + .HasMany(p => p.MemberOf) + .WithMany() + .UsingEntity(e => e.ToTable("SecurityPrincipalMemberships")); } protected override void ConfigureConventions(ModelConfigurationBuilder configurationBuilder) { diff --git a/LocalPrincipal.cs b/LocalPrincipal.cs index 36428ef..35ff310 100644 --- a/LocalPrincipal.cs +++ b/LocalPrincipal.cs @@ -1,13 +1,16 @@ using Microsoft.EntityFrameworkCore; +using System.ComponentModel.DataAnnotations.Schema; namespace HyperBooru; [Index(nameof(Name))] [Index(nameof(Sid))] public class LocalPrincipal : IPrincipal { - public string Name { get; set; } - public SecurityIdentifier Sid { get; set; } - public List MemberOf { get; set; } + [DatabaseGenerated(DatabaseGeneratedOption.Identity)] + public int LocalPrincipalId { get; set; } + public string Name { get; set; } + public SecurityIdentifier Sid { get; set; } + public List MemberOf { get; set; } } public class LocalUser : LocalPrincipal, IUser { -- cgit v1.3