Story
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SVSim.Database.Common;
|
||||
using SVSim.Database.Entities.Story;
|
||||
using SVSim.Database.Models;
|
||||
using SVSim.Database.Models.Config;
|
||||
|
||||
@@ -67,6 +68,14 @@ public class SVSimDbContext : DbContext
|
||||
public DbSet<PuzzleMissionEntry> PuzzleMissions => Set<PuzzleMissionEntry>();
|
||||
public DbSet<ViewerPuzzleClear> ViewerPuzzleClears => Set<ViewerPuzzleClear>();
|
||||
|
||||
// Story reference data + viewer progress
|
||||
public DbSet<StoryWorld> StoryWorlds => Set<StoryWorld>();
|
||||
public DbSet<StorySection> StorySections => Set<StorySection>();
|
||||
public DbSet<StoryChapter> StoryChapters => Set<StoryChapter>();
|
||||
public DbSet<SpecialBattleSetting> SpecialBattleSettings => Set<SpecialBattleSetting>();
|
||||
public DbSet<ViewerStoryProgress> ViewerStoryProgress => Set<ViewerStoryProgress>();
|
||||
public DbSet<ViewerStoryBranchUnlock> ViewerStoryBranchUnlocks => Set<ViewerStoryBranchUnlock>();
|
||||
|
||||
#endregion
|
||||
|
||||
public override async Task<int> SaveChangesAsync(CancellationToken cancellationToken = default)
|
||||
@@ -142,6 +151,29 @@ public class SVSimDbContext : DbContext
|
||||
.HasColumnType("jsonb");
|
||||
}
|
||||
|
||||
// --- Story entities ---
|
||||
|
||||
// Composite PKs for viewer-state tables
|
||||
modelBuilder.Entity<ViewerStoryProgress>().HasKey(x => new { x.ViewerId, x.StoryId });
|
||||
modelBuilder.Entity<ViewerStoryBranchUnlock>().HasKey(x => new { x.ViewerId, x.StoryId });
|
||||
|
||||
// StoryChapter owned collections (shadow-PK per row)
|
||||
modelBuilder.Entity<StoryChapter>(c =>
|
||||
{
|
||||
c.OwnsMany(x => x.BattleSettings, b => { b.WithOwner().HasForeignKey("StoryId"); b.Property<int>("Id"); b.HasKey("StoryId", "Id"); });
|
||||
c.OwnsMany(x => x.Rewards, b => { b.WithOwner().HasForeignKey("StoryId"); b.Property<int>("Id"); b.HasKey("StoryId", "Id"); });
|
||||
c.OwnsMany(x => x.SubChapters, b => { b.WithOwner().HasForeignKey("StoryId"); b.Property<int>("Id"); b.HasKey("StoryId", "Id"); });
|
||||
});
|
||||
|
||||
// FK relationships
|
||||
modelBuilder.Entity<StorySection>().HasOne(s => s.World).WithMany().HasForeignKey(s => s.WorldId);
|
||||
modelBuilder.Entity<StoryChapter>().HasOne(c => c.Section).WithMany().HasForeignKey(c => c.SectionId);
|
||||
modelBuilder.Entity<StoryChapter>().HasOne(c => c.SpecialBattleSetting).WithMany().HasForeignKey(c => c.SpecialBattleSettingId);
|
||||
|
||||
// Indexes
|
||||
modelBuilder.Entity<StoryChapter>().HasIndex(c => new { c.SectionId, c.CharaId, c.ChapterId });
|
||||
modelBuilder.Entity<StoryChapter>().HasIndex(c => c.NextChapterId);
|
||||
|
||||
base.OnModelCreating(modelBuilder);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user