| | 1 | | using System; |
| | 2 | | using Jellyfin.Database.Implementations.Entities; |
| | 3 | | using Microsoft.EntityFrameworkCore; |
| | 4 | | using Microsoft.EntityFrameworkCore.Metadata.Builders; |
| | 5 | |
|
| | 6 | | namespace Jellyfin.Database.Implementations.ModelConfiguration; |
| | 7 | |
|
| | 8 | | /// <summary> |
| | 9 | | /// Configuration for BaseItem. |
| | 10 | | /// </summary> |
| | 11 | | public class BaseItemConfiguration : IEntityTypeConfiguration<BaseItemEntity> |
| | 12 | | { |
| | 13 | | /// <inheritdoc/> |
| | 14 | | public void Configure(EntityTypeBuilder<BaseItemEntity> builder) |
| | 15 | | { |
| 2 | 16 | | builder.HasKey(e => e.Id); |
| | 17 | | // TODO: See rant in entity file. |
| | 18 | | // builder.HasOne(e => e.Parent).WithMany(e => e.DirectChildren).HasForeignKey(e => e.ParentId); |
| | 19 | | // builder.HasOne(e => e.TopParent).WithMany(e => e.AllChildren).HasForeignKey(e => e.TopParentId); |
| | 20 | | // builder.HasOne(e => e.Season).WithMany(e => e.SeasonEpisodes).HasForeignKey(e => e.SeasonId); |
| | 21 | | // builder.HasOne(e => e.Series).WithMany(e => e.SeriesEpisodes).HasForeignKey(e => e.SeriesId); |
| 2 | 22 | | builder.HasMany(e => e.Peoples); |
| 2 | 23 | | builder.HasMany(e => e.UserData); |
| 2 | 24 | | builder.HasMany(e => e.ItemValues); |
| 2 | 25 | | builder.HasMany(e => e.MediaStreams); |
| 2 | 26 | | builder.HasMany(e => e.Chapters); |
| 2 | 27 | | builder.HasMany(e => e.Provider); |
| 2 | 28 | | builder.HasMany(e => e.Parents); |
| 2 | 29 | | builder.HasMany(e => e.Children); |
| 2 | 30 | | builder.HasMany(e => e.LockedFields); |
| 2 | 31 | | builder.HasMany(e => e.TrailerTypes); |
| 2 | 32 | | builder.HasMany(e => e.Images); |
| | 33 | |
|
| 2 | 34 | | builder.HasIndex(e => e.Path); |
| 2 | 35 | | builder.HasIndex(e => e.ParentId); |
| 2 | 36 | | builder.HasIndex(e => e.PresentationUniqueKey); |
| 2 | 37 | | builder.HasIndex(e => new { e.Id, e.Type, e.IsFolder, e.IsVirtualItem }); |
| | 38 | |
|
| | 39 | | // covering index |
| 2 | 40 | | builder.HasIndex(e => new { e.TopParentId, e.Id }); |
| | 41 | | // series |
| 2 | 42 | | builder.HasIndex(e => new { e.Type, e.SeriesPresentationUniqueKey, e.PresentationUniqueKey, e.SortName }); |
| | 43 | | // series counts |
| | 44 | | // seriesdateplayed sort order |
| 2 | 45 | | builder.HasIndex(e => new { e.Type, e.SeriesPresentationUniqueKey, e.IsFolder, e.IsVirtualItem }); |
| | 46 | | // live tv programs |
| 2 | 47 | | builder.HasIndex(e => new { e.Type, e.TopParentId, e.StartDate }); |
| | 48 | | // covering index for getitemvalues |
| 2 | 49 | | builder.HasIndex(e => new { e.Type, e.TopParentId, e.Id }); |
| | 50 | | // used by movie suggestions |
| 2 | 51 | | builder.HasIndex(e => new { e.Type, e.TopParentId, e.PresentationUniqueKey }); |
| | 52 | | // latest items |
| 2 | 53 | | builder.HasIndex(e => new { e.Type, e.TopParentId, e.IsVirtualItem, e.PresentationUniqueKey, e.DateCreated }); |
| 2 | 54 | | builder.HasIndex(e => new { e.IsFolder, e.TopParentId, e.IsVirtualItem, e.PresentationUniqueKey, e.DateCreated } |
| | 55 | | // resume |
| 2 | 56 | | builder.HasIndex(e => new { e.MediaType, e.TopParentId, e.IsVirtualItem, e.PresentationUniqueKey }); |
| | 57 | |
|
| 2 | 58 | | builder.HasData(new BaseItemEntity() |
| 2 | 59 | | { |
| 2 | 60 | | Id = Guid.Parse("00000000-0000-0000-0000-000000000001"), |
| 2 | 61 | | Type = "PLACEHOLDER", |
| 2 | 62 | | Name = "This is a placeholder item for UserData that has been detacted from its original item", |
| 2 | 63 | | }); |
| 2 | 64 | | } |
| | 65 | | } |