WIP: Fix migration to DB version 23 (#571)

* Watch out for malformed AlbumReleases in Albums

Don't try to insert if Title is empty and catch and SQLite exceptions.

* Better fix for migration

Filter out null titles and duplicate release ids

Revert "Watch out for malformed AlbumReleases in Albums"

This reverts commit b9f707dc2f.

* Purge tracks linked to bad albumrelease

* fixup! migration missing titles, releases not in remote, artist cleaning
pull/573/head
ta264 6 years ago committed by Qstick
parent c392569a63
commit 6723f32abb

@ -5,6 +5,8 @@ using System.Collections.Generic;
using NzbDrone.Core.Music; using NzbDrone.Core.Music;
using System.Data; using System.Data;
using System; using System;
using System.Linq;
using NzbDrone.Common.Extensions;
namespace NzbDrone.Core.Datastore.Migration namespace NzbDrone.Core.Datastore.Migration
{ {
@ -158,7 +160,8 @@ namespace NzbDrone.Core.Datastore.Migration
private void PopulateReleases(IDbConnection conn, IDbTransaction tran) private void PopulateReleases(IDbConnection conn, IDbTransaction tran)
{ {
var releases = ReadReleasesFromAlbums(conn, tran); var releases = ReadReleasesFromAlbums(conn, tran);
WriteReleasesToReleases(releases,conn, tran); var dupeFreeReleases = releases.DistinctBy(x => x.ForeignReleaseId).ToList();
WriteReleasesToReleases(dupeFreeReleases, conn, tran);
} }
public class LegacyAlbumRelease : IEmbeddedDocument public class LegacyAlbumRelease : IEmbeddedDocument
@ -200,7 +203,7 @@ namespace NzbDrone.Core.Datastore.Migration
releases.Add(new AlbumRelease { releases.Add(new AlbumRelease {
AlbumId = rgId, AlbumId = rgId,
ForeignReleaseId = albumRelease.Id, ForeignReleaseId = albumRelease.Id,
Title = albumRelease.Title, Title = albumRelease.Title.IsNotNullOrWhiteSpace() ? albumRelease.Title : "",
Status = "", Status = "",
Duration = 0, Duration = 0,
Label = albumRelease.Label, Label = albumRelease.Label,

@ -20,7 +20,8 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
SELECT ArtistMetadata.Id FROM ArtistMetadata SELECT ArtistMetadata.Id FROM ArtistMetadata
LEFT OUTER JOIN Albums ON Albums.ArtistMetadataId = ArtistMetadata.Id LEFT OUTER JOIN Albums ON Albums.ArtistMetadataId = ArtistMetadata.Id
LEFT OUTER JOIN Tracks ON Tracks.ArtistMetadataId = ArtistMetadata.Id LEFT OUTER JOIN Tracks ON Tracks.ArtistMetadataId = ArtistMetadata.Id
WHERE Albums.Id IS NULL AND Tracks.Id IS NULL)"); LEFT OUTER JOIN Artists ON Artists.ArtistMetadataId = ArtistMetadata.Id
WHERE Albums.Id IS NULL AND Tracks.Id IS NULL AND Artists.Id IS NULL)");
} }
} }
} }

@ -112,7 +112,7 @@ namespace NzbDrone.Core.Music
album.AlbumReleases = new List<AlbumRelease>(); album.AlbumReleases = new List<AlbumRelease>();
var remoteReleases = albumInfo.AlbumReleases.Value.DistinctBy(m => m.ForeignReleaseId).ToList(); var remoteReleases = albumInfo.AlbumReleases.Value.DistinctBy(m => m.ForeignReleaseId).ToList();
var existingReleases = _releaseService.GetReleasesByForeignReleaseId(remoteReleases.Select(x => x.ForeignReleaseId).ToList()); var existingReleases = _releaseService.GetReleasesByAlbum(album.Id);
var newReleaseList = new List<AlbumRelease>(); var newReleaseList = new List<AlbumRelease>();
var updateReleaseList = new List<AlbumRelease>(); var updateReleaseList = new List<AlbumRelease>();

Loading…
Cancel
Save