Fixed: Migrating case-sensitive Preferred Word REGEX to Custom Formats

Closes #3322
This commit is contained in:
Qstick 2023-02-04 17:54:17 -06:00
commit 6635840972
2 changed files with 87 additions and 22 deletions

View file

@ -36,7 +36,7 @@ namespace NzbDrone.Core.Test.Datastore.Migration
}); });
}); });
var customFormats = db.Query<CustomFormat171>("SELECT \"Id\", \"Name\", \"IncludeCustomFormatWhenRenaming\", \"Specifications\" FROM \"CustomFormats\""); var customFormats = db.Query<CustomFormat063>("SELECT \"Id\", \"Name\", \"IncludeCustomFormatWhenRenaming\", \"Specifications\" FROM \"CustomFormats\"");
customFormats.Should().HaveCount(1); customFormats.Should().HaveCount(1);
customFormats.First().Name.Should().Be("Unnamed_1"); customFormats.First().Name.Should().Be("Unnamed_1");
@ -68,7 +68,7 @@ namespace NzbDrone.Core.Test.Datastore.Migration
}); });
}); });
var customFormats = db.Query<CustomFormat171>("SELECT \"Id\", \"Name\", \"IncludeCustomFormatWhenRenaming\", \"Specifications\" FROM \"CustomFormats\""); var customFormats = db.Query<CustomFormat063>("SELECT \"Id\", \"Name\", \"IncludeCustomFormatWhenRenaming\", \"Specifications\" FROM \"CustomFormats\"");
customFormats.Should().HaveCount(0); customFormats.Should().HaveCount(0);
} }
@ -97,7 +97,7 @@ namespace NzbDrone.Core.Test.Datastore.Migration
}); });
}); });
var customFormats = db.Query<CustomFormat171>("SELECT \"Id\", \"Name\", \"IncludeCustomFormatWhenRenaming\", \"Specifications\" FROM \"CustomFormats\""); var customFormats = db.Query<CustomFormat063>("SELECT \"Id\", \"Name\", \"IncludeCustomFormatWhenRenaming\", \"Specifications\" FROM \"CustomFormats\"");
customFormats.Should().HaveCount(1); customFormats.Should().HaveCount(1);
customFormats.First().Name.Should().Be("Unnamed_1"); customFormats.First().Name.Should().Be("Unnamed_1");
@ -129,7 +129,7 @@ namespace NzbDrone.Core.Test.Datastore.Migration
}); });
}); });
var releaseProfiles = db.Query<ReleaseProfile171>("SELECT \"Id\" FROM \"ReleaseProfiles\""); var releaseProfiles = db.Query<ReleaseProfile063>("SELECT \"Id\" FROM \"ReleaseProfiles\"");
releaseProfiles.Should().HaveCount(1); releaseProfiles.Should().HaveCount(1);
} }
@ -158,7 +158,7 @@ namespace NzbDrone.Core.Test.Datastore.Migration
}); });
}); });
var releaseProfiles = db.Query<ReleaseProfile171>("SELECT \"Id\" FROM \"ReleaseProfiles\""); var releaseProfiles = db.Query<ReleaseProfile063>("SELECT \"Id\" FROM \"ReleaseProfiles\"");
releaseProfiles.Should().HaveCount(0); releaseProfiles.Should().HaveCount(0);
} }
@ -187,7 +187,7 @@ namespace NzbDrone.Core.Test.Datastore.Migration
}); });
}); });
var customFormats = db.Query<CustomFormat171>("SELECT \"Id\", \"Name\", \"IncludeCustomFormatWhenRenaming\", \"Specifications\" FROM \"CustomFormats\""); var customFormats = db.Query<CustomFormat063>("SELECT \"Id\", \"Name\", \"IncludeCustomFormatWhenRenaming\", \"Specifications\" FROM \"CustomFormats\"");
customFormats.Should().HaveCount(1); customFormats.Should().HaveCount(1);
customFormats.First().Name.Should().Be("Unnamed_1"); customFormats.First().Name.Should().Be("Unnamed_1");
@ -237,7 +237,7 @@ namespace NzbDrone.Core.Test.Datastore.Migration
}); });
}); });
var customFormats = db.Query<CustomFormat171>("SELECT \"Id\", \"Name\", \"IncludeCustomFormatWhenRenaming\", \"Specifications\" FROM \"CustomFormats\""); var customFormats = db.Query<CustomFormat063>("SELECT \"Id\", \"Name\", \"IncludeCustomFormatWhenRenaming\", \"Specifications\" FROM \"CustomFormats\"");
customFormats.Should().HaveCount(2); customFormats.Should().HaveCount(2);
customFormats.First().Name.Should().Be("Unnamed_1"); customFormats.First().Name.Should().Be("Unnamed_1");
@ -275,7 +275,7 @@ namespace NzbDrone.Core.Test.Datastore.Migration
}); });
}); });
var customFormats = db.Query<CustomFormat171>("SELECT \"Id\", \"Name\", \"IncludeCustomFormatWhenRenaming\", \"Specifications\" FROM \"CustomFormats\""); var customFormats = db.Query<CustomFormat063>("SELECT \"Id\", \"Name\", \"IncludeCustomFormatWhenRenaming\", \"Specifications\" FROM \"CustomFormats\"");
customFormats.Should().HaveCount(2); customFormats.Should().HaveCount(2);
customFormats.First().Name.Should().Be("Unnamed_1_0"); customFormats.First().Name.Should().Be("Unnamed_1_0");
@ -315,7 +315,7 @@ namespace NzbDrone.Core.Test.Datastore.Migration
}); });
}); });
var customFormats = db.Query<QualityProfile171>("SELECT \"Id\", \"Name\", \"FormatItems\" FROM \"QualityProfiles\""); var customFormats = db.Query<QualityProfile063>("SELECT \"Id\", \"Name\", \"FormatItems\" FROM \"QualityProfiles\"");
customFormats.Should().HaveCount(1); customFormats.Should().HaveCount(1);
customFormats.First().FormatItems.Should().HaveCount(1); customFormats.First().FormatItems.Should().HaveCount(1);
@ -353,13 +353,75 @@ namespace NzbDrone.Core.Test.Datastore.Migration
}); });
}); });
var customFormats = db.Query<QualityProfile171>("SELECT \"Id\", \"Name\", \"FormatItems\" FROM \"QualityProfiles\""); var customFormats = db.Query<QualityProfile063>("SELECT \"Id\", \"Name\", \"FormatItems\" FROM \"QualityProfiles\"");
customFormats.Should().HaveCount(1); customFormats.Should().HaveCount(1);
customFormats.First().FormatItems.Should().HaveCount(1); customFormats.First().FormatItems.Should().HaveCount(1);
customFormats.First().FormatItems.First().Score.Should().Be(0); customFormats.First().FormatItems.First().Score.Should().Be(0);
} }
[Test]
public void should_migrate_case_sensitive_regex()
{
var db = WithMigrationTestDb(c =>
{
c.Insert.IntoTable("ReleaseProfiles").Row(new
{
Preferred = new[]
{
new
{
Key = "/somestring/",
Value = 2
}
}.ToJson(),
Required = "[]",
Ignored = "[]",
Tags = "[]",
IncludePreferredWhenRenaming = true,
Enabled = true,
IndexerId = 0
});
});
var customFormats = db.Query<CustomFormat063>("SELECT \"Id\", \"Name\", \"IncludeCustomFormatWhenRenaming\", \"Specifications\" FROM \"CustomFormats\"");
customFormats.Should().HaveCount(1);
customFormats.First().Specifications.Should().HaveCount(1);
customFormats.First().Specifications.First().Body.Value.Should().Be("somestring");
}
[Test]
public void should_migrate_case_insensitive_regex()
{
var db = WithMigrationTestDb(c =>
{
c.Insert.IntoTable("ReleaseProfiles").Row(new
{
Preferred = new[]
{
new
{
Key = "/somestring/i",
Value = 2
}
}.ToJson(),
Required = "[]",
Ignored = "[]",
Tags = "[]",
IncludePreferredWhenRenaming = true,
Enabled = true,
IndexerId = 0
});
});
var customFormats = db.Query<CustomFormat063>("SELECT \"Id\", \"Name\", \"IncludeCustomFormatWhenRenaming\", \"Specifications\" FROM \"CustomFormats\"");
customFormats.Should().HaveCount(1);
customFormats.First().Specifications.Should().HaveCount(1);
customFormats.First().Specifications.First().Body.Value.Should().Be("somestring");
}
[Test] [Test]
public void should_migrate_naming_configs() public void should_migrate_naming_configs()
{ {
@ -373,52 +435,52 @@ namespace NzbDrone.Core.Test.Datastore.Migration
}); });
}); });
var customFormats = db.Query<NamingConfig171>("SELECT \"StandardTrackFormat\", \"MultiDiscTrackFormat\" FROM \"NamingConfig\""); var customFormats = db.Query<NamingConfig063>("SELECT \"StandardTrackFormat\", \"MultiDiscTrackFormat\" FROM \"NamingConfig\"");
customFormats.Should().HaveCount(1); customFormats.Should().HaveCount(1);
customFormats.First().StandardTrackFormat.Should().Be("{Series Title} - S{season:00}E{episode:00} - {Episode Title} {Custom Formats } {Quality Full}"); customFormats.First().StandardTrackFormat.Should().Be("{Series Title} - S{season:00}E{episode:00} - {Episode Title} {Custom Formats } {Quality Full}");
customFormats.First().MultiDiscTrackFormat.Should().Be("{Series Title} - {Air-Date} - {Episode Title} {Custom.Formats } {Quality Full}"); customFormats.First().MultiDiscTrackFormat.Should().Be("{Series Title} - {Air-Date} - {Episode Title} {Custom.Formats } {Quality Full}");
} }
private class NamingConfig171 private class NamingConfig063
{ {
public string StandardTrackFormat { get; set; } public string StandardTrackFormat { get; set; }
public string MultiDiscTrackFormat { get; set; } public string MultiDiscTrackFormat { get; set; }
} }
private class ReleaseProfile171 private class ReleaseProfile063
{ {
public int Id { get; set; } public int Id { get; set; }
} }
private class QualityProfile171 private class QualityProfile063
{ {
public int Id { get; set; } public int Id { get; set; }
public string Name { get; set; } public string Name { get; set; }
public List<FormatItem171> FormatItems { get; set; } public List<FormatItem063> FormatItems { get; set; }
} }
private class FormatItem171 private class FormatItem063
{ {
public int Format { get; set; } public int Format { get; set; }
public int Score { get; set; } public int Score { get; set; }
} }
private class CustomFormat171 private class CustomFormat063
{ {
public int Id { get; set; } public int Id { get; set; }
public string Name { get; set; } public string Name { get; set; }
public bool IncludeCustomFormatWhenRenaming { get; set; } public bool IncludeCustomFormatWhenRenaming { get; set; }
public List<CustomFormatSpec171> Specifications { get; set; } public List<CustomFormatSpec063> Specifications { get; set; }
} }
private class CustomFormatSpec171 private class CustomFormatSpec063
{ {
public string Type { get; set; } public string Type { get; set; }
public CustomFormatReleaseTitleSpec171 Body { get; set; } public CustomFormatReleaseTitleSpec063 Body { get; set; }
} }
private class CustomFormatReleaseTitleSpec171 private class CustomFormatReleaseTitleSpec063
{ {
public int Order { get; set; } public int Order { get; set; }
public string ImplementationName { get; set; } public string ImplementationName { get; set; }

View file

@ -148,7 +148,10 @@ namespace NzbDrone.Core.Datastore.Migration
foreach (var term in data) foreach (var term in data)
{ {
var regexTerm = term.Key.TrimStart('/').TrimEnd("/i"); var regexTerm = term.Key
.TrimStart('/')
.TrimEnd('/')
.TrimEnd("/i");
// Validate Regex before creating a CF // Validate Regex before creating a CF
try try