parent
3a580eaf5b
commit
35248c277d
@ -0,0 +1,107 @@
|
||||
using System.Linq;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common.Serializer;
|
||||
using NzbDrone.Core.Datastore.Migration;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using RestSharp;
|
||||
|
||||
namespace NzbDrone.Core.Test.Datastore.Migration
|
||||
{
|
||||
[TestFixture]
|
||||
public class download_clients_rename_tv_to_musicFixture : MigrationTest<download_clients_rename_tv_to_music>
|
||||
{
|
||||
[Test]
|
||||
public void should_rename_settings_for_deluge()
|
||||
{
|
||||
var db = WithMigrationTestDb(c =>
|
||||
{
|
||||
c.Insert.IntoTable("DownloadClients").Row(new
|
||||
{
|
||||
Enable = true,
|
||||
Name = "Deluge",
|
||||
Implementation = "Deluge",
|
||||
Priority = 1,
|
||||
Settings = new
|
||||
{
|
||||
Host = "127.0.0.1",
|
||||
UrlBase = "/my/",
|
||||
TvDirectory = "abc",
|
||||
RecentTvPriority = 1,
|
||||
OlderTvPriority = 1
|
||||
}.ToJson(),
|
||||
ConfigContract = "DelugeSettings"
|
||||
});
|
||||
});
|
||||
|
||||
var items = db.Query<DownloadClientDefinition67>("SELECT * FROM \"DownloadClients\"");
|
||||
|
||||
items.Should().HaveCount(1);
|
||||
|
||||
items.First().Settings.Should().NotContainKey("tvDirectory");
|
||||
items.First().Settings.Should().ContainKey("musicDirectory");
|
||||
items.First().Settings["musicDirectory"].Should().Be("abc");
|
||||
|
||||
items.First().Settings.Should().NotContainKey("recentTvPriority");
|
||||
items.First().Settings.Should().ContainKey("recentMusicPriority");
|
||||
items.First().Settings["recentMusicPriority"].Should().Be(1);
|
||||
|
||||
items.First().Settings.Should().NotContainKey("olderTvPriority");
|
||||
items.First().Settings.Should().ContainKey("olderMusicPriority");
|
||||
items.First().Settings["olderMusicPriority"].Should().Be(1);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_rename_settings_for_qbittorrent()
|
||||
{
|
||||
var db = WithMigrationTestDb(c =>
|
||||
{
|
||||
c.Insert.IntoTable("DownloadClients").Row(new
|
||||
{
|
||||
Enable = true,
|
||||
Name = "QBittorrent",
|
||||
Implementation = "QBittorrent",
|
||||
Priority = 1,
|
||||
Settings = new
|
||||
{
|
||||
Host = "127.0.0.1",
|
||||
UrlBase = "/my/",
|
||||
TvDirectory = "abc",
|
||||
RecentTvPriority = 1,
|
||||
OlderTvPriority = 1
|
||||
}.ToJson(),
|
||||
ConfigContract = "QBittorrentSettings"
|
||||
});
|
||||
});
|
||||
|
||||
var items = db.Query<DownloadClientDefinition67>("SELECT * FROM \"DownloadClients\"");
|
||||
|
||||
items.Should().HaveCount(1);
|
||||
|
||||
items.First().Settings.Should().NotContainKey("tvDirectory");
|
||||
items.First().Settings.Should().ContainKey("musicDirectory");
|
||||
items.First().Settings["musicDirectory"].Should().Be("abc");
|
||||
|
||||
items.First().Settings.Should().NotContainKey("recentTvPriority");
|
||||
items.First().Settings.Should().ContainKey("recentMusicPriority");
|
||||
items.First().Settings["recentMusicPriority"].Should().Be(1);
|
||||
|
||||
items.First().Settings.Should().NotContainKey("olderTvPriority");
|
||||
items.First().Settings.Should().ContainKey("olderMusicPriority");
|
||||
items.First().Settings["olderMusicPriority"].Should().Be(1);
|
||||
}
|
||||
}
|
||||
|
||||
public class DownloadClientDefinition67
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public bool Enable { get; set; }
|
||||
public int Priority { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Implementation { get; set; }
|
||||
public JsonObject Settings { get; set; }
|
||||
public string ConfigContract { get; set; }
|
||||
public bool RemoveCompletedDownloads { get; set; }
|
||||
public bool RemoveFailedDownloads { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using Dapper;
|
||||
using FluentMigrator;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using NzbDrone.Common.Serializer;
|
||||
using NzbDrone.Core.Datastore.Migration.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Datastore.Migration
|
||||
{
|
||||
[Migration(067)]
|
||||
public class download_clients_rename_tv_to_music : NzbDroneMigrationBase
|
||||
{
|
||||
protected override void MainDbUpgrade()
|
||||
{
|
||||
Execute.WithConnection(MigrateSettingsTvToMusic);
|
||||
}
|
||||
|
||||
private void MigrateSettingsTvToMusic(IDbConnection conn, IDbTransaction tran)
|
||||
{
|
||||
var updatedClients = new List<object>();
|
||||
|
||||
using (var selectCommand = conn.CreateCommand())
|
||||
{
|
||||
selectCommand.Transaction = tran;
|
||||
selectCommand.CommandText = "SELECT \"Id\", \"Settings\" FROM \"DownloadClients\"";
|
||||
|
||||
using var reader = selectCommand.ExecuteReader();
|
||||
|
||||
while (reader.Read())
|
||||
{
|
||||
var id = reader.GetInt32(0);
|
||||
var settings = reader.GetString(1);
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(settings))
|
||||
{
|
||||
var jsonObject = Json.Deserialize<JObject>(settings);
|
||||
|
||||
if (jsonObject.ContainsKey("recentTvPriority"))
|
||||
{
|
||||
jsonObject.Add("recentMusicPriority", jsonObject.Value<int>("recentTvPriority"));
|
||||
jsonObject.Remove("recentTvPriority");
|
||||
}
|
||||
|
||||
if (jsonObject.ContainsKey("olderTvPriority"))
|
||||
{
|
||||
jsonObject.Add("olderMusicPriority", jsonObject.Value<int>("olderTvPriority"));
|
||||
jsonObject.Remove("olderTvPriority");
|
||||
}
|
||||
|
||||
if (jsonObject.ContainsKey("tvDirectory"))
|
||||
{
|
||||
jsonObject.Add("musicDirectory", jsonObject.Value<string>("tvDirectory"));
|
||||
jsonObject.Remove("tvDirectory");
|
||||
}
|
||||
|
||||
settings = jsonObject.ToJson();
|
||||
}
|
||||
|
||||
updatedClients.Add(new
|
||||
{
|
||||
Id = id,
|
||||
Settings = settings
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
var updateClientsSql = "UPDATE \"DownloadClients\" SET \"Settings\" = @Settings WHERE \"Id\" = @Id";
|
||||
conn.Execute(updateClientsSql, updatedClients, transaction: tran);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in new issue