Refactor database configuration and migrations for PostgreSQL support

- Updated default database configuration to use PostgreSQL instead of SQLite when no database.xml exists.
- Removed obsolete migration routines: MigrateUserDb, RemoveDuplicateExtras, ReseedFolderFlag.
- Introduced new read-only view projections for PostgreSQL: ItemPersonView, ItemProviderView, LibrarySummaryView, MediaStreamInfoView, UserPlaybackHistoryView, VideoItemView.
- Registered view mappings in PostgresDatabaseProvider to ensure proper handling of read-only views.
- Cleaned up unused SQLite cache size configuration in ConfigurationExtensions.

Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
2026-04-30 18:47:48 -04:00
parent 9fc10226c9
commit e1f7a4bee9
15 changed files with 637 additions and 429 deletions
@@ -14,6 +14,7 @@ using System.Threading;
using System.Threading.Tasks;
using Jellyfin.Database.Implementations.Entities;
using Jellyfin.Database.Implementations.Entities.Security;
using Jellyfin.Database.Implementations.Entities.Views;
using Jellyfin.Database.Implementations.Interfaces;
using Jellyfin.Database.Implementations.Locking;
using Microsoft.EntityFrameworkCore;
@@ -156,6 +157,44 @@ public class JellyfinDbContext(DbContextOptions<JellyfinDbContext> options, ILog
/// </summary>
public DbSet<VideoStreamDetails> VideoStreamDetails => this.Set<VideoStreamDetails>();
// ── Read-only view projections (PostgreSQL only) ──────────────────────
/// <summary>
/// Gets the flat view over MediaStreamInfos joined with audio and video detail tables.
/// Maps to library."MediaStreamInfos_v".
/// </summary>
public DbSet<MediaStreamInfoView> MediaStreamInfoViews => this.Set<MediaStreamInfoView>();
/// <summary>
/// Gets the view of video items joined with their primary stream details.
/// Maps to library."VideoItems_v".
/// </summary>
public DbSet<VideoItemView> VideoItemViews => this.Set<VideoItemView>();
/// <summary>
/// Gets the view of per-user watch history with calculated progress.
/// Maps to library."UserPlaybackHistory_v".
/// </summary>
public DbSet<UserPlaybackHistoryView> UserPlaybackHistoryViews => this.Set<UserPlaybackHistoryView>();
/// <summary>
/// Gets the view of items with pivoted external provider IDs.
/// Maps to library."ItemProviders_v".
/// </summary>
public DbSet<ItemProviderView> ItemProviderViews => this.Set<ItemProviderView>();
/// <summary>
/// Gets the view of cast and crew entries linked to their items.
/// Maps to library."ItemPeople_v".
/// </summary>
public DbSet<ItemPersonView> ItemPersonViews => this.Set<ItemPersonView>();
/// <summary>
/// Gets the aggregate library statistics view, one row per item type.
/// Maps to library."LibrarySummary_v".
/// </summary>
public DbSet<LibrarySummaryView> LibrarySummaryViews => this.Set<LibrarySummaryView>();
/// <summary>
/// Gets the <see cref="DbSet{TEntity}"/>.
/// </summary>