parent
62221c2a7f
commit
96db74494a
@ -1,5 +1,7 @@
|
|||||||
import migrateAddAuthorDefaults from './migrateAddAuthorDefaults';
|
import migrateAddAuthorDefaults from './migrateAddAuthorDefaults';
|
||||||
|
import migrateAuthorSortKey from './migrateAuthorSortKey';
|
||||||
|
|
||||||
export default function migrate(persistedState) {
|
export default function migrate(persistedState) {
|
||||||
migrateAddAuthorDefaults(persistedState);
|
migrateAddAuthorDefaults(persistedState);
|
||||||
|
migrateAuthorSortKey(persistedState);
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,15 @@
|
|||||||
|
import { get, set } from 'lodash';
|
||||||
|
|
||||||
|
const TABLES_TO_MIGRATE = ['blacklist', 'history', 'queue.paged', 'wanted.missing', 'wanted.cutoffUnmet'];
|
||||||
|
|
||||||
|
export default function migrateAuthorSortKey(persistedState) {
|
||||||
|
|
||||||
|
for (const table of TABLES_TO_MIGRATE) {
|
||||||
|
const key = `${table}.sortKey`;
|
||||||
|
const sortKey = get(persistedState, key);
|
||||||
|
|
||||||
|
if (sortKey === 'authors.sortName') {
|
||||||
|
set(persistedState, key, 'authorMetadata.sortName');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,42 @@
|
|||||||
|
using FluentAssertions;
|
||||||
|
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using NzbDrone.Common.Extensions;
|
||||||
|
|
||||||
|
namespace NzbDrone.Common.Test.ExtensionTests.StringExtensionTests
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
public class ToSortNameFixture
|
||||||
|
{
|
||||||
|
[TestCase("a[b]c(d)e{f}g<h>i", "aceg<h>i")]
|
||||||
|
[TestCase("a[[b]c(d)e{f}]g(h(i)j[k]l{m})n{{{o}}}p", "agnp")]
|
||||||
|
[TestCase("a[b(c]d)e", "ae")]
|
||||||
|
[TestCase("a{b(c}d)e", "ae")]
|
||||||
|
[TestCase("a]b}c)d", "abcd")]
|
||||||
|
[TestCase("a[b]c]d(e)f{g)h}i}j)k]l", "acdfijkl")]
|
||||||
|
[TestCase("a]b[c", "ab")]
|
||||||
|
[TestCase("a(b[c]d{e}f", "a")]
|
||||||
|
[TestCase("a{b}c{d[e]f(g)h", "ac")]
|
||||||
|
public void should_remove_brackets(string input, string expected)
|
||||||
|
{
|
||||||
|
input.RemoveBracketedText().Should().Be(expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestCase("Aristotle", "Aristotle")]
|
||||||
|
[TestCase("Mr. Dr Prof.", "Mr. Dr Prof.")]
|
||||||
|
[TestCase("Senior Inc", "Senior Inc")]
|
||||||
|
[TestCase("Don \"Team\" Smith", "Smith, Don \"Team\"")]
|
||||||
|
[TestCase("Don Team Smith", "Don Team Smith")]
|
||||||
|
[TestCase("National Lampoon", "National Lampoon")]
|
||||||
|
[TestCase("Jane Doe", "Doe, Jane")]
|
||||||
|
[TestCase("Mrs. Jane Q. Doe III", "Doe, Jane Q. III")]
|
||||||
|
[TestCase("Leonardo Da Vinci", "Da Vinci, Leonardo")]
|
||||||
|
[TestCase("Van Gogh", "Van Gogh")]
|
||||||
|
[TestCase("Van", "Van")]
|
||||||
|
[TestCase("John [x]von Neumann (III)", "von Neumann, John")]
|
||||||
|
public void should_get_sort_name(string input, string expected)
|
||||||
|
{
|
||||||
|
input.ToSortName().Should().Be(expected);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,41 @@
|
|||||||
|
using System.Data;
|
||||||
|
using System.Linq;
|
||||||
|
using Dapper;
|
||||||
|
using FluentMigrator;
|
||||||
|
using NzbDrone.Common.Extensions;
|
||||||
|
using NzbDrone.Core.Datastore.Migration.Framework;
|
||||||
|
|
||||||
|
namespace NzbDrone.Core.Datastore.Migration
|
||||||
|
{
|
||||||
|
[Migration(009)]
|
||||||
|
public class update_author_sort_name : NzbDroneMigrationBase
|
||||||
|
{
|
||||||
|
protected override void MainDbUpgrade()
|
||||||
|
{
|
||||||
|
Alter.Table("AuthorMetadata").AddColumn("SortName").AsString().Nullable();
|
||||||
|
Execute.WithConnection(MigrateAuthorSortName);
|
||||||
|
Alter.Table("AuthorMetadata").AlterColumn("SortName").AsString().NotNullable();
|
||||||
|
|
||||||
|
Delete.Column("SortName").FromTable("Authors");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void MigrateAuthorSortName(IDbConnection conn, IDbTransaction tran)
|
||||||
|
{
|
||||||
|
var rows = conn.Query<AuthorName>("SELECT AuthorMetadata.Id, AuthorMetadata.Name FROM AuthorMetadata", transaction: tran);
|
||||||
|
|
||||||
|
foreach (var row in rows)
|
||||||
|
{
|
||||||
|
row.SortName = row.Name.ToSortName().ToLower();
|
||||||
|
}
|
||||||
|
|
||||||
|
var sql = "UPDATE AuthorMetadata SET SortName = @SortName WHERE Id = @Id";
|
||||||
|
conn.Execute(sql, rows, transaction: tran);
|
||||||
|
}
|
||||||
|
|
||||||
|
private class AuthorName : ModelBase
|
||||||
|
{
|
||||||
|
public string Name { get; set; }
|
||||||
|
public string SortName { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue