jellyfin/Jellyfin.Server.Implementations/JellyfinDbContext.cs

189 lines
6.2 KiB
C#
Raw Normal View History

using System;
2020-05-02 22:32:22 +00:00
using System.Linq;
using Jellyfin.Data.Entities;
using Jellyfin.Data.Entities.Security;
using Jellyfin.Data.Interfaces;
2020-05-02 22:32:22 +00:00
using Microsoft.EntityFrameworkCore;
namespace Jellyfin.Server.Implementations;
/// <inheritdoc/>
2023-01-16 17:14:44 +00:00
public class JellyfinDbContext : DbContext
2020-05-02 22:32:22 +00:00
{
/// <summary>
2023-01-16 17:14:44 +00:00
/// Initializes a new instance of the <see cref="JellyfinDbContext"/> class.
/// </summary>
/// <param name="options">The database context options.</param>
2023-01-16 17:14:44 +00:00
public JellyfinDbContext(DbContextOptions<JellyfinDbContext> options) : base(options)
2020-05-02 22:32:22 +00:00
{
}
2020-05-23 00:20:18 +00:00
2023-01-16 17:13:06 +00:00
/// <summary>
/// Gets the <see cref="DbSet{TEntity}"/> containing the access schedules.
/// </summary>
2023-01-16 15:28:31 +00:00
public DbSet<AccessSchedule> AccessSchedules => Set<AccessSchedule>();
2023-01-16 17:13:06 +00:00
/// <summary>
/// Gets the <see cref="DbSet{TEntity}"/> containing the activity logs.
/// </summary>
2023-01-16 15:28:31 +00:00
public DbSet<ActivityLog> ActivityLogs => Set<ActivityLog>();
2020-05-15 21:24:01 +00:00
2023-01-16 17:13:06 +00:00
/// <summary>
/// Gets the <see cref="DbSet{TEntity}"/> containing the API keys.
/// </summary>
2023-01-16 15:28:31 +00:00
public DbSet<ApiKey> ApiKeys => Set<ApiKey>();
2023-01-16 17:13:06 +00:00
/// <summary>
/// Gets the <see cref="DbSet{TEntity}"/> containing the devices.
/// </summary>
2023-01-16 15:28:31 +00:00
public DbSet<Device> Devices => Set<Device>();
2021-04-10 20:15:59 +00:00
2023-01-16 17:13:06 +00:00
/// <summary>
/// Gets the <see cref="DbSet{TEntity}"/> containing the device options.
/// </summary>
2023-01-16 15:28:31 +00:00
public DbSet<DeviceOptions> DeviceOptions => Set<DeviceOptions>();
2021-04-10 20:15:59 +00:00
2023-01-16 17:13:06 +00:00
/// <summary>
/// Gets the <see cref="DbSet{TEntity}"/> containing the display preferences.
/// </summary>
2023-01-16 15:28:31 +00:00
public DbSet<DisplayPreferences> DisplayPreferences => Set<DisplayPreferences>();
2020-07-01 01:44:41 +00:00
2023-01-16 17:13:06 +00:00
/// <summary>
/// Gets the <see cref="DbSet{TEntity}"/> containing the image infos.
/// </summary>
2023-01-16 15:28:31 +00:00
public DbSet<ImageInfo> ImageInfos => Set<ImageInfo>();
2023-01-16 17:13:06 +00:00
/// <summary>
/// Gets the <see cref="DbSet{TEntity}"/> containing the item display preferences.
/// </summary>
2023-01-16 15:28:31 +00:00
public DbSet<ItemDisplayPreferences> ItemDisplayPreferences => Set<ItemDisplayPreferences>();
2023-01-16 17:13:06 +00:00
/// <summary>
/// Gets the <see cref="DbSet{TEntity}"/> containing the custom item display preferences.
/// </summary>
2023-01-16 15:28:31 +00:00
public DbSet<CustomItemDisplayPreferences> CustomItemDisplayPreferences => Set<CustomItemDisplayPreferences>();
2023-01-16 17:13:06 +00:00
/// <summary>
/// Gets the <see cref="DbSet{TEntity}"/> containing the permissions.
/// </summary>
2023-01-16 15:28:31 +00:00
public DbSet<Permission> Permissions => Set<Permission>();
2020-05-15 21:24:01 +00:00
2023-01-16 17:13:06 +00:00
/// <summary>
/// Gets the <see cref="DbSet{TEntity}"/> containing the preferences.
/// </summary>
2023-01-16 15:28:31 +00:00
public DbSet<Preference> Preferences => Set<Preference>();
2020-05-15 21:24:01 +00:00
2023-01-16 17:13:06 +00:00
/// <summary>
/// Gets the <see cref="DbSet{TEntity}"/> containing the users.
/// </summary>
2023-01-16 15:28:31 +00:00
public DbSet<User> Users => Set<User>();
2020-06-15 21:43:52 +00:00
2023-01-16 15:28:31 +00:00
/*public DbSet<Artwork> Artwork => Set<Artwork>();
2020-06-15 21:43:52 +00:00
2023-01-16 15:28:31 +00:00
public DbSet<Book> Books => Set<Book>();
2020-06-15 21:43:52 +00:00
2023-01-16 15:28:31 +00:00
public DbSet<BookMetadata> BookMetadata => Set<BookMetadata>();
2020-06-15 21:43:52 +00:00
2023-01-16 15:28:31 +00:00
public DbSet<Chapter> Chapters => Set<Chapter>();
2020-06-15 21:43:52 +00:00
2023-01-16 15:28:31 +00:00
public DbSet<Collection> Collections => Set<Collection>();
2020-06-15 21:43:52 +00:00
2023-01-16 15:28:31 +00:00
public DbSet<CollectionItem> CollectionItems => Set<CollectionItem>();
2020-06-15 21:43:52 +00:00
2023-01-16 15:28:31 +00:00
public DbSet<Company> Companies => Set<Company>();
2020-06-15 21:43:52 +00:00
2023-01-16 15:28:31 +00:00
public DbSet<CompanyMetadata> CompanyMetadata => Set<CompanyMetadata>();
2020-06-15 21:43:52 +00:00
2023-01-16 15:28:31 +00:00
public DbSet<CustomItem> CustomItems => Set<CustomItem>();
2020-06-15 21:43:52 +00:00
2023-01-16 15:28:31 +00:00
public DbSet<CustomItemMetadata> CustomItemMetadata => Set<CustomItemMetadata>();
2020-06-15 21:43:52 +00:00
2023-01-16 15:28:31 +00:00
public DbSet<Episode> Episodes => Set<Episode>();
2020-06-15 21:43:52 +00:00
2023-01-16 15:28:31 +00:00
public DbSet<EpisodeMetadata> EpisodeMetadata => Set<EpisodeMetadata>();
2020-06-15 21:43:52 +00:00
2023-01-16 15:28:31 +00:00
public DbSet<Genre> Genres => Set<Genre>();
2020-06-15 21:43:52 +00:00
2023-01-16 15:28:31 +00:00
public DbSet<Group> Groups => Set<Groups>();
2020-06-15 21:43:52 +00:00
2023-01-16 15:28:31 +00:00
public DbSet<Library> Libraries => Set<Library>();
2020-06-15 21:43:52 +00:00
2023-01-16 15:28:31 +00:00
public DbSet<LibraryItem> LibraryItems => Set<LibraryItems>();
2020-06-15 21:43:52 +00:00
2023-01-16 15:28:31 +00:00
public DbSet<LibraryRoot> LibraryRoot => Set<LibraryRoot>();
2020-06-15 21:43:52 +00:00
2023-01-16 15:28:31 +00:00
public DbSet<MediaFile> MediaFiles => Set<MediaFiles>();
2020-06-15 21:43:52 +00:00
2023-01-16 15:28:31 +00:00
public DbSet<MediaFileStream> MediaFileStream => Set<MediaFileStream>();
2020-06-15 21:43:52 +00:00
2023-01-16 15:28:31 +00:00
public DbSet<Metadata> Metadata => Set<Metadata>();
2020-06-15 21:43:52 +00:00
2023-01-16 15:28:31 +00:00
public DbSet<MetadataProvider> MetadataProviders => Set<MetadataProvider>();
2020-06-15 21:43:52 +00:00
2023-01-16 15:28:31 +00:00
public DbSet<MetadataProviderId> MetadataProviderIds => Set<MetadataProviderId>();
2020-06-15 21:43:52 +00:00
2023-01-16 15:28:31 +00:00
public DbSet<Movie> Movies => Set<Movie>();
2020-06-15 21:43:52 +00:00
2023-01-16 15:28:31 +00:00
public DbSet<MovieMetadata> MovieMetadata => Set<MovieMetadata>();
2020-06-15 21:43:52 +00:00
2023-01-16 15:28:31 +00:00
public DbSet<MusicAlbum> MusicAlbums => Set<MusicAlbum>();
2020-06-15 21:43:52 +00:00
2023-01-16 15:28:31 +00:00
public DbSet<MusicAlbumMetadata> MusicAlbumMetadata => Set<MusicAlbumMetadata>();
2020-06-15 21:43:52 +00:00
2023-01-16 15:28:31 +00:00
public DbSet<Person> People => Set<Person>();
2020-06-15 21:43:52 +00:00
2023-01-16 15:28:31 +00:00
public DbSet<PersonRole> PersonRoles => Set<PersonRole>();
2020-06-15 21:43:52 +00:00
2023-01-16 15:28:31 +00:00
public DbSet<Photo> Photo => Set<Photo>();
2020-06-15 21:43:52 +00:00
2023-01-16 15:28:31 +00:00
public DbSet<PhotoMetadata> PhotoMetadata => Set<PhotoMetadata>();
2020-06-15 21:43:52 +00:00
2023-01-16 15:28:31 +00:00
public DbSet<ProviderMapping> ProviderMappings => Set<ProviderMapping>();
2020-06-15 21:43:52 +00:00
2023-01-16 15:28:31 +00:00
public DbSet<Rating> Ratings => Set<Rating>();
2020-05-02 22:32:22 +00:00
/// <summary>
/// Repository for global::Jellyfin.Data.Entities.RatingSource - This is the entity to
/// store review ratings, not age ratings.
/// </summary>
2023-01-16 15:28:31 +00:00
public DbSet<RatingSource> RatingSources => Set<RatingSource>();
2020-06-15 21:43:52 +00:00
2023-01-16 15:28:31 +00:00
public DbSet<Release> Releases => Set<Release>();
2020-06-15 21:43:52 +00:00
2023-01-16 15:28:31 +00:00
public DbSet<Season> Seasons => Set<Season>();
2020-06-15 21:43:52 +00:00
2023-01-16 15:28:31 +00:00
public DbSet<SeasonMetadata> SeasonMetadata => Set<SeasonMetadata>();
2020-06-15 21:43:52 +00:00
2023-01-16 15:28:31 +00:00
public DbSet<Series> Series => Set<Series>();
2020-06-15 21:43:52 +00:00
2023-01-16 15:28:31 +00:00
public DbSet<SeriesMetadata> SeriesMetadata => Set<SeriesMetadata();
2020-06-15 21:43:52 +00:00
2023-01-16 15:28:31 +00:00
public DbSet<Track> Tracks => Set<Track>();
2020-06-15 21:43:52 +00:00
2023-01-16 15:28:31 +00:00
public DbSet<TrackMetadata> TrackMetadata => Set<TrackMetadata>();*/
2020-05-02 22:32:22 +00:00
/// <inheritdoc/>
public override int SaveChanges()
{
foreach (var saveEntity in ChangeTracker.Entries()
.Where(e => e.State == EntityState.Modified)
.Select(entry => entry.Entity)
.OfType<IHasConcurrencyToken>())
2020-05-02 22:32:22 +00:00
{
saveEntity.OnSavingChanges();
2020-05-23 00:20:18 +00:00
}
2020-05-02 22:32:22 +00:00
return base.SaveChanges();
}
2020-05-02 22:32:22 +00:00
/// <inheritdoc />
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.SetDefaultDateTimeKind(DateTimeKind.Utc);
base.OnModelCreating(modelBuilder);
// Configuration for each entity is in it's own class inside 'ModelConfiguration'.
2023-01-16 17:14:44 +00:00
modelBuilder.ApplyConfigurationsFromAssembly(typeof(JellyfinDbContext).Assembly);
2020-05-02 22:32:22 +00:00
}
}