Fixed bug where deletes of artifact groupings would not cascade

This commit is contained in:
Vincent Allen
2025-11-12 19:10:35 -05:00
parent b34449808f
commit 9298829db6
325 changed files with 5233 additions and 20996 deletions

View File

@@ -1,8 +1,27 @@
/*
<EFBFBD>Commons Clause<73> License Condition v1.0
https://commonsclause.com/
The Software is provided to you by the Licensor under the License, as defined below, subject to the following condition.
Without limiting other conditions in the License, the grant of rights under the License will not include, and the License does not grant to you, the right to Sell the Software.
For purposes of the foregoing, <20>Sell<6C> means practicing any or all of the rights granted to you under the License to provide to third parties, for a fee or other consideration (including without limitation fees for hosting or consulting/ support services related to the Software), a product or service whose value derives, entirely or substantially, from the functionality of the Software. Any license notice or attribution required by the License must also include this Commons Clause License Condition notice.
Software: Open Archival
License: GNU GPL: https://www.gnu.org/licenses/gpl-3.0.en.html
Licensor: Vincent Allen
*/
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.ChangeTracking;
using OpenArchival.DataAccess;
using Microsoft.EntityFrameworkCore;
using OpenArchival.DataAccess;
namespace OpenArchival.DataAccess;
@@ -32,6 +51,8 @@ public class ApplicationDbContext(DbContextOptions<ApplicationDbContext> options
public DbSet<BlogPostTag> BlogPostTags { get; set; }
public DbSet<BlogPostViewCount> BlogPostViews { get; set; }
/// <summary>
/// Configuration for what featured artifacts will be show on the homepage of the search page
/// </summary>
@@ -68,6 +89,12 @@ public class ApplicationDbContext(DbContextOptions<ApplicationDbContext> options
modelBuilder.Entity<ArtifactEntry>()
.HasMany(entry => entry.Files)
.WithOne(file => file.ParentArtifactEntry)
.HasForeignKey(file => file.ParentArtifactEntryId)
.OnDelete(DeleteBehavior.Cascade);
modelBuilder.Entity<BlogPost>()
.HasOne(p => p.MainPhoto)
.WithOne(p => p.ParentBlogPost)
.OnDelete(DeleteBehavior.Cascade);
modelBuilder.Entity<ArtifactGrouping>()
@@ -85,6 +112,11 @@ public class ApplicationDbContext(DbContextOptions<ApplicationDbContext> options
sourceDictionary => new Dictionary<string, string>(sourceDictionary)
);
modelBuilder.Entity<BlogPost>()
.HasOne(post => post.MainPhoto)
.WithOne(file => file.ParentBlogPost)
.HasForeignKey<FilePathListing>(file => file.ParentBlogPostId);
// Create the search vector columns for artifat groupings
modelBuilder.Entity<ArtifactGrouping>()
.HasGeneratedTsVectorColumn(
@@ -191,4 +223,4 @@ public class ApplicationDbContext(DbContextOptions<ApplicationDbContext> options
.HasIndex(p => p.AllSearchVector)
.HasMethod("GIN");
}
}
}