From f4af78817d5832c11ff96f365714917fad0db4f9 Mon Sep 17 00:00:00 2001 From: Fernando Fernández Date: Mon, 6 Sep 2021 21:05:21 +0200 Subject: Move model configuration to its own classes --- .../ModelConfiguration/UserConfiguration.cs | 62 ++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 Jellyfin.Server.Implementations/ModelConfiguration/UserConfiguration.cs (limited to 'Jellyfin.Server.Implementations/ModelConfiguration/UserConfiguration.cs') diff --git a/Jellyfin.Server.Implementations/ModelConfiguration/UserConfiguration.cs b/Jellyfin.Server.Implementations/ModelConfiguration/UserConfiguration.cs new file mode 100644 index 000000000..ee8831804 --- /dev/null +++ b/Jellyfin.Server.Implementations/ModelConfiguration/UserConfiguration.cs @@ -0,0 +1,62 @@ +using Jellyfin.Data.Entities; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; + +namespace Jellyfin.Server.Implementations.ModelConfiguration +{ + /// + /// FluentAPI configuration for the User entity. + /// + public class UserConfiguration : IEntityTypeConfiguration + { + /// + public void Configure(EntityTypeBuilder builder) + { + // Collations + + builder + .Property(user => user.Username) + .UseCollation("NOCASE"); + + // Delete behavior + + builder + .HasOne(u => u.ProfileImage) + .WithOne() + .OnDelete(DeleteBehavior.Cascade); + + builder + .HasMany(u => u.Permissions) + .WithOne() + .HasForeignKey(p => p.UserId) + .OnDelete(DeleteBehavior.Cascade); + + builder + .HasMany(u => u.Preferences) + .WithOne() + .HasForeignKey(p => p.UserId) + .OnDelete(DeleteBehavior.Cascade); + + builder + .HasMany(u => u.AccessSchedules) + .WithOne() + .OnDelete(DeleteBehavior.Cascade); + + builder + .HasMany(u => u.DisplayPreferences) + .WithOne() + .OnDelete(DeleteBehavior.Cascade); + + builder + .HasMany(u => u.ItemDisplayPreferences) + .WithOne() + .OnDelete(DeleteBehavior.Cascade); + + // Indexes + + builder + .HasIndex(entity => entity.Username) + .IsUnique(); + } + } +} -- cgit v1.2.3 From e5980f868643e4e92448bbfb31a0fedae3929691 Mon Sep 17 00:00:00 2001 From: Fernando Fernández Date: Tue, 7 Sep 2021 17:53:35 +0200 Subject: Fix typo in comment and remove useless ones --- Jellyfin.Server.Implementations/JellyfinDb.cs | 2 +- .../ModelConfiguration/ApiKeyConfiguration.cs | 2 -- .../ModelConfiguration/CustomItemDisplayPreferencesConfiguration.cs | 2 -- .../ModelConfiguration/DeviceConfiguration.cs | 2 -- .../ModelConfiguration/DeviceOptionsConfiguration.cs | 2 -- .../ModelConfiguration/DisplayPreferencesConfiguration.cs | 4 ---- .../ModelConfiguration/PermissionConfiguration.cs | 2 -- .../ModelConfiguration/PreferenceConfiguration.cs | 2 -- .../ModelConfiguration/UserConfiguration.cs | 6 ------ 9 files changed, 1 insertion(+), 23 deletions(-) (limited to 'Jellyfin.Server.Implementations/ModelConfiguration/UserConfiguration.cs') diff --git a/Jellyfin.Server.Implementations/JellyfinDb.cs b/Jellyfin.Server.Implementations/JellyfinDb.cs index b176e14a6..dc4f53913 100644 --- a/Jellyfin.Server.Implementations/JellyfinDb.cs +++ b/Jellyfin.Server.Implementations/JellyfinDb.cs @@ -155,7 +155,7 @@ namespace Jellyfin.Server.Implementations base.OnModelCreating(modelBuilder); modelBuilder.HasDefaultSchema("jellyfin"); - // Configuration for each entity is in it's own class inside 'ModelConfiguratio'. + // Configuration for each entity is in it's own class inside 'ModelConfiguration'. modelBuilder.ApplyConfigurationsFromAssembly(typeof(JellyfinDb).Assembly); } } diff --git a/Jellyfin.Server.Implementations/ModelConfiguration/ApiKeyConfiguration.cs b/Jellyfin.Server.Implementations/ModelConfiguration/ApiKeyConfiguration.cs index 9067d3833..3f19b6986 100644 --- a/Jellyfin.Server.Implementations/ModelConfiguration/ApiKeyConfiguration.cs +++ b/Jellyfin.Server.Implementations/ModelConfiguration/ApiKeyConfiguration.cs @@ -12,8 +12,6 @@ namespace Jellyfin.Server.Implementations.ModelConfiguration /// public void Configure(EntityTypeBuilder builder) { - // Indexes - builder .HasIndex(entity => entity.AccessToken) .IsUnique(); diff --git a/Jellyfin.Server.Implementations/ModelConfiguration/CustomItemDisplayPreferencesConfiguration.cs b/Jellyfin.Server.Implementations/ModelConfiguration/CustomItemDisplayPreferencesConfiguration.cs index 75d9ba529..779aec986 100644 --- a/Jellyfin.Server.Implementations/ModelConfiguration/CustomItemDisplayPreferencesConfiguration.cs +++ b/Jellyfin.Server.Implementations/ModelConfiguration/CustomItemDisplayPreferencesConfiguration.cs @@ -12,8 +12,6 @@ namespace Jellyfin.Server.Implementations.ModelConfiguration /// public void Configure(EntityTypeBuilder builder) { - // Indexes - builder .HasIndex(entity => new { entity.UserId, entity.ItemId, entity.Client, entity.Key }) .IsUnique(); diff --git a/Jellyfin.Server.Implementations/ModelConfiguration/DeviceConfiguration.cs b/Jellyfin.Server.Implementations/ModelConfiguration/DeviceConfiguration.cs index 5b4e711cc..a750b65c0 100644 --- a/Jellyfin.Server.Implementations/ModelConfiguration/DeviceConfiguration.cs +++ b/Jellyfin.Server.Implementations/ModelConfiguration/DeviceConfiguration.cs @@ -12,8 +12,6 @@ namespace Jellyfin.Server.Implementations.ModelConfiguration /// public void Configure(EntityTypeBuilder builder) { - // Indexes - builder .HasIndex(entity => new { entity.DeviceId, entity.DateLastActivity }); diff --git a/Jellyfin.Server.Implementations/ModelConfiguration/DeviceOptionsConfiguration.cs b/Jellyfin.Server.Implementations/ModelConfiguration/DeviceOptionsConfiguration.cs index 0db1944b5..038afd752 100644 --- a/Jellyfin.Server.Implementations/ModelConfiguration/DeviceOptionsConfiguration.cs +++ b/Jellyfin.Server.Implementations/ModelConfiguration/DeviceOptionsConfiguration.cs @@ -12,8 +12,6 @@ namespace Jellyfin.Server.Implementations.ModelConfiguration /// public void Configure(EntityTypeBuilder builder) { - // Indexes - builder .HasIndex(entity => entity.DeviceId) .IsUnique(); diff --git a/Jellyfin.Server.Implementations/ModelConfiguration/DisplayPreferencesConfiguration.cs b/Jellyfin.Server.Implementations/ModelConfiguration/DisplayPreferencesConfiguration.cs index 807078803..9b437861b 100644 --- a/Jellyfin.Server.Implementations/ModelConfiguration/DisplayPreferencesConfiguration.cs +++ b/Jellyfin.Server.Implementations/ModelConfiguration/DisplayPreferencesConfiguration.cs @@ -12,15 +12,11 @@ namespace Jellyfin.Server.Implementations.ModelConfiguration /// public void Configure(EntityTypeBuilder builder) { - // Delete behaviour - builder .HasMany(d => d.HomeSections) .WithOne() .OnDelete(DeleteBehavior.Cascade); - // Indexes - builder .HasIndex(entity => new { entity.UserId, entity.ItemId, entity.Client }) .IsUnique(); diff --git a/Jellyfin.Server.Implementations/ModelConfiguration/PermissionConfiguration.cs b/Jellyfin.Server.Implementations/ModelConfiguration/PermissionConfiguration.cs index 56e76d88d..240e284c0 100644 --- a/Jellyfin.Server.Implementations/ModelConfiguration/PermissionConfiguration.cs +++ b/Jellyfin.Server.Implementations/ModelConfiguration/PermissionConfiguration.cs @@ -12,8 +12,6 @@ namespace Jellyfin.Server.Implementations.ModelConfiguration /// public void Configure(EntityTypeBuilder builder) { - // Indexes - // Used to get a user's permissions or a specific permission for a user. // Also prevents multiple values being created for a user. // Filtered over non-null user ids for when other entities (groups, API keys) get permissions diff --git a/Jellyfin.Server.Implementations/ModelConfiguration/PreferenceConfiguration.cs b/Jellyfin.Server.Implementations/ModelConfiguration/PreferenceConfiguration.cs index 3cd5f8afb..49c869c6a 100644 --- a/Jellyfin.Server.Implementations/ModelConfiguration/PreferenceConfiguration.cs +++ b/Jellyfin.Server.Implementations/ModelConfiguration/PreferenceConfiguration.cs @@ -12,8 +12,6 @@ namespace Jellyfin.Server.Implementations.ModelConfiguration /// public void Configure(EntityTypeBuilder builder) { - // Indexes - builder .HasIndex(p => new { p.UserId, p.Kind }) .HasFilter("[UserId] IS NOT NULL") diff --git a/Jellyfin.Server.Implementations/ModelConfiguration/UserConfiguration.cs b/Jellyfin.Server.Implementations/ModelConfiguration/UserConfiguration.cs index ee8831804..a369cf656 100644 --- a/Jellyfin.Server.Implementations/ModelConfiguration/UserConfiguration.cs +++ b/Jellyfin.Server.Implementations/ModelConfiguration/UserConfiguration.cs @@ -12,14 +12,10 @@ namespace Jellyfin.Server.Implementations.ModelConfiguration /// public void Configure(EntityTypeBuilder builder) { - // Collations - builder .Property(user => user.Username) .UseCollation("NOCASE"); - // Delete behavior - builder .HasOne(u => u.ProfileImage) .WithOne() @@ -52,8 +48,6 @@ namespace Jellyfin.Server.Implementations.ModelConfiguration .WithOne() .OnDelete(DeleteBehavior.Cascade); - // Indexes - builder .HasIndex(entity => entity.Username) .IsUnique(); -- cgit v1.2.3