< Summary - Jellyfin

Information
Class: Jellyfin.Server.Implementations.JellyfinDbContext
Assembly: Jellyfin.Server.Implementations
File(s): /srv/git/jellyfin/Jellyfin.Server.Implementations/JellyfinDbContext.cs
Line coverage
38%
Covered lines: 10
Uncovered lines: 16
Coverable lines: 26
Total lines: 198
Line coverage: 38.4%
Branch coverage
0%
Covered branches: 0
Total branches: 2
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
get_AccessSchedules()100%210%
get_ActivityLogs()100%11100%
get_ApiKeys()100%210%
get_Devices()100%11100%
get_DeviceOptions()100%11100%
get_DisplayPreferences()100%210%
get_ImageInfos()100%210%
get_ItemDisplayPreferences()100%210%
get_CustomItemDisplayPreferences()100%210%
get_Permissions()100%210%
get_Preferences()100%210%
get_Users()100%11100%
get_TrickplayInfos()100%210%
get_MediaSegments()100%210%
SaveChanges()0%620%
OnModelCreating(...)100%11100%

File(s)

/srv/git/jellyfin/Jellyfin.Server.Implementations/JellyfinDbContext.cs

#LineLine coverage
 1using System;
 2using System.Linq;
 3using Jellyfin.Data.Entities;
 4using Jellyfin.Data.Entities.Security;
 5using Jellyfin.Data.Interfaces;
 6using Microsoft.EntityFrameworkCore;
 7
 8namespace Jellyfin.Server.Implementations;
 9
 10/// <inheritdoc/>
 11public class JellyfinDbContext : DbContext
 12{
 13    /// <summary>
 14    /// Initializes a new instance of the <see cref="JellyfinDbContext"/> class.
 15    /// </summary>
 16    /// <param name="options">The database context options.</param>
 2217    public JellyfinDbContext(DbContextOptions<JellyfinDbContext> options) : base(options)
 18    {
 2219    }
 20
 21    /// <summary>
 22    /// Gets the <see cref="DbSet{TEntity}"/> containing the access schedules.
 23    /// </summary>
 024    public DbSet<AccessSchedule> AccessSchedules => Set<AccessSchedule>();
 25
 26    /// <summary>
 27    /// Gets the <see cref="DbSet{TEntity}"/> containing the activity logs.
 28    /// </summary>
 3729    public DbSet<ActivityLog> ActivityLogs => Set<ActivityLog>();
 30
 31    /// <summary>
 32    /// Gets the <see cref="DbSet{TEntity}"/> containing the API keys.
 33    /// </summary>
 034    public DbSet<ApiKey> ApiKeys => Set<ApiKey>();
 35
 36    /// <summary>
 37    /// Gets the <see cref="DbSet{TEntity}"/> containing the devices.
 38    /// </summary>
 3839    public DbSet<Device> Devices => Set<Device>();
 40
 41    /// <summary>
 42    /// Gets the <see cref="DbSet{TEntity}"/> containing the device options.
 43    /// </summary>
 2244    public DbSet<DeviceOptions> DeviceOptions => Set<DeviceOptions>();
 45
 46    /// <summary>
 47    /// Gets the <see cref="DbSet{TEntity}"/> containing the display preferences.
 48    /// </summary>
 049    public DbSet<DisplayPreferences> DisplayPreferences => Set<DisplayPreferences>();
 50
 51    /// <summary>
 52    /// Gets the <see cref="DbSet{TEntity}"/> containing the image infos.
 53    /// </summary>
 054    public DbSet<ImageInfo> ImageInfos => Set<ImageInfo>();
 55
 56    /// <summary>
 57    /// Gets the <see cref="DbSet{TEntity}"/> containing the item display preferences.
 58    /// </summary>
 059    public DbSet<ItemDisplayPreferences> ItemDisplayPreferences => Set<ItemDisplayPreferences>();
 60
 61    /// <summary>
 62    /// Gets the <see cref="DbSet{TEntity}"/> containing the custom item display preferences.
 63    /// </summary>
 064    public DbSet<CustomItemDisplayPreferences> CustomItemDisplayPreferences => Set<CustomItemDisplayPreferences>();
 65
 66    /// <summary>
 67    /// Gets the <see cref="DbSet{TEntity}"/> containing the permissions.
 68    /// </summary>
 069    public DbSet<Permission> Permissions => Set<Permission>();
 70
 71    /// <summary>
 72    /// Gets the <see cref="DbSet{TEntity}"/> containing the preferences.
 73    /// </summary>
 074    public DbSet<Preference> Preferences => Set<Preference>();
 75
 76    /// <summary>
 77    /// Gets the <see cref="DbSet{TEntity}"/> containing the users.
 78    /// </summary>
 7979    public DbSet<User> Users => Set<User>();
 80
 81    /// <summary>
 82    /// Gets the <see cref="DbSet{TEntity}"/> containing the trickplay metadata.
 83    /// </summary>
 084    public DbSet<TrickplayInfo> TrickplayInfos => Set<TrickplayInfo>();
 85
 86    /// <summary>
 87    /// Gets the <see cref="DbSet{TEntity}"/> containing the media segments.
 88    /// </summary>
 089    public DbSet<MediaSegment> MediaSegments => Set<MediaSegment>();
 90
 91    /*public DbSet<Artwork> Artwork => Set<Artwork>();
 92
 93    public DbSet<Book> Books => Set<Book>();
 94
 95    public DbSet<BookMetadata> BookMetadata => Set<BookMetadata>();
 96
 97    public DbSet<Chapter> Chapters => Set<Chapter>();
 98
 99    public DbSet<Collection> Collections => Set<Collection>();
 100
 101    public DbSet<CollectionItem> CollectionItems => Set<CollectionItem>();
 102
 103    public DbSet<Company> Companies => Set<Company>();
 104
 105    public DbSet<CompanyMetadata> CompanyMetadata => Set<CompanyMetadata>();
 106
 107    public DbSet<CustomItem> CustomItems => Set<CustomItem>();
 108
 109    public DbSet<CustomItemMetadata> CustomItemMetadata => Set<CustomItemMetadata>();
 110
 111    public DbSet<Episode> Episodes => Set<Episode>();
 112
 113    public DbSet<EpisodeMetadata> EpisodeMetadata => Set<EpisodeMetadata>();
 114
 115    public DbSet<Genre> Genres => Set<Genre>();
 116
 117    public DbSet<Group> Groups => Set<Groups>();
 118
 119    public DbSet<Library> Libraries => Set<Library>();
 120
 121    public DbSet<LibraryItem> LibraryItems => Set<LibraryItems>();
 122
 123    public DbSet<LibraryRoot> LibraryRoot => Set<LibraryRoot>();
 124
 125    public DbSet<MediaFile> MediaFiles => Set<MediaFiles>();
 126
 127    public DbSet<MediaFileStream> MediaFileStream => Set<MediaFileStream>();
 128
 129    public DbSet<Metadata> Metadata => Set<Metadata>();
 130
 131    public DbSet<MetadataProvider> MetadataProviders => Set<MetadataProvider>();
 132
 133    public DbSet<MetadataProviderId> MetadataProviderIds => Set<MetadataProviderId>();
 134
 135    public DbSet<Movie> Movies => Set<Movie>();
 136
 137    public DbSet<MovieMetadata> MovieMetadata => Set<MovieMetadata>();
 138
 139    public DbSet<MusicAlbum> MusicAlbums => Set<MusicAlbum>();
 140
 141    public DbSet<MusicAlbumMetadata> MusicAlbumMetadata => Set<MusicAlbumMetadata>();
 142
 143    public DbSet<Person> People => Set<Person>();
 144
 145    public DbSet<PersonRole> PersonRoles => Set<PersonRole>();
 146
 147    public DbSet<Photo> Photo => Set<Photo>();
 148
 149    public DbSet<PhotoMetadata> PhotoMetadata => Set<PhotoMetadata>();
 150
 151    public DbSet<ProviderMapping> ProviderMappings => Set<ProviderMapping>();
 152
 153    public DbSet<Rating> Ratings => Set<Rating>();
 154
 155    /// <summary>
 156    /// Repository for global::Jellyfin.Data.Entities.RatingSource - This is the entity to
 157    /// store review ratings, not age ratings.
 158    /// </summary>
 159    public DbSet<RatingSource> RatingSources => Set<RatingSource>();
 160
 161    public DbSet<Release> Releases => Set<Release>();
 162
 163    public DbSet<Season> Seasons => Set<Season>();
 164
 165    public DbSet<SeasonMetadata> SeasonMetadata => Set<SeasonMetadata>();
 166
 167    public DbSet<Series> Series => Set<Series>();
 168
 169    public DbSet<SeriesMetadata> SeriesMetadata => Set<SeriesMetadata();
 170
 171    public DbSet<Track> Tracks => Set<Track>();
 172
 173    public DbSet<TrackMetadata> TrackMetadata => Set<TrackMetadata>();*/
 174
 175    /// <inheritdoc/>
 176    public override int SaveChanges()
 177    {
 0178        foreach (var saveEntity in ChangeTracker.Entries()
 0179                     .Where(e => e.State == EntityState.Modified)
 0180                     .Select(entry => entry.Entity)
 0181                     .OfType<IHasConcurrencyToken>())
 182        {
 0183            saveEntity.OnSavingChanges();
 184        }
 185
 0186        return base.SaveChanges();
 187    }
 188
 189    /// <inheritdoc />
 190    protected override void OnModelCreating(ModelBuilder modelBuilder)
 191    {
 1192        modelBuilder.SetDefaultDateTimeKind(DateTimeKind.Utc);
 1193        base.OnModelCreating(modelBuilder);
 194
 195        // Configuration for each entity is in it's own class inside 'ModelConfiguration'.
 1196        modelBuilder.ApplyConfigurationsFromAssembly(typeof(JellyfinDbContext).Assembly);
 1197    }
 198}