You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.7 KiB
47 lines
1.7 KiB
using System.Data;
|
|
using FluentMigrator;
|
|
using NzbDrone.Core.Datastore.Migration.Framework;
|
|
|
|
namespace NzbDrone.Core.Datastore.Migration
|
|
{
|
|
[Migration(118)]
|
|
public class update_movie_slug : NzbDroneMigrationBase
|
|
{
|
|
protected override void MainDbUpgrade()
|
|
{
|
|
Execute.WithConnection(SetTitleSlug);
|
|
}
|
|
|
|
private void SetTitleSlug(IDbConnection conn, IDbTransaction tran)
|
|
{
|
|
using (var getSeriesCmd = conn.CreateCommand())
|
|
{
|
|
getSeriesCmd.Transaction = tran;
|
|
getSeriesCmd.CommandText = @"SELECT ""Id"", ""Title"", ""Year"", ""TmdbId"" FROM ""Movies""";
|
|
using (var seriesReader = getSeriesCmd.ExecuteReader())
|
|
{
|
|
while (seriesReader.Read())
|
|
{
|
|
var id = seriesReader.GetInt32(0);
|
|
var title = seriesReader.GetString(1);
|
|
var year = seriesReader.GetInt32(2);
|
|
var tmdbId = seriesReader.GetInt32(3);
|
|
|
|
var titleSlug = Parser.Parser.ToUrlSlug(title + "-" + tmdbId);
|
|
|
|
using (var updateCmd = conn.CreateCommand())
|
|
{
|
|
updateCmd.Transaction = tran;
|
|
updateCmd.CommandText = "UPDATE \"Movies\" SET \"TitleSlug\" = ? WHERE \"Id\" = ?";
|
|
updateCmd.AddParameter(titleSlug);
|
|
updateCmd.AddParameter(id);
|
|
|
|
updateCmd.ExecuteNonQuery();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|