New: Migrated StevenLu URL to new URL

This commit is contained in:
Robin Dadswell 2025-02-05 15:03:32 +00:00 committed by Bogdan
parent dd900eb739
commit b3dd571a92
2 changed files with 110 additions and 0 deletions

View file

@ -0,0 +1,55 @@
using System.Linq;
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Common.Serializer;
using NzbDrone.Core.Datastore;
using NzbDrone.Core.Datastore.Migration;
using NzbDrone.Core.Test.Framework;
namespace NzbDrone.Core.Test.Datastore.Migration
{
[TestFixture]
public class stevenlu_update_urlFixture : MigrationTest<stevenlu_update_url>
{
[Test]
public void should_update_stevenlu_url()
{
var db = WithMigrationTestDb(c =>
{
c.Insert.IntoTable("ImportLists").Row(new
{
Enabled = true,
EnableAuto = true,
Name = "StevenLu List",
QualityProfileId = 1,
MinimumAvailability = 1,
RootFolderPath = "/movies",
Monitor = 0,
SearchOnAdd = true,
Tags = "[]",
Implementation = "StevenLuImport",
ConfigContract = "StevenLuSettings",
Settings = new StevenLuSettings241
{
Link = "https://s3.amazonaws.com/popular-movies/movies.json"
}.ToJson()
});
});
var items = db.Query<ImportListDefinition241>("SELECT \"Id\", \"Settings\" FROM \"ImportLists\"");
items.Should().HaveCount(1);
items.First().Settings.Link.Should().Be("https://popular-movies-data.stevenlu.com/movies.json");
}
}
public class ImportListDefinition241 : ModelBase
{
public StevenLuSettings241 Settings { get; set; }
}
public class StevenLuSettings241
{
public string Link { get; set; }
}
}

View file

@ -0,0 +1,55 @@
using System.Collections.Generic;
using System.Data;
using Dapper;
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(241)]
public class stevenlu_update_url : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Execute.WithConnection(FixStevenLuListsLink);
}
private void FixStevenLuListsLink(IDbConnection conn, IDbTransaction tran)
{
var updated = new List<object>();
using (var getStevenLuListCmd = conn.CreateCommand())
{
getStevenLuListCmd.Transaction = tran;
getStevenLuListCmd.CommandText = "SELECT \"Id\", \"Settings\" FROM \"ImportLists\" WHERE \"ConfigContract\" = 'StevenLuSettings'";
using var reader = getStevenLuListCmd.ExecuteReader();
while (reader.Read())
{
var id = reader.GetInt32(0);
var settings = Json.Deserialize<JObject>(reader.GetString(1));
var link = settings.Value<string>("link");
if (link.IsNotNullOrWhiteSpace() && link.StartsWith("https://s3.amazonaws.com/popular-movies"))
{
settings["link"] = "https://popular-movies-data.stevenlu.com/movies.json";
}
updated.Add(new
{
Id = id,
Settings = settings.ToJson()
});
}
}
var updateSql = "UPDATE \"ImportLists\" SET \"Settings\" = @Settings WHERE \"Id\" = @Id";
conn.Execute(updateSql, updated, transaction: tran);
}
}
}