Fixed: Alternative Titles appearing multiple times. Duplicate alt titles will be deleted. Fixes #2040

Leonardo Galli 7 years ago
parent e7c9217dc0
commit 25b0a52ba6

@ -59,7 +59,7 @@ namespace NzbDrone.Core.Datastore
public IEnumerable<TModel> All() public IEnumerable<TModel> All()
{ {
return DataMapper.Query<TModel>().ToList(); return Query.ToList();
} }
public int Count() public int Count()

@ -0,0 +1,32 @@
using System.Collections.Generic;
using System.Data;
using FluentMigrator;
using Newtonsoft.Json.Linq;
using NzbDrone.Common.Extensions;
using NzbDrone.Common.Serializer;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(141)]
public class fix_duplicate_alt_titles : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Execute.WithConnection(RenameUrlToBaseUrl);
Alter.Table("AlternativeTitles").AlterColumn("CleanTitle").AsString().Unique();
}
private void RenameUrlToBaseUrl(IDbConnection conn, IDbTransaction tran)
{
using (var cmd = conn.CreateCommand())
{
cmd.Transaction = tran;
cmd.CommandText = "DELETE FROM AlternativeTitles WHERE rowid NOT IN ( SELECT MIN(rowid) FROM AlternativeTitles GROUP BY CleanTitle )";
cmd.ExecuteNonQuery();
}
}
}
}

@ -126,6 +126,7 @@
<Compile Include="Authentication\UserService.cs" /> <Compile Include="Authentication\UserService.cs" />
<Compile Include="Datastore\Migration\123_create_netimport_table.cs" /> <Compile Include="Datastore\Migration\123_create_netimport_table.cs" />
<Compile Include="Datastore\Migration\140_add_alternative_titles_table.cs" /> <Compile Include="Datastore\Migration\140_add_alternative_titles_table.cs" />
<Compile Include="Datastore\Migration\141_fix_duplicate_alt_titles.cs" />
<Compile Include="Housekeeping\Housekeepers\CleanupOrphanedAlternativeTitles.cs" /> <Compile Include="Housekeeping\Housekeepers\CleanupOrphanedAlternativeTitles.cs" />
<Compile Include="MediaFiles\Events\MovieFileUpdatedEvent.cs" /> <Compile Include="MediaFiles\Events\MovieFileUpdatedEvent.cs" />
<Compile Include="Datastore\Migration\134_add_remux_qualities_for_the_wankers.cs" /> <Compile Include="Datastore\Migration\134_add_remux_qualities_for_the_wankers.cs" />

Loading…
Cancel
Save