Updated usage of internal user Id

This commit is contained in:
JPVenson 2024-11-23 22:39:39 +00:00
parent 0dd6dacc4f
commit 80cace4321

View File

@ -82,12 +82,12 @@ public class MigrateLibraryDb : IMigrationRoutine
_logger.LogInformation("Start moving TypedBaseItem."); _logger.LogInformation("Start moving TypedBaseItem.");
var typedBaseItemsQuery = """ var typedBaseItemsQuery = """
SELECT guid, type, data, StartDate, EndDate, ChannelId, IsMovie, SELECT guid, type, data, StartDate, EndDate, ChannelId, IsMovie,
IsSeries, EpisodeTitle, IsRepeat, CommunityRating, CustomRating, IndexNumber, IsLocked, PreferredMetadataLanguage, IsSeries, EpisodeTitle, IsRepeat, CommunityRating, CustomRating, IndexNumber, IsLocked, PreferredMetadataLanguage,
PreferredMetadataCountryCode, Width, Height, DateLastRefreshed, Name, Path, PremiereDate, Overview, ParentIndexNumber, PreferredMetadataCountryCode, Width, Height, DateLastRefreshed, Name, Path, PremiereDate, Overview, ParentIndexNumber,
ProductionYear, OfficialRating, ForcedSortName, RunTimeTicks, Size, DateCreated, DateModified, Genres, ParentId, TopParentId, ProductionYear, OfficialRating, ForcedSortName, RunTimeTicks, Size, DateCreated, DateModified, Genres, ParentId, TopParentId,
Audio, ExternalServiceId, IsInMixedFolder, DateLastSaved, LockedFields, Studios, Tags, TrailerTypes, OriginalTitle, PrimaryVersionId, Audio, ExternalServiceId, IsInMixedFolder, DateLastSaved, LockedFields, Studios, Tags, TrailerTypes, OriginalTitle, PrimaryVersionId,
DateLastMediaAdded, Album, LUFS, NormalizationGain, CriticRating, IsVirtualItem, SeriesName, UserDataKey, SeasonName, SeasonId, SeriesId, DateLastMediaAdded, Album, LUFS, NormalizationGain, CriticRating, IsVirtualItem, SeriesName, UserDataKey, SeasonName, SeasonId, SeriesId,
PresentationUniqueKey, InheritedParentalRatingValue, ExternalSeriesId, Tagline, ProviderIds, Images, ProductionLocations, ExtraIds, TotalBitrate, PresentationUniqueKey, InheritedParentalRatingValue, ExternalSeriesId, Tagline, ProviderIds, Images, ProductionLocations, ExtraIds, TotalBitrate,
ExtraType, Artists, AlbumArtists, ExternalId, SeriesPresentationUniqueKey, ShowId, OwnerId, MediaType FROM TypedBaseItems ExtraType, Artists, AlbumArtists, ExternalId, SeriesPresentationUniqueKey, ShowId, OwnerId, MediaType FROM TypedBaseItems
"""; """;
dbContext.BaseItems.ExecuteDelete(); dbContext.BaseItems.ExecuteDelete();
@ -155,7 +155,7 @@ public class MigrateLibraryDb : IMigrationRoutine
_logger.LogInformation("Start moving UserData."); _logger.LogInformation("Start moving UserData.");
var queryResult = connection.Query(""" var queryResult = connection.Query("""
SELECT key, userId, rating, played, playCount, isFavorite, playbackPositionTicks, lastPlayedDate, AudioStreamIndex, SubtitleStreamIndex FROM UserDatas SELECT key, userId, rating, played, playCount, isFavorite, playbackPositionTicks, lastPlayedDate, AudioStreamIndex, SubtitleStreamIndex FROM UserDatas
WHERE EXISTS(SELECT 1 FROM TypedBaseItems WHERE TypedBaseItems.UserDataKey = UserDatas.key) WHERE EXISTS(SELECT 1 FROM TypedBaseItems WHERE TypedBaseItems.UserDataKey = UserDatas.key)
"""); """);
@ -188,12 +188,12 @@ public class MigrateLibraryDb : IMigrationRoutine
_logger.LogInformation("Start moving MediaStreamInfos."); _logger.LogInformation("Start moving MediaStreamInfos.");
var mediaStreamQuery = """ var mediaStreamQuery = """
SELECT ItemId, StreamIndex, StreamType, Codec, Language, ChannelLayout, Profile, AspectRatio, Path, SELECT ItemId, StreamIndex, StreamType, Codec, Language, ChannelLayout, Profile, AspectRatio, Path,
IsInterlaced, BitRate, Channels, SampleRate, IsDefault, IsForced, IsExternal, Height, Width, IsInterlaced, BitRate, Channels, SampleRate, IsDefault, IsForced, IsExternal, Height, Width,
AverageFrameRate, RealFrameRate, Level, PixelFormat, BitDepth, IsAnamorphic, RefFrames, CodecTag, AverageFrameRate, RealFrameRate, Level, PixelFormat, BitDepth, IsAnamorphic, RefFrames, CodecTag,
Comment, NalLengthSize, IsAvc, Title, TimeBase, CodecTimeBase, ColorPrimaries, ColorSpace, ColorTransfer, Comment, NalLengthSize, IsAvc, Title, TimeBase, CodecTimeBase, ColorPrimaries, ColorSpace, ColorTransfer,
DvVersionMajor, DvVersionMinor, DvProfile, DvLevel, RpuPresentFlag, ElPresentFlag, BlPresentFlag, DvBlSignalCompatibilityId, IsHearingImpaired DvVersionMajor, DvVersionMinor, DvProfile, DvLevel, RpuPresentFlag, ElPresentFlag, BlPresentFlag, DvBlSignalCompatibilityId, IsHearingImpaired
FROM MediaStreams FROM MediaStreams
WHERE EXISTS(SELECT 1 FROM TypedBaseItems WHERE TypedBaseItems.guid = MediaStreams.ItemId) WHERE EXISTS(SELECT 1 FROM TypedBaseItems WHERE TypedBaseItems.guid = MediaStreams.ItemId)
"""; """;
dbContext.MediaStreamInfos.ExecuteDelete(); dbContext.MediaStreamInfos.ExecuteDelete();
@ -212,7 +212,7 @@ public class MigrateLibraryDb : IMigrationRoutine
_logger.LogInformation("Start moving People."); _logger.LogInformation("Start moving People.");
var personsQuery = """ var personsQuery = """
SELECT ItemId, Name, Role, PersonType, SortOrder FROM People SELECT ItemId, Name, Role, PersonType, SortOrder FROM People
WHERE EXISTS(SELECT 1 FROM TypedBaseItems WHERE TypedBaseItems.guid = People.ItemId) WHERE EXISTS(SELECT 1 FROM TypedBaseItems WHERE TypedBaseItems.guid = People.ItemId)
"""; """;
dbContext.Peoples.ExecuteDelete(); dbContext.Peoples.ExecuteDelete();
@ -288,8 +288,8 @@ public class MigrateLibraryDb : IMigrationRoutine
_logger.LogInformation("Start moving AncestorIds."); _logger.LogInformation("Start moving AncestorIds.");
var ancestorIdsQuery = """ var ancestorIdsQuery = """
SELECT ItemId, AncestorId, AncestorIdText FROM AncestorIds SELECT ItemId, AncestorId, AncestorIdText FROM AncestorIds
WHERE WHERE
EXISTS(SELECT 1 FROM TypedBaseItems WHERE TypedBaseItems.guid = AncestorIds.ItemId) EXISTS(SELECT 1 FROM TypedBaseItems WHERE TypedBaseItems.guid = AncestorIds.ItemId)
AND AND
EXISTS(SELECT 1 FROM TypedBaseItems WHERE TypedBaseItems.guid = AncestorIds.AncestorId) EXISTS(SELECT 1 FROM TypedBaseItems WHERE TypedBaseItems.guid = AncestorIds.AncestorId)
@ -333,12 +333,12 @@ public class MigrateLibraryDb : IMigrationRoutine
private UserData? GetUserData(ImmutableArray<User> users, SqliteDataReader dto) private UserData? GetUserData(ImmutableArray<User> users, SqliteDataReader dto)
{ {
var indexOfUser = dto.GetInt32(1); var internalUserId = dto.GetInt32(1);
var user = users.ElementAtOrDefault(indexOfUser - 1); var user = users.FirstOrDefault(e => e.InternalId == internalUserId);
if (user is null) if (user is null)
{ {
_logger.LogError("Tried to find user with index '{Idx}' but there are only '{MaxIdx}' users.", indexOfUser, users.Length); _logger.LogError("Tried to find user with index '{Idx}' but there are only '{MaxIdx}' users.", internalUserId, users.Length);
return null; return null;
} }