feat!: Remove old migration steps

The following migration steps were removed:

- `MigrateTrashUpdaterAppDataDir`
- `MigrateTrashYml`
pull/201/head
Robert Dailey 1 year ago
parent 21a63ab8e1
commit 5609853321

@ -24,6 +24,7 @@ changes you may need to make.
- **BREAKING**: Array-style instances are no longer supported.
- **BREAKING**: Remove deprecated CLI commands: `radarr`, `sonarr`, and `create-config`.
- **BREAKING**: Removed `reset_unmatched_scores` support under quality profile score section.
- **BREAKING**: Migration steps that dealt with the old `trash.yml` have been removed.
## [4.4.1] - 2023-04-08

@ -1,5 +1,4 @@
using Recyclarr.Cli.Migration;
using Recyclarr.Cli.Migration.Steps;
using Recyclarr.Cli.TestLibrary;
using Spectre.Console.Testing;
@ -9,20 +8,6 @@ namespace Recyclarr.Cli.Tests.Migration;
[Parallelizable(ParallelScope.All)]
public class MigrationExecutorTest : CliIntegrationFixture
{
[Test]
public void Migration_steps_are_in_expected_order()
{
var steps = Resolve<IEnumerable<IMigrationStep>>();
var orderedSteps = steps.OrderBy(x => x.Order).Select(x => x.GetType()).ToList();
orderedSteps.Should().BeEquivalentTo(
new[]
{
typeof(MigrateTrashYml),
typeof(MigrateTrashUpdaterAppDataDir)
},
config => config.WithStrictOrdering());
}
[Test]
public void Step_not_executed_if_check_returns_false()
{

@ -1,78 +0,0 @@
using System.IO.Abstractions;
using Recyclarr.Cli.Migration.Steps;
using Recyclarr.TestLibrary.AutoFixture;
using Recyclarr.TrashLib.TestLibrary;
namespace Recyclarr.Cli.Tests.Migration.Steps;
[TestFixture]
[Parallelizable(ParallelScope.All)]
public class MigrateTrashUpdaterAppDataDirTest
{
[Test, AutoMockData]
public void Migration_check_returns_true_if_trash_updater_dir_exists(
[Frozen(Matching.ImplementedInterfaces)] TestAppPaths paths,
MigrateTrashUpdaterAppDataDir sut)
{
paths.AppDataDirectory.Parent.SubDirectory("trash-updater").Create();
sut.CheckIfNeeded().Should().BeTrue();
}
[Test, AutoMockData]
public void Migration_check_returns_false_if_trash_updater_dir_doesnt_exists(
MigrateTrashUpdaterAppDataDir sut)
{
sut.CheckIfNeeded().Should().BeFalse();
}
[Test, AutoMockData]
public void Migration_throws_if_recyclarr_yml_already_exists(
[Frozen(Matching.ImplementedInterfaces)] MockFileSystem fs,
[Frozen(Matching.ImplementedInterfaces)] TestAppPaths paths,
MigrateTrashUpdaterAppDataDir sut)
{
fs.AddEmptyFile(sut.OldPath.File("recyclarr.yml"));
fs.AddEmptyFile(sut.NewPath.File("recyclarr.yml"));
var act = () => sut.Execute(null);
act.Should().Throw<IOException>();
}
[Test, AutoMockData]
public void Migration_success(
[Frozen(Matching.ImplementedInterfaces)] MockFileSystem fs,
[Frozen(Matching.ImplementedInterfaces)] TestAppPaths paths,
MigrateTrashUpdaterAppDataDir sut)
{
// Add file instead of directory since the migration step only operates on files
var baseDir = sut.OldPath;
fs.AddEmptyFile(baseDir.File("settings.yml"));
fs.AddEmptyFile(baseDir.File("recyclarr.yml"));
fs.AddEmptyFile(baseDir.File("this-gets-ignored.yml"));
fs.AddDirectory(baseDir.SubDirectory("repo"));
fs.AddDirectory(baseDir.SubDirectory("cache"));
fs.AddEmptyFile(baseDir.File("cache/sonarr/test.txt"));
sut.Execute(null);
var expectedBase = sut.NewPath;
fs.AllDirectories.Should().NotContain(x => x.Contains("trash-updater"));
fs.AllFiles.Should().BeEquivalentTo(
expectedBase.File("settings.yml").FullName,
expectedBase.File("recyclarr.yml").FullName,
expectedBase.SubDirectory("cache").SubDirectory("sonarr").File("test.txt").FullName);
}
[Test, AutoMockData]
public void No_exception_if_source_files_do_not_exist(
[Frozen(Matching.ImplementedInterfaces)] MockFileSystem fs,
[Frozen(Matching.ImplementedInterfaces)] TestAppPaths paths,
MigrateTrashUpdaterAppDataDir sut)
{
var act = () => sut.Execute(null);
act.Should().NotThrow();
}
}

@ -1,57 +0,0 @@
using System.Text.RegularExpressions;
using Recyclarr.Cli.Migration.Steps;
using Recyclarr.TestLibrary.AutoFixture;
namespace Recyclarr.Cli.Tests.Migration.Steps;
[TestFixture]
[Parallelizable(ParallelScope.All)]
public partial class MigrateTrashYmlTest
{
private static readonly string BasePath = AppContext.BaseDirectory;
[Test, AutoMockData]
public void Migration_check_returns_true_if_trash_yml_exists(
[Frozen(Matching.ImplementedInterfaces)] MockFileSystem fs,
MigrateTrashYml sut)
{
fs.AddFile(Path.Combine(BasePath, "trash.yml"), new MockFileData(""));
sut.CheckIfNeeded().Should().BeTrue();
}
[Test, AutoMockData]
public void Migration_check_returns_false_if_trash_yml_doesnt_exists(
[Frozen(Matching.ImplementedInterfaces)] MockFileSystem fs,
MigrateTrashYml sut)
{
sut.CheckIfNeeded().Should().BeFalse();
}
[Test, AutoMockData]
public void Migration_throws_if_recyclarr_yml_already_exists(
[Frozen(Matching.ImplementedInterfaces)] MockFileSystem fs,
MigrateTrashYml sut)
{
fs.AddFile(Path.Combine(BasePath, "recyclarr.yml"), new MockFileData(""));
var act = () => sut.Execute(null);
act.Should().Throw<IOException>();
}
[Test, AutoMockData]
public void Migration_success(
[Frozen(Matching.ImplementedInterfaces)] MockFileSystem fs,
MigrateTrashYml sut)
{
const string expectedData = "fake contents";
fs.AddFile(Path.Combine(BasePath, "trash.yml"), expectedData);
sut.Execute(null);
fs.AllFiles.Should().ContainSingle(x => RecyclarrYmlRegex().IsMatch(x));
}
[GeneratedRegex("[/\\\\]recyclarr\\.yml$", RegexOptions.None, 1000)]
private static partial Regex RecyclarrYmlRegex();
}

@ -1,5 +1,4 @@
using Autofac;
using Recyclarr.Cli.Migration.Steps;
namespace Recyclarr.Cli.Migration;
@ -13,8 +12,7 @@ public class MigrationAutofacModule : Module
// Migration Steps
builder.RegisterTypes
(
typeof(MigrateTrashYml),
typeof(MigrateTrashUpdaterAppDataDir)
// Add migration steps here in order of execution
)
.As<IMigrationStep>();
}

@ -1,87 +0,0 @@
using System.IO.Abstractions;
using JetBrains.Annotations;
using Recyclarr.Common.Extensions;
using Recyclarr.TrashLib.Startup;
using Spectre.Console;
namespace Recyclarr.Cli.Migration.Steps;
/// <remarks>
/// Implemented on 4/30/2022.
/// </remarks>
[UsedImplicitly]
public class MigrateTrashUpdaterAppDataDir : IMigrationStep
{
private readonly IFileSystem _fs;
private readonly IAppPaths _paths;
public int Order => 20;
public bool Required => true;
public string Description
=> $"Merge files from old app data directory `{OldPath}` into `{NewPath}` and delete old directory";
public IReadOnlyCollection<string> Remediation => new[]
{
$"Check if `{NewPath}` already exists. If so, manually copy all files from `{OldPath}` and delete it to fix the error.",
$"Ensure Recyclarr has permission to recursively delete {OldPath}",
$"Ensure Recyclarr has permission to create and move files into {NewPath}"
};
public MigrateTrashUpdaterAppDataDir(IFileSystem fs, IAppPaths paths)
{
_fs = fs;
_paths = paths;
}
public IDirectoryInfo NewPath
{
get
{
// Will be something like `/home/user/.config/recyclarr`.
var path = _paths.AppDataDirectory;
path.Refresh();
return path;
}
}
public IDirectoryInfo OldPath => NewPath.Parent.SubDirectory("trash-updater");
public bool CheckIfNeeded()
{
return OldPath.Exists;
}
public void Execute(IAnsiConsole? console)
{
MoveDirectory("cache", console);
MoveFile("recyclarr.yml");
MoveFile("settings.yml");
if (OldPath.Exists)
{
OldPath.Delete(true);
}
}
private void MoveDirectory(string directory, IAnsiConsole? console)
{
var oldPath = OldPath.SubDirectory(directory);
if (oldPath.Exists)
{
_fs.MergeDirectory(
oldPath,
NewPath.SubDirectory(directory),
console);
}
}
private void MoveFile(string file)
{
var recyclarrYaml = OldPath.File(file);
if (recyclarrYaml.Exists)
{
recyclarrYaml.MoveTo(NewPath.File(file).FullName);
}
}
}

@ -1,46 +0,0 @@
using System.IO.Abstractions;
using JetBrains.Annotations;
using Spectre.Console;
namespace Recyclarr.Cli.Migration.Steps;
/// <remarks>
/// Implemented on 4/30/2022.
/// </remarks>
[UsedImplicitly]
public class MigrateTrashYml : IMigrationStep
{
private readonly IFileSystem _fileSystem;
private readonly string _oldConfigPath = Path.Combine(AppContext.BaseDirectory, "trash.yml");
// Do not use AppPaths class here since that may change yet again in the future and break this migration step.
private readonly string _newConfigPath = Path.Combine(AppContext.BaseDirectory, "recyclarr.yml");
public int Order => 10;
public string Description { get; }
public IReadOnlyCollection<string> Remediation { get; }
public bool Required => true;
public MigrateTrashYml(IFileSystem fileSystem)
{
_fileSystem = fileSystem;
Remediation = new[]
{
$"Check if `{_newConfigPath}` already exists. If so, manually copy the data you want and then delete `{_oldConfigPath}` to fix the error.",
$"Ensure Recyclarr has permission to delete {_oldConfigPath}",
$"Ensure Recyclarr has permission to create {_newConfigPath}"
};
Description = $"Rename default YAML config from `{_oldConfigPath}` to `{_newConfigPath}`";
}
public bool CheckIfNeeded()
{
return _fileSystem.File.Exists(_oldConfigPath);
}
public void Execute(IAnsiConsole? console)
{
_fileSystem.File.Move(_oldConfigPath, _newConfigPath);
}
}

@ -37,4 +37,8 @@
<ItemGroup>
<EmbeddedResource Include="config-template.yml" />
</ItemGroup>
<ItemGroup>
<Folder Include="Migration\Steps\" />
</ItemGroup>
</Project>

Loading…
Cancel
Save