parent
0de302ad48
commit
b2b877a8c3
@ -0,0 +1,17 @@
|
|||||||
|
export const IMDB_ID = 'imdbId';
|
||||||
|
export const TMDB_ID = 'tmdbId';
|
||||||
|
export const TVDB_ID = 'tvdbId';
|
||||||
|
export const TRAKT_ID = 'traktId';
|
||||||
|
export const R_ID = 'rId';
|
||||||
|
export const TVMAZE_ID = 'tvMazeId';
|
||||||
|
export const SEASON = 'season';
|
||||||
|
export const EPISODE = 'episode';
|
||||||
|
export const ARTIST = 'artist';
|
||||||
|
export const ALBUM = 'album';
|
||||||
|
export const LABEL = 'label';
|
||||||
|
export const TRACK = 'track';
|
||||||
|
export const YEAR = 'year';
|
||||||
|
export const GENRE = 'genre';
|
||||||
|
export const AUTHOR = 'author';
|
||||||
|
export const TITLE = 'title';
|
||||||
|
export const PUBLISHER = 'publisher';
|
@ -0,0 +1,91 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using FluentAssertions;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using NzbDrone.Common.Serializer;
|
||||||
|
using NzbDrone.Core.Datastore.Migration;
|
||||||
|
using NzbDrone.Core.Test.Framework;
|
||||||
|
|
||||||
|
namespace NzbDrone.Core.Test.Datastore.Migration
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
public class history_fix_data_titlesFixture : MigrationTest<history_fix_data_titles>
|
||||||
|
{
|
||||||
|
[Test]
|
||||||
|
public void should_update_data_for_book_search()
|
||||||
|
{
|
||||||
|
var db = WithMigrationTestDb(c =>
|
||||||
|
{
|
||||||
|
c.Insert.IntoTable("History").Row(new
|
||||||
|
{
|
||||||
|
IndexerId = 1,
|
||||||
|
Date = DateTime.UtcNow,
|
||||||
|
Data = new
|
||||||
|
{
|
||||||
|
Author = "Fake Author",
|
||||||
|
BookTitle = "Fake Book Title",
|
||||||
|
Publisher = "",
|
||||||
|
Year = "",
|
||||||
|
Genre = "",
|
||||||
|
Query = "",
|
||||||
|
QueryType = "book",
|
||||||
|
Source = "Prowlarr",
|
||||||
|
Host = "localhost"
|
||||||
|
}.ToJson(),
|
||||||
|
EventType = 2,
|
||||||
|
Successful = true
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
var items = db.Query<HistoryDefinition34>("SELECT * FROM \"History\"");
|
||||||
|
|
||||||
|
items.Should().HaveCount(1);
|
||||||
|
|
||||||
|
items.First().Data.Should().NotContainKey("bookTitle");
|
||||||
|
items.First().Data.Should().ContainKey("title");
|
||||||
|
items.First().Data.GetValueOrDefault("title").Should().Be("Fake Book Title");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_update_data_for_release_grabbed()
|
||||||
|
{
|
||||||
|
var db = WithMigrationTestDb(c =>
|
||||||
|
{
|
||||||
|
c.Insert.IntoTable("History").Row(new
|
||||||
|
{
|
||||||
|
IndexerId = 1,
|
||||||
|
Date = DateTime.UtcNow,
|
||||||
|
Data = new
|
||||||
|
{
|
||||||
|
GrabMethod = "Proxy",
|
||||||
|
Title = "Fake Release Title",
|
||||||
|
Source = "Prowlarr",
|
||||||
|
Host = "localhost"
|
||||||
|
}.ToJson(),
|
||||||
|
EventType = 1,
|
||||||
|
Successful = true
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
var items = db.Query<HistoryDefinition34>("SELECT * FROM \"History\"");
|
||||||
|
|
||||||
|
items.Should().HaveCount(1);
|
||||||
|
|
||||||
|
items.First().Data.Should().NotContainKey("title");
|
||||||
|
items.First().Data.Should().ContainKey("grabTitle");
|
||||||
|
items.First().Data.GetValueOrDefault("grabTitle").Should().Be("Fake Release Title");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class HistoryDefinition34
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
public int IndexerId { get; set; }
|
||||||
|
public DateTime Date { get; set; }
|
||||||
|
public Dictionary<string, string> Data { get; set; }
|
||||||
|
public int EventType { get; set; }
|
||||||
|
public string DownloadId { get; set; }
|
||||||
|
public bool Successful { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,66 @@
|
|||||||
|
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(034)]
|
||||||
|
public class history_fix_data_titles : NzbDroneMigrationBase
|
||||||
|
{
|
||||||
|
protected override void MainDbUpgrade()
|
||||||
|
{
|
||||||
|
Execute.WithConnection(MigrateHistoryDataTitle);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void MigrateHistoryDataTitle(IDbConnection conn, IDbTransaction tran)
|
||||||
|
{
|
||||||
|
var updatedHistory = new List<object>();
|
||||||
|
|
||||||
|
using (var selectCommand = conn.CreateCommand())
|
||||||
|
{
|
||||||
|
selectCommand.Transaction = tran;
|
||||||
|
selectCommand.CommandText = "SELECT \"Id\", \"Data\" FROM \"History\"";
|
||||||
|
|
||||||
|
using var reader = selectCommand.ExecuteReader();
|
||||||
|
|
||||||
|
while (reader.Read())
|
||||||
|
{
|
||||||
|
var id = reader.GetInt32(0);
|
||||||
|
var data = reader.GetString(1);
|
||||||
|
|
||||||
|
if (!string.IsNullOrWhiteSpace(data))
|
||||||
|
{
|
||||||
|
var jsonObject = Json.Deserialize<JObject>(data);
|
||||||
|
|
||||||
|
if (jsonObject.ContainsKey("title"))
|
||||||
|
{
|
||||||
|
jsonObject.Add("grabTitle", jsonObject.Value<string>("title"));
|
||||||
|
jsonObject.Remove("title");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (jsonObject.ContainsKey("bookTitle"))
|
||||||
|
{
|
||||||
|
jsonObject.Add("title", jsonObject.Value<string>("bookTitle"));
|
||||||
|
jsonObject.Remove("bookTitle");
|
||||||
|
}
|
||||||
|
|
||||||
|
data = jsonObject.ToJson();
|
||||||
|
|
||||||
|
updatedHistory.Add(new
|
||||||
|
{
|
||||||
|
Id = id,
|
||||||
|
Data = data
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var updateHistorySql = "UPDATE \"History\" SET \"Data\" = @Data WHERE \"Id\" = @Id";
|
||||||
|
conn.Execute(updateHistorySql, updatedHistory, transaction: tran);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue