diff --git a/Jellyfin.Server/Migrations/Routines/MigrateAuthenticationDb.cs b/Jellyfin.Server/Migrations/Routines/MigrateAuthenticationDb.cs index afd7aee5d..ba0e33585 100644 --- a/Jellyfin.Server/Migrations/Routines/MigrateAuthenticationDb.cs +++ b/Jellyfin.Server/Migrations/Routines/MigrateAuthenticationDb.cs @@ -5,6 +5,7 @@ using Emby.Server.Implementations.Data; using Jellyfin.Data.Entities.Security; using Jellyfin.Server.Implementations; using MediaBrowser.Controller; +using MediaBrowser.Controller.Library; using Microsoft.Extensions.Logging; using SQLitePCL.pretty; @@ -20,6 +21,7 @@ namespace Jellyfin.Server.Migrations.Routines private readonly ILogger _logger; private readonly JellyfinDbProvider _dbProvider; private readonly IServerApplicationPaths _appPaths; + private readonly IUserManager _userManager; /// /// Initializes a new instance of the class. @@ -27,11 +29,17 @@ namespace Jellyfin.Server.Migrations.Routines /// The logger. /// The database provider. /// The server application paths. - public MigrateAuthenticationDb(ILogger logger, JellyfinDbProvider dbProvider, IServerApplicationPaths appPaths) + /// The user manager. + public MigrateAuthenticationDb( + ILogger logger, + JellyfinDbProvider dbProvider, + IServerApplicationPaths appPaths, + IUserManager userManager) { _logger = logger; _dbProvider = dbProvider; _appPaths = appPaths; + _userManager = userManager; } /// @@ -74,6 +82,14 @@ namespace Jellyfin.Server.Migrations.Routines } else { + var userId = new Guid(row[6].ToString()); + var user = _userManager.GetUserById(userId); + if (user is null) + { + // User doesn't exist, don't bring over the device. + continue; + } + dbContext.Devices.Add(new Device( new Guid(row[6].ToString()), row[3].ToString(),