| | 1 | | using System; |
| | 2 | | using System.Linq; |
| | 3 | | using Jellyfin.Data.Entities; |
| | 4 | | using Jellyfin.Data.Entities.Security; |
| | 5 | | using Jellyfin.Data.Interfaces; |
| | 6 | | using Microsoft.EntityFrameworkCore; |
| | 7 | |
|
| | 8 | | namespace Jellyfin.Server.Implementations; |
| | 9 | |
|
| | 10 | | /// <inheritdoc/> |
| | 11 | | public 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> |
| 22 | 17 | | public JellyfinDbContext(DbContextOptions<JellyfinDbContext> options) : base(options) |
| | 18 | | { |
| 22 | 19 | | } |
| | 20 | |
|
| | 21 | | /// <summary> |
| | 22 | | /// Gets the <see cref="DbSet{TEntity}"/> containing the access schedules. |
| | 23 | | /// </summary> |
| 0 | 24 | | public DbSet<AccessSchedule> AccessSchedules => Set<AccessSchedule>(); |
| | 25 | |
|
| | 26 | | /// <summary> |
| | 27 | | /// Gets the <see cref="DbSet{TEntity}"/> containing the activity logs. |
| | 28 | | /// </summary> |
| 37 | 29 | | public DbSet<ActivityLog> ActivityLogs => Set<ActivityLog>(); |
| | 30 | |
|
| | 31 | | /// <summary> |
| | 32 | | /// Gets the <see cref="DbSet{TEntity}"/> containing the API keys. |
| | 33 | | /// </summary> |
| 0 | 34 | | public DbSet<ApiKey> ApiKeys => Set<ApiKey>(); |
| | 35 | |
|
| | 36 | | /// <summary> |
| | 37 | | /// Gets the <see cref="DbSet{TEntity}"/> containing the devices. |
| | 38 | | /// </summary> |
| 38 | 39 | | public DbSet<Device> Devices => Set<Device>(); |
| | 40 | |
|
| | 41 | | /// <summary> |
| | 42 | | /// Gets the <see cref="DbSet{TEntity}"/> containing the device options. |
| | 43 | | /// </summary> |
| 22 | 44 | | public DbSet<DeviceOptions> DeviceOptions => Set<DeviceOptions>(); |
| | 45 | |
|
| | 46 | | /// <summary> |
| | 47 | | /// Gets the <see cref="DbSet{TEntity}"/> containing the display preferences. |
| | 48 | | /// </summary> |
| 0 | 49 | | public DbSet<DisplayPreferences> DisplayPreferences => Set<DisplayPreferences>(); |
| | 50 | |
|
| | 51 | | /// <summary> |
| | 52 | | /// Gets the <see cref="DbSet{TEntity}"/> containing the image infos. |
| | 53 | | /// </summary> |
| 0 | 54 | | public DbSet<ImageInfo> ImageInfos => Set<ImageInfo>(); |
| | 55 | |
|
| | 56 | | /// <summary> |
| | 57 | | /// Gets the <see cref="DbSet{TEntity}"/> containing the item display preferences. |
| | 58 | | /// </summary> |
| 0 | 59 | | public DbSet<ItemDisplayPreferences> ItemDisplayPreferences => Set<ItemDisplayPreferences>(); |
| | 60 | |
|
| | 61 | | /// <summary> |
| | 62 | | /// Gets the <see cref="DbSet{TEntity}"/> containing the custom item display preferences. |
| | 63 | | /// </summary> |
| 0 | 64 | | public DbSet<CustomItemDisplayPreferences> CustomItemDisplayPreferences => Set<CustomItemDisplayPreferences>(); |
| | 65 | |
|
| | 66 | | /// <summary> |
| | 67 | | /// Gets the <see cref="DbSet{TEntity}"/> containing the permissions. |
| | 68 | | /// </summary> |
| 0 | 69 | | public DbSet<Permission> Permissions => Set<Permission>(); |
| | 70 | |
|
| | 71 | | /// <summary> |
| | 72 | | /// Gets the <see cref="DbSet{TEntity}"/> containing the preferences. |
| | 73 | | /// </summary> |
| 0 | 74 | | public DbSet<Preference> Preferences => Set<Preference>(); |
| | 75 | |
|
| | 76 | | /// <summary> |
| | 77 | | /// Gets the <see cref="DbSet{TEntity}"/> containing the users. |
| | 78 | | /// </summary> |
| 79 | 79 | | public DbSet<User> Users => Set<User>(); |
| | 80 | |
|
| | 81 | | /// <summary> |
| | 82 | | /// Gets the <see cref="DbSet{TEntity}"/> containing the trickplay metadata. |
| | 83 | | /// </summary> |
| 0 | 84 | | public DbSet<TrickplayInfo> TrickplayInfos => Set<TrickplayInfo>(); |
| | 85 | |
|
| | 86 | | /// <summary> |
| | 87 | | /// Gets the <see cref="DbSet{TEntity}"/> containing the media segments. |
| | 88 | | /// </summary> |
| 0 | 89 | | 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 | | { |
| 0 | 178 | | foreach (var saveEntity in ChangeTracker.Entries() |
| 0 | 179 | | .Where(e => e.State == EntityState.Modified) |
| 0 | 180 | | .Select(entry => entry.Entity) |
| 0 | 181 | | .OfType<IHasConcurrencyToken>()) |
| | 182 | | { |
| 0 | 183 | | saveEntity.OnSavingChanges(); |
| | 184 | | } |
| | 185 | |
|
| 0 | 186 | | return base.SaveChanges(); |
| | 187 | | } |
| | 188 | |
|
| | 189 | | /// <inheritdoc /> |
| | 190 | | protected override void OnModelCreating(ModelBuilder modelBuilder) |
| | 191 | | { |
| 1 | 192 | | modelBuilder.SetDefaultDateTimeKind(DateTimeKind.Utc); |
| 1 | 193 | | base.OnModelCreating(modelBuilder); |
| | 194 | |
|
| | 195 | | // Configuration for each entity is in it's own class inside 'ModelConfiguration'. |
| 1 | 196 | | modelBuilder.ApplyConfigurationsFromAssembly(typeof(JellyfinDbContext).Assembly); |
| 1 | 197 | | } |
| | 198 | | } |