diff options
| author | Jake Mannens <jake@asger.xyz> | 2023-09-29 19:00:16 +1000 |
|---|---|---|
| committer | Jake Mannens <jake@asger.xyz> | 2023-09-29 19:00:16 +1000 |
| commit | f9d34b1d61c3877c64828e23a0090f49c7418928 (patch) | |
| tree | 15451995acb2d74c6903cf0384f6cac616f5138d | |
| parent | e0cf80a5d0e2d6898b611892a331aa917b9370d9 (diff) | |
Updated DB schema
| -rw-r--r-- | HBContext.cs | 23 | ||||
| -rw-r--r-- | 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<UploadedFile>().ToTable("UploadedFiles"); modelBuilder.Entity<LocalPrincipal>().ToTable("SecurityPrincipals"); + modelBuilder.Entity<HBObject>() + .Property(o => o.Owner) + .HasDefaultValue(new SecurityIdentifier(WellKnownSidType.WorldSid)); + // Seed internal tag definitions // These should NEVER change modelBuilder.Entity<TagDefinition>().HasData(new TagDefinition[] { @@ -71,9 +79,10 @@ public class HBContext : DbContext { // Seed initial admin user modelBuilder.Entity<LocalUser>().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<TagDefinition>() .HasMany(e => e.ImplicitTags) - .WithMany(); + .WithMany() + .UsingEntity(e => e.ToTable("ImplicitTags")); modelBuilder.Entity<Media>() .HasOne(m => m.CurrentUploadedFile) .WithOne() .HasForeignKey<Media>("CurrentUploadedFileId"); + + modelBuilder.Entity<LocalPrincipal>() + .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<LocalGroup> MemberOf { get; set; } + [DatabaseGenerated(DatabaseGeneratedOption.Identity)] + public int LocalPrincipalId { get; set; } + public string Name { get; set; } + public SecurityIdentifier Sid { get; set; } + public List<LocalGroup> MemberOf { get; set; } } public class LocalUser : LocalPrincipal, IUser { |
