From ce62cff57de234a67b2e89c6afb7747758b6593e Mon Sep 17 00:00:00 2001 From: Joseph Milazzo Date: Thu, 27 Apr 2017 18:28:36 -0500 Subject: [PATCH] Changed the db to represent compilations. By default a track will have a single albumId and a list of artistIds. If the album is a compilation, we will use Various Artists to align with Plex, iTunes, and Amazon. --- .../Datastore/Migration/111_setup_music.cs | 18 +++++------------- src/NzbDrone.Core/Datastore/TableMapping.cs | 7 ++----- src/NzbDrone.Core/Music/Compilation.cs | 19 ------------------- src/NzbDrone.Core/Music/Track.cs | 1 + 4 files changed, 8 insertions(+), 37 deletions(-) delete mode 100644 src/NzbDrone.Core/Music/Compilation.cs diff --git a/src/NzbDrone.Core/Datastore/Migration/111_setup_music.cs b/src/NzbDrone.Core/Datastore/Migration/111_setup_music.cs index 7fe64acfe..48f921f30 100644 --- a/src/NzbDrone.Core/Datastore/Migration/111_setup_music.cs +++ b/src/NzbDrone.Core/Datastore/Migration/111_setup_music.cs @@ -30,12 +30,11 @@ namespace NzbDrone.Core.Datastore.Migration ; Create.TableForModel("Albums") - .WithColumn("AlbumId").AsInt32() // Does this map to collectionId? - .WithColumn("CompilationId").AsInt32() - .WithColumn("Compilation").AsBoolean() + .WithColumn("AlbumId").AsInt32() + .WithColumn("ArtistId").AsInt32() .WithColumn("Title").AsString() .WithColumn("Year").AsInt32() - .WithColumn("Image").AsInt32() // Is this needed? + .WithColumn("Image").AsInt32() .WithColumn("TrackCount").AsInt32() .WithColumn("DiscCount").AsInt32() .WithColumn("Monitored").AsBoolean(); @@ -43,8 +42,7 @@ namespace NzbDrone.Core.Datastore.Migration Create.TableForModel("Tracks") .WithColumn("ItunesTrackId").AsInt32().Unique() .WithColumn("AlbumId").AsInt32() - .WithColumn("CompilationId").AsInt32().Nullable() - .WithColumn("Compilation").AsBoolean().WithDefaultValue("False") + .WithColumn("ArtistsId").AsString().Nullable() .WithColumn("TrackNumber").AsInt32() .WithColumn("Title").AsString().Nullable() .WithColumn("Ignored").AsBoolean().Nullable() @@ -53,10 +51,7 @@ namespace NzbDrone.Core.Datastore.Migration .WithColumn("TrackCensoredName").AsString().Nullable() .WithColumn("TrackFileId").AsInt32().Nullable() .WithColumn("ReleaseDate").AsDateTime().Nullable(); - //.WithColumn("AbsoluteEpisodeNumber").AsInt32().Nullable() - //.WithColumn("SceneAbsoluteEpisodeNumber").AsInt32().Nullable() - //.WithColumn("SceneSeasonNumber").AsInt32().Nullable() - //.WithColumn("SceneEpisodeNumber").AsInt32().Nullable(); + Create.TableForModel("TrackFiles") .WithColumn("ArtistId").AsInt32() @@ -66,9 +61,6 @@ namespace NzbDrone.Core.Datastore.Migration .WithColumn("DateAdded").AsDateTime() .WithColumn("AlbumId").AsInt32(); // How does this impact stand alone tracks? - Create.TableForModel("Compilation") - .WithColumn("CompilationId").AsInt32().Unique() - .WithColumn("ArtistId").AsString().Nullable(); } } diff --git a/src/NzbDrone.Core/Datastore/TableMapping.cs b/src/NzbDrone.Core/Datastore/TableMapping.cs index ce619b72b..dcf8c0924 100644 --- a/src/NzbDrone.Core/Datastore/TableMapping.cs +++ b/src/NzbDrone.Core/Datastore/TableMapping.cs @@ -103,17 +103,14 @@ namespace NzbDrone.Core.Datastore .For("Tracks") .LazyLoad(condition: parent => parent.Id > 0, query: (db, parent) => db.Query().Where(c => c.ItunesTrackId == parent.Id).ToList()) - .HasOne(file => file.Artist, file => file.AlbumId); + .HasOne(file => file.Artist, file => file.AlbumId); Mapper.Entity().RegisterModel("Tracks") //.Ignore(e => e.SeriesTitle) .Ignore(e => e.Album) .Ignore(e => e.HasFile) .Relationship() - .HasOne(track => track.TrackFile, track => track.TrackFileId); - - Mapper.Entity().RegisterModel("Compilation") - .Relationships.AutoMapICollectionOrComplexProperties(); //TODO: Figure out how to map this Table + .HasOne(track => track.TrackFile, track => track.TrackFileId); // TODO: Check lazy load for artists Mapper.Entity().RegisterModel("QualityDefinitions") .Ignore(d => d.Weight); diff --git a/src/NzbDrone.Core/Music/Compilation.cs b/src/NzbDrone.Core/Music/Compilation.cs deleted file mode 100644 index 923e6d7f3..000000000 --- a/src/NzbDrone.Core/Music/Compilation.cs +++ /dev/null @@ -1,19 +0,0 @@ -using NzbDrone.Core.Datastore; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace NzbDrone.Core.Music -{ - public class Compilation : ModelBase - { - public Compilation() - { - - } - - public int CompilationId { get; set; } - public LazyList Artists { get; set; } - } -} diff --git a/src/NzbDrone.Core/Music/Track.cs b/src/NzbDrone.Core/Music/Track.cs index 89793d514..65e28231b 100644 --- a/src/NzbDrone.Core/Music/Track.cs +++ b/src/NzbDrone.Core/Music/Track.cs @@ -19,6 +19,7 @@ namespace NzbDrone.Core.Music public int ItunesTrackId { get; set; } public int AlbumId { get; set; } + public LazyLoaded ArtistsId { get; set; } public int CompilationId { get; set; } public bool Compilation { get; set; } public int TrackNumber { get; set; }