| | 1 | | using Jellyfin.Database.Implementations.Entities; |
| | 2 | | using Microsoft.EntityFrameworkCore; |
| | 3 | | using Microsoft.EntityFrameworkCore.Metadata.Builders; |
| | 4 | |
|
| | 5 | | namespace Jellyfin.Database.Implementations.ModelConfiguration |
| | 6 | | { |
| | 7 | | /// <summary> |
| | 8 | | /// FluentAPI configuration for the User entity. |
| | 9 | | /// </summary> |
| | 10 | | public class UserConfiguration : IEntityTypeConfiguration<User> |
| | 11 | | { |
| | 12 | | /// <inheritdoc/> |
| | 13 | | public void Configure(EntityTypeBuilder<User> builder) |
| | 14 | | { |
| 2 | 15 | | builder |
| 2 | 16 | | .Property(user => user.Username); |
| | 17 | |
|
| 2 | 18 | | builder |
| 2 | 19 | | .HasOne(u => u.ProfileImage) |
| 2 | 20 | | .WithOne() |
| 2 | 21 | | .OnDelete(DeleteBehavior.Cascade); |
| | 22 | |
|
| 2 | 23 | | builder |
| 2 | 24 | | .HasMany(u => u.Permissions) |
| 2 | 25 | | .WithOne() |
| 2 | 26 | | .HasForeignKey(p => p.UserId) |
| 2 | 27 | | .OnDelete(DeleteBehavior.Cascade); |
| | 28 | |
|
| 2 | 29 | | builder |
| 2 | 30 | | .HasMany(u => u.Preferences) |
| 2 | 31 | | .WithOne() |
| 2 | 32 | | .HasForeignKey(p => p.UserId) |
| 2 | 33 | | .OnDelete(DeleteBehavior.Cascade); |
| | 34 | |
|
| 2 | 35 | | builder |
| 2 | 36 | | .HasMany(u => u.AccessSchedules) |
| 2 | 37 | | .WithOne() |
| 2 | 38 | | .OnDelete(DeleteBehavior.Cascade); |
| | 39 | |
|
| 2 | 40 | | builder |
| 2 | 41 | | .HasMany(u => u.DisplayPreferences) |
| 2 | 42 | | .WithOne() |
| 2 | 43 | | .OnDelete(DeleteBehavior.Cascade); |
| | 44 | |
|
| 2 | 45 | | builder |
| 2 | 46 | | .HasMany(u => u.ItemDisplayPreferences) |
| 2 | 47 | | .WithOne() |
| 2 | 48 | | .OnDelete(DeleteBehavior.Cascade); |
| | 49 | |
|
| 2 | 50 | | builder |
| 2 | 51 | | .HasIndex(entity => entity.Username) |
| 2 | 52 | | .IsUnique(); |
| 2 | 53 | | } |
| | 54 | | } |
| | 55 | | } |