From bedcb6b176130fc2c6bd4657c8af4d407b64c970 Mon Sep 17 00:00:00 2001 From: Jake Mannens Date: Thu, 28 Sep 2023 03:14:35 +1000 Subject: Updated DB schema and configured ACLs to use SIDs --- Migrations/20230920052204_Security.Designer.cs | 455 ------------------------- Migrations/20230920052204_Security.cs | 194 ----------- Migrations/HBContextModelSnapshot.cs | 125 +------ 3 files changed, 14 insertions(+), 760 deletions(-) delete mode 100644 Migrations/20230920052204_Security.Designer.cs delete mode 100644 Migrations/20230920052204_Security.cs (limited to 'Migrations') diff --git a/Migrations/20230920052204_Security.Designer.cs b/Migrations/20230920052204_Security.Designer.cs deleted file mode 100644 index 8640c30..0000000 --- a/Migrations/20230920052204_Security.Designer.cs +++ /dev/null @@ -1,455 +0,0 @@ -// -using System; -using HyperBooru; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; - -#nullable disable - -namespace HyperBooru.Migrations -{ - [DbContext(typeof(HBContext))] - [Migration("20230920052204_Security")] - partial class Security - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "7.0.10") - .HasAnnotation("Relational:MaxIdentifierLength", 63); - - NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); - - modelBuilder.Entity("HyperBooru.HBObject", b => - { - b.Property("ObjectId") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("ObjectId")); - - b.Property("Guid") - .HasColumnType("uuid"); - - b.HasKey("ObjectId"); - - b.HasIndex("Guid"); - - b.ToTable("Objects", (string)null); - - b.UseTptMappingStrategy(); - }); - - modelBuilder.Entity("HyperBooru.OcrData", b => - { - b.Property("OcrDataId") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("OcrDataId")); - - b.Property("MediaId") - .HasColumnType("integer"); - - b.Property("SearchableText") - .IsRequired() - .HasColumnType("text"); - - b.Property("Text") - .IsRequired() - .HasColumnType("text"); - - b.Property("Timestamp") - .HasColumnType("timestamp with time zone"); - - b.HasKey("OcrDataId"); - - b.HasIndex("MediaId") - .IsUnique(); - - b.ToTable("OcrData"); - }); - - modelBuilder.Entity("TagDefinitionTagDefinition", b => - { - b.Property("ImplicitTagsObjectId") - .HasColumnType("integer"); - - b.Property("TagDefinitionObjectId") - .HasColumnType("integer"); - - b.HasKey("ImplicitTagsObjectId", "TagDefinitionObjectId"); - - b.HasIndex("TagDefinitionObjectId"); - - b.ToTable("TagDefinitionTagDefinition"); - }); - - modelBuilder.Entity("HyperBooru.Acl", b => - { - b.HasBaseType("HyperBooru.HBObject"); - - b.Property("SubjectTempId1") - .HasColumnType("integer"); - - b.ToTable("Acls"); - }); - - modelBuilder.Entity("HyperBooru.AclRule", b => - { - b.HasBaseType("HyperBooru.HBObject"); - - b.Property("AclObjectId") - .HasColumnType("integer"); - - b.Property("Action") - .HasColumnType("integer"); - - b.Property("Permissions") - .HasColumnType("bigint"); - - b.Property("PrincipalObjectId") - .HasColumnType("integer"); - - b.HasIndex("AclObjectId"); - - b.HasIndex("PrincipalObjectId"); - - b.ToTable("AclRules"); - }); - - modelBuilder.Entity("HyperBooru.HBPrincipal", b => - { - b.HasBaseType("HyperBooru.HBObject"); - - b.Property("Name") - .IsRequired() - .HasColumnType("text"); - - b.HasIndex("Name"); - - b.ToTable("Principals"); - }); - - modelBuilder.Entity("HyperBooru.Media", b => - { - b.HasBaseType("HyperBooru.HBObject"); - - b.Property("CurrentUploadedFileId") - .HasColumnType("integer"); - - b.Property("LongDescription") - .HasColumnType("text"); - - b.Property("ShortDescription") - .HasColumnType("text"); - - b.HasIndex("CurrentUploadedFileId") - .IsUnique(); - - b.ToTable("Media", (string)null); - }); - - modelBuilder.Entity("HyperBooru.Tag", b => - { - b.HasBaseType("HyperBooru.HBObject"); - - b.Property("CreateTime") - .HasColumnType("timestamp with time zone"); - - b.Property("TagDefinitionId") - .HasColumnType("integer"); - - b.Property("TargetObjectId") - .HasColumnType("integer"); - - b.HasIndex("TagDefinitionId"); - - b.HasIndex("TargetObjectId"); - - b.ToTable("Tags", (string)null); - }); - - modelBuilder.Entity("HyperBooru.TagDefinition", b => - { - b.HasBaseType("HyperBooru.HBObject"); - - b.Property("Alias") - .HasColumnType("text"); - - b.Property("Name") - .IsRequired() - .HasColumnType("text"); - - b.Property("Namespace") - .HasColumnType("text"); - - b.Property("Source") - .HasColumnType("integer"); - - b.ToTable("TagDefinitions", (string)null); - - b.HasData( - new - { - ObjectId = -1, - Guid = new Guid("ebdad4f8-455a-4351-8017-1d4854d6fa38"), - Name = "nsfw", - Source = 0 - }, - new - { - ObjectId = -2, - Guid = new Guid("ea212801-5bcc-4c0e-814f-fb9d30db58bc"), - Name = "ingest", - Source = 0 - }); - }); - - modelBuilder.Entity("HyperBooru.UploadedFile", b => - { - b.HasBaseType("HyperBooru.HBObject"); - - b.Property("Checksum") - .IsRequired() - .HasColumnType("text"); - - b.Property("ChecksumVerified") - .HasColumnType("boolean"); - - b.Property("CreateTime") - .HasColumnType("timestamp with time zone"); - - b.Property("Filename") - .HasColumnType("text"); - - b.Property("Height") - .HasColumnType("integer"); - - b.Property("LastAccessTime") - .HasColumnType("timestamp with time zone"); - - b.Property("LastWriteTime") - .HasColumnType("timestamp with time zone"); - - b.Property("Length") - .HasColumnType("bigint"); - - b.Property("MediaObjectId") - .HasColumnType("integer"); - - b.Property("MimeType") - .IsRequired() - .HasColumnType("text"); - - b.Property("UploadTime") - .HasColumnType("timestamp with time zone"); - - b.Property("Width") - .HasColumnType("integer"); - - b.HasIndex("MediaObjectId"); - - b.ToTable("UploadedFiles", (string)null); - }); - - modelBuilder.Entity("HyperBooru.Group", b => - { - b.HasBaseType("HyperBooru.HBPrincipal"); - - b.Property("HBPrincipalObjectId") - .HasColumnType("integer"); - - b.HasIndex("HBPrincipalObjectId"); - - b.ToTable("Groups"); - }); - - modelBuilder.Entity("HyperBooru.User", b => - { - b.HasBaseType("HyperBooru.HBPrincipal"); - - b.Property("PasswordHash") - .IsRequired() - .HasColumnType("text"); - - b.ToTable("Users"); - - b.HasData( - new - { - ObjectId = -3, - Guid = new Guid("8fbbc2e9-0609-460a-ab3a-c3bdd10ab793"), - Name = "admin", - PasswordHash = "P4geAuE2yX/PDRHuJSq74FF5vO782rWz5c0LAQPR8m45DEYAONhu1wYnAn60PSNyjocqEBdnCeKCJfK3sKyuWw==" - }); - }); - - modelBuilder.Entity("HyperBooru.OcrData", b => - { - b.HasOne("HyperBooru.Media", "Media") - .WithOne("OcrData") - .HasForeignKey("HyperBooru.OcrData", "MediaId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Media"); - }); - - modelBuilder.Entity("TagDefinitionTagDefinition", b => - { - b.HasOne("HyperBooru.TagDefinition", null) - .WithMany() - .HasForeignKey("ImplicitTagsObjectId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("HyperBooru.TagDefinition", null) - .WithMany() - .HasForeignKey("TagDefinitionObjectId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("HyperBooru.Acl", b => - { - b.HasOne("HyperBooru.HBObject", "Subject") - .WithOne("Acl") - .HasForeignKey("HyperBooru.Acl", "ObjectId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Subject"); - }); - - modelBuilder.Entity("HyperBooru.AclRule", b => - { - b.HasOne("HyperBooru.Acl", null) - .WithMany("Rules") - .HasForeignKey("AclObjectId"); - - b.HasOne("HyperBooru.HBPrincipal", "Principal") - .WithMany() - .HasForeignKey("PrincipalObjectId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Principal"); - }); - - modelBuilder.Entity("HyperBooru.Media", b => - { - b.HasOne("HyperBooru.UploadedFile", "CurrentUploadedFile") - .WithOne() - .HasForeignKey("HyperBooru.Media", "CurrentUploadedFileId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("HyperBooru.HBObject", null) - .WithOne() - .HasForeignKey("HyperBooru.Media", "ObjectId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("CurrentUploadedFile"); - }); - - modelBuilder.Entity("HyperBooru.Tag", b => - { - b.HasOne("HyperBooru.HBObject", null) - .WithOne() - .HasForeignKey("HyperBooru.Tag", "ObjectId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("HyperBooru.TagDefinition", "TagDefinition") - .WithMany() - .HasForeignKey("TagDefinitionId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("HyperBooru.HBObject", "Target") - .WithMany("Tags") - .HasForeignKey("TargetObjectId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("TagDefinition"); - - b.Navigation("Target"); - }); - - modelBuilder.Entity("HyperBooru.TagDefinition", b => - { - b.HasOne("HyperBooru.HBObject", null) - .WithOne() - .HasForeignKey("HyperBooru.TagDefinition", "ObjectId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("HyperBooru.UploadedFile", b => - { - b.HasOne("HyperBooru.Media", "Media") - .WithMany("UploadedFiles") - .HasForeignKey("MediaObjectId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("HyperBooru.HBObject", null) - .WithOne() - .HasForeignKey("HyperBooru.UploadedFile", "ObjectId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Media"); - }); - - modelBuilder.Entity("HyperBooru.Group", b => - { - b.HasOne("HyperBooru.HBPrincipal", null) - .WithMany("MemberOf") - .HasForeignKey("HBPrincipalObjectId"); - }); - - modelBuilder.Entity("HyperBooru.User", b => - { - b.HasOne("HyperBooru.HBPrincipal", null) - .WithOne() - .HasForeignKey("HyperBooru.User", "ObjectId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("HyperBooru.HBObject", b => - { - b.Navigation("Acl"); - - b.Navigation("Tags"); - }); - - modelBuilder.Entity("HyperBooru.Acl", b => - { - b.Navigation("Rules"); - }); - - modelBuilder.Entity("HyperBooru.HBPrincipal", b => - { - b.Navigation("MemberOf"); - }); - - modelBuilder.Entity("HyperBooru.Media", b => - { - b.Navigation("OcrData"); - - b.Navigation("UploadedFiles"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/Migrations/20230920052204_Security.cs b/Migrations/20230920052204_Security.cs deleted file mode 100644 index 982cb97..0000000 --- a/Migrations/20230920052204_Security.cs +++ /dev/null @@ -1,194 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace HyperBooru.Migrations -{ - /// - public partial class Security : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropForeignKey( - name: "FK_Users_Objects_ObjectId", - table: "Users"); - - migrationBuilder.DropIndex( - name: "IX_Users_Username", - table: "Users"); - - migrationBuilder.DropColumn( - name: "Username", - table: "Users"); - - migrationBuilder.CreateTable( - name: "Acls", - columns: table => new - { - ObjectId = table.Column(type: "integer", nullable: false), - SubjectTempId1 = table.Column(type: "integer", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_Acls", x => x.ObjectId); - table.ForeignKey( - name: "FK_Acls_Objects_ObjectId", - column: x => x.ObjectId, - principalTable: "Objects", - principalColumn: "ObjectId", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "Principals", - columns: table => new - { - ObjectId = table.Column(type: "integer", nullable: false), - Name = table.Column(type: "text", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Principals", x => x.ObjectId); - }); - - migrationBuilder.CreateTable( - name: "AclRules", - columns: table => new - { - ObjectId = table.Column(type: "integer", nullable: false), - PrincipalObjectId = table.Column(type: "integer", nullable: false), - Action = table.Column(type: "integer", nullable: false), - Permissions = table.Column(type: "bigint", nullable: false), - AclObjectId = table.Column(type: "integer", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_AclRules", x => x.ObjectId); - table.ForeignKey( - name: "FK_AclRules_Acls_AclObjectId", - column: x => x.AclObjectId, - principalTable: "Acls", - principalColumn: "ObjectId"); - table.ForeignKey( - name: "FK_AclRules_Principals_PrincipalObjectId", - column: x => x.PrincipalObjectId, - principalTable: "Principals", - principalColumn: "ObjectId", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "Groups", - columns: table => new - { - ObjectId = table.Column(type: "integer", nullable: false), - HBPrincipalObjectId = table.Column(type: "integer", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_Groups", x => x.ObjectId); - table.ForeignKey( - name: "FK_Groups_Principals_HBPrincipalObjectId", - column: x => x.HBPrincipalObjectId, - principalTable: "Principals", - principalColumn: "ObjectId"); - }); - - migrationBuilder.UpdateData( - table: "Objects", - keyColumn: "ObjectId", - keyValue: -3, - column: "Guid", - value: new Guid("8fbbc2e9-0609-460a-ab3a-c3bdd10ab793")); - - migrationBuilder.InsertData( - table: "Principals", - columns: new[] { "ObjectId", "Name" }, - values: new object[] { -3, "admin" }); - - migrationBuilder.CreateIndex( - name: "IX_AclRules_AclObjectId", - table: "AclRules", - column: "AclObjectId"); - - migrationBuilder.CreateIndex( - name: "IX_AclRules_PrincipalObjectId", - table: "AclRules", - column: "PrincipalObjectId"); - - migrationBuilder.CreateIndex( - name: "IX_Groups_HBPrincipalObjectId", - table: "Groups", - column: "HBPrincipalObjectId"); - - migrationBuilder.CreateIndex( - name: "IX_Principals_Name", - table: "Principals", - column: "Name"); - - migrationBuilder.AddForeignKey( - name: "FK_Users_Principals_ObjectId", - table: "Users", - column: "ObjectId", - principalTable: "Principals", - principalColumn: "ObjectId", - onDelete: ReferentialAction.Cascade); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropForeignKey( - name: "FK_Users_Principals_ObjectId", - table: "Users"); - - migrationBuilder.DropTable( - name: "AclRules"); - - migrationBuilder.DropTable( - name: "Groups"); - - migrationBuilder.DropTable( - name: "Acls"); - - migrationBuilder.DropTable( - name: "Principals"); - - migrationBuilder.AddColumn( - name: "Username", - table: "Users", - type: "text", - nullable: false, - defaultValue: ""); - - migrationBuilder.UpdateData( - table: "Objects", - keyColumn: "ObjectId", - keyValue: -3, - column: "Guid", - value: new Guid("4fa948f4-7c45-4f81-bb6b-e417491e6c96")); - - migrationBuilder.UpdateData( - table: "Users", - keyColumn: "ObjectId", - keyValue: -3, - column: "Username", - value: "admin"); - - migrationBuilder.CreateIndex( - name: "IX_Users_Username", - table: "Users", - column: "Username"); - - migrationBuilder.AddForeignKey( - name: "FK_Users_Objects_ObjectId", - table: "Users", - column: "ObjectId", - principalTable: "Objects", - principalColumn: "ObjectId", - onDelete: ReferentialAction.Cascade); - } - } -} diff --git a/Migrations/HBContextModelSnapshot.cs b/Migrations/HBContextModelSnapshot.cs index 5514b9b..16e6b48 100644 --- a/Migrations/HBContextModelSnapshot.cs +++ b/Migrations/HBContextModelSnapshot.cs @@ -69,7 +69,7 @@ namespace HyperBooru.Migrations b.HasIndex("MediaId") .IsUnique(); - b.ToTable("OcrData"); + b.ToTable("OcrData", (string)null); }); modelBuilder.Entity("TagDefinitionTagDefinition", b => @@ -84,53 +84,7 @@ namespace HyperBooru.Migrations b.HasIndex("TagDefinitionObjectId"); - b.ToTable("TagDefinitionTagDefinition"); - }); - - modelBuilder.Entity("HyperBooru.Acl", b => - { - b.HasBaseType("HyperBooru.HBObject"); - - b.Property("SubjectTempId1") - .HasColumnType("integer"); - - b.ToTable("Acls"); - }); - - modelBuilder.Entity("HyperBooru.AclRule", b => - { - b.HasBaseType("HyperBooru.HBObject"); - - b.Property("AclObjectId") - .HasColumnType("integer"); - - b.Property("Action") - .HasColumnType("integer"); - - b.Property("Permissions") - .HasColumnType("bigint"); - - b.Property("PrincipalObjectId") - .HasColumnType("integer"); - - b.HasIndex("AclObjectId"); - - b.HasIndex("PrincipalObjectId"); - - b.ToTable("AclRules"); - }); - - modelBuilder.Entity("HyperBooru.HBPrincipal", b => - { - b.HasBaseType("HyperBooru.HBObject"); - - b.Property("Name") - .IsRequired() - .HasColumnType("text"); - - b.HasIndex("Name"); - - b.ToTable("Principals"); + b.ToTable("TagDefinitionTagDefinition", (string)null); }); modelBuilder.Entity("HyperBooru.Media", b => @@ -255,35 +209,29 @@ namespace HyperBooru.Migrations b.ToTable("UploadedFiles", (string)null); }); - modelBuilder.Entity("HyperBooru.Group", b => - { - b.HasBaseType("HyperBooru.HBPrincipal"); - - b.Property("HBPrincipalObjectId") - .HasColumnType("integer"); - - b.HasIndex("HBPrincipalObjectId"); - - b.ToTable("Groups"); - }); - modelBuilder.Entity("HyperBooru.User", b => { - b.HasBaseType("HyperBooru.HBPrincipal"); + b.HasBaseType("HyperBooru.HBObject"); b.Property("PasswordHash") .IsRequired() .HasColumnType("text"); - b.ToTable("Users"); + b.Property("Username") + .IsRequired() + .HasColumnType("text"); + + b.HasIndex("Username"); + + b.ToTable("Users", (string)null); b.HasData( new { ObjectId = -3, - Guid = new Guid("8fbbc2e9-0609-460a-ab3a-c3bdd10ab793"), - Name = "admin", - PasswordHash = "P4geAuE2yX/PDRHuJSq74FF5vO782rWz5c0LAQPR8m45DEYAONhu1wYnAn60PSNyjocqEBdnCeKCJfK3sKyuWw==" + Guid = new Guid("4fa948f4-7c45-4f81-bb6b-e417491e6c96"), + PasswordHash = "P4geAuE2yX/PDRHuJSq74FF5vO782rWz5c0LAQPR8m45DEYAONhu1wYnAn60PSNyjocqEBdnCeKCJfK3sKyuWw==", + Username = "admin" }); }); @@ -313,32 +261,6 @@ namespace HyperBooru.Migrations .IsRequired(); }); - modelBuilder.Entity("HyperBooru.Acl", b => - { - b.HasOne("HyperBooru.HBObject", "Subject") - .WithOne("Acl") - .HasForeignKey("HyperBooru.Acl", "ObjectId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Subject"); - }); - - modelBuilder.Entity("HyperBooru.AclRule", b => - { - b.HasOne("HyperBooru.Acl", null) - .WithMany("Rules") - .HasForeignKey("AclObjectId"); - - b.HasOne("HyperBooru.HBPrincipal", "Principal") - .WithMany() - .HasForeignKey("PrincipalObjectId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Principal"); - }); - modelBuilder.Entity("HyperBooru.Media", b => { b.HasOne("HyperBooru.UploadedFile", "CurrentUploadedFile") @@ -407,16 +329,9 @@ namespace HyperBooru.Migrations b.Navigation("Media"); }); - modelBuilder.Entity("HyperBooru.Group", b => - { - b.HasOne("HyperBooru.HBPrincipal", null) - .WithMany("MemberOf") - .HasForeignKey("HBPrincipalObjectId"); - }); - modelBuilder.Entity("HyperBooru.User", b => { - b.HasOne("HyperBooru.HBPrincipal", null) + b.HasOne("HyperBooru.HBObject", null) .WithOne() .HasForeignKey("HyperBooru.User", "ObjectId") .OnDelete(DeleteBehavior.Cascade) @@ -425,21 +340,9 @@ namespace HyperBooru.Migrations modelBuilder.Entity("HyperBooru.HBObject", b => { - b.Navigation("Acl"); - b.Navigation("Tags"); }); - modelBuilder.Entity("HyperBooru.Acl", b => - { - b.Navigation("Rules"); - }); - - modelBuilder.Entity("HyperBooru.HBPrincipal", b => - { - b.Navigation("MemberOf"); - }); - modelBuilder.Entity("HyperBooru.Media", b => { b.Navigation("OcrData"); -- cgit v1.3