Browse Source

Use NOCASE collation and index on username field

Patrick Barron 4 years ago
parent
commit
a07ad71222
1 changed files with 13 additions and 0 deletions
  1. 13 0
      Jellyfin.Server.Implementations/JellyfinDb.cs

+ 13 - 0
Jellyfin.Server.Implementations/JellyfinDb.cs

@@ -149,6 +149,14 @@ namespace Jellyfin.Server.Implementations
 
             modelBuilder.HasDefaultSchema("jellyfin");
 
+            // Collations
+
+            modelBuilder.Entity<User>()
+                .Property(user => user.Username)
+                .UseCollation("NOCASE");
+
+            // Delete behavior
+
             modelBuilder.Entity<User>()
                 .HasOne(u => u.ProfileImage)
                 .WithOne()
@@ -174,6 +182,11 @@ namespace Jellyfin.Server.Implementations
                 .WithOne()
                 .OnDelete(DeleteBehavior.Cascade);
 
+            // Indexes
+
+            modelBuilder.Entity<User>()
+                .HasIndex(entity => entity.Username)
+                .IsUnique();
 
             modelBuilder.Entity<DisplayPreferences>()
                 .HasIndex(entity => new { entity.UserId, entity.ItemId, entity.Client })