Squash Pre-Fork Sonarr Migrations (#4029)

pull/4054/head
Qstick 5 years ago committed by GitHub
parent b3553e93ab
commit 06b56db67c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,102 +0,0 @@
using System.Linq;
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Core.Datastore.Migration;
using NzbDrone.Core.Test.Framework;
namespace NzbDrone.Core.Test.Datastore.Migration
{
[TestFixture]
public class delay_profileFixture : MigrationTest<delay_profile>
{
[Test]
public void should_migrate_old_delays()
{
var db = WithMigrationTestDb(c =>
{
c.Insert.IntoTable("Profiles").Row(new
{
GrabDelay = 1,
Name = "OneHour",
Cutoff = 0,
Items = "[]"
});
c.Insert.IntoTable("Profiles").Row(new
{
GrabDelay = 2,
Name = "TwoHours",
Cutoff = "{}",
Items = "[]"
});
});
var allProfiles = db.Query<DelayProfile70>("SELECT * FROM DelayProfiles");
allProfiles.Should().HaveCount(3);
allProfiles.Should().OnlyContain(c => c.PreferredProtocol == 1);
allProfiles.Should().OnlyContain(c => c.TorrentDelay == 0);
allProfiles.Should().Contain(c => c.UsenetDelay == 60);
allProfiles.Should().Contain(c => c.UsenetDelay == 120);
}
[Test]
public void should_create_tag_for_delay_profile()
{
var db = WithMigrationTestDb(c =>
{
c.Insert.IntoTable("Profiles").Row(new
{
GrabDelay = 1,
Name = "OneHour",
Cutoff = 0,
Items = "[]"
});
});
var tags = db.Query<Tag69>("SELECT * FROM Tags");
tags.Should().HaveCount(1);
tags.First().Label.Should().Be("delay-60");
}
[Test]
public void should_add_tag_to_series_that_had_a_profile_with_delay_attached()
{
var db = WithMigrationTestDb(c =>
{
c.Insert.IntoTable("Profiles").Row(new
{
GrabDelay = 1,
Name = "OneHour",
Cutoff = 0,
Items = "[]"
});
c.Insert.IntoTable("Series").Row(new
{
TvdbId = 0,
TvRageId = 0,
Title = "Series",
TitleSlug = "series",
CleanTitle = "series",
Status = 0,
Images = "[]",
Path = @"C:\Test\Series",
Monitored = 1,
SeasonFolder = 1,
RunTime = 0,
SeriesType = 0,
UseSceneNumbering = 0,
Tags = "[1]"
});
});
var tag = db.Query<Tag69>("SELECT Id, Label FROM Tags").Single();
var series = db.Query<Series69>("SELECT Tags FROM Series");
series.Should().HaveCount(1);
series.First().Tags.Should().BeEquivalentTo(tag.Id);
}
}
}

@ -1,35 +0,0 @@
using System.Linq;
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Core.Datastore.Migration;
using NzbDrone.Core.Test.Framework;
namespace NzbDrone.Core.Test.Datastore.Migration
{
[TestFixture]
public class unknown_quality_in_profileFixture : MigrationTest<unknown_quality_in_profile>
{
[Test]
public void should_add_unknown_to_old_profile()
{
var db = WithMigrationTestDb(c =>
{
c.Insert.IntoTable("Profiles").Row(new
{
Id = 0,
Name = "SDTV",
Cutoff = 1,
Items = "[ { \"quality\": 1, \"allowed\": true } ]",
Language = 1
});
});
var profiles = db.Query<Profile70>("SELECT Items FROM Profiles LIMIT 1");
var items = profiles.First().Items;
items.Should().HaveCount(2);
items.First().Quality.Should().Be(0);
items.First().Allowed.Should().Be(false);
}
}
}

@ -1,103 +0,0 @@
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.Datastore.Migration.Framework;
using NzbDrone.Core.Test.Framework;
namespace NzbDrone.Core.Test.Datastore.Migration
{
[TestFixture]
public class history_downloadIdFixture : MigrationTest<history_downloadId>
{
[Test]
public void should_move_grab_id_from_date_to_columns()
{
var db = WithMigrationTestDb(c =>
{
InsertHistory(c, new Dictionary<string, string>
{
{ "indexer", "test" },
{ "downloadClientId", "123" }
});
InsertHistory(c, new Dictionary<string, string>
{
{ "indexer", "test" },
{ "downloadClientId", "abc" }
});
});
var history = db.Query<History72>("SELECT DownloadId, Data FROM History");
history.Should().HaveCount(2);
history.Should().NotContain(c => c.Data.ContainsKey("downloadClientId"));
history.Should().Contain(c => c.DownloadId == "123");
history.Should().Contain(c => c.DownloadId == "abc");
}
[Test]
public void should_leave_items_with_no_grabid()
{
var db = WithMigrationTestDb(c =>
{
InsertHistory(c, new Dictionary<string, string>
{
{ "indexer", "test" },
{ "downloadClientId", "123" }
});
InsertHistory(c, new Dictionary<string, string>
{
{ "indexer", "test" }
});
});
var history = db.Query<History72>("SELECT DownloadId, Data FROM History");
history.Should().HaveCount(2);
history.Should().NotContain(c => c.Data.ContainsKey("downloadClientId"));
history.Should().Contain(c => c.DownloadId == "123");
history.Should().Contain(c => c.DownloadId == null);
}
[Test]
public void should_leave_other_data()
{
var db = WithMigrationTestDb(c =>
{
InsertHistory(c, new Dictionary<string, string>
{
{ "indexer", "test" },
{ "group", "test2" },
{ "downloadClientId", "123" }
});
});
var history = db.Query<History72>("SELECT DownloadId, Data FROM History").Single();
history.Data.Should().NotContainKey("downloadClientId");
history.Data.Should().Contain(new KeyValuePair<string, string>("indexer", "test"));
history.Data.Should().Contain(new KeyValuePair<string, string>("group", "test2"));
history.DownloadId.Should().Be("123");
}
private void InsertHistory(NzbDroneMigrationBase migrationBase, Dictionary<string, string> data)
{
migrationBase.Insert.IntoTable("History").Row(new
{
EpisodeId = 1,
SeriesId = 1,
SourceTitle = "Test",
Date = DateTime.Now,
Quality = "{}",
Data = data.ToJson(),
EventType = 1
});
}
}
}

@ -1,97 +0,0 @@
using System.Linq;
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Core.Datastore.Migration;
using NzbDrone.Core.Test.Framework;
namespace NzbDrone.Core.Test.Datastore.Migration
{
[TestFixture]
public class force_lib_updateFixture : MigrationTest<force_lib_update>
{
[Test]
public void should_not_fail_on_empty_db()
{
var db = WithMigrationTestDb();
db.Query("SELECT * FROM ScheduledTasks").Should().BeEmpty();
db.Query("SELECT * FROM Series").Should().BeEmpty();
}
[Test]
public void should_reset_job_last_execution_time()
{
var db = WithMigrationTestDb(c =>
{
c.Insert.IntoTable("ScheduledTasks").Row(new
{
TypeName = "NzbDrone.Core.Tv.Commands.RefreshSeriesCommand",
Interval = 10,
LastExecution = "2000-01-01 00:00:00"
});
c.Insert.IntoTable("ScheduledTasks").Row(new
{
TypeName = "NzbDrone.Core.Backup.BackupCommand",
Interval = 10,
LastExecution = "2000-01-01 00:00:00"
});
});
var jobs = db.Query<ScheduledTasks75>("SELECT TypeName, LastExecution FROM ScheduledTasks");
jobs.Single(c => c.TypeName == "NzbDrone.Core.Tv.Commands.RefreshSeriesCommand")
.LastExecution.Year.Should()
.Be(2014);
jobs.Single(c => c.TypeName == "NzbDrone.Core.Backup.BackupCommand")
.LastExecution.Year.Should()
.Be(2000);
}
[Test]
public void should_reset_series_last_sync_time()
{
var db = WithMigrationTestDb(c =>
{
c.Insert.IntoTable("Series").Row(new
{
Tvdbid = 1,
TvRageId = 1,
Title = "Title1",
CleanTitle = "CleanTitle1",
Status = 1,
Images = "",
Path = "c:\\test",
Monitored = 1,
SeasonFolder = 1,
Runtime = 0,
SeriesType = 0,
UseSceneNumbering = 0,
LastInfoSync = "2000-01-01 00:00:00"
});
c.Insert.IntoTable("Series").Row(new
{
Tvdbid = 2,
TvRageId = 2,
Title = "Title2",
CleanTitle = "CleanTitle2",
Status = 1,
Images = "",
Path = "c:\\test2",
Monitored = 1,
SeasonFolder = 1,
Runtime = 0,
SeriesType = 0,
UseSceneNumbering = 0,
LastInfoSync = "2000-01-01 00:00:00"
});
});
var series = db.Query<Series69>("SELECT LastInfoSync FROM Series");
series.Should().OnlyContain(c => c.LastInfoSync.Value.Year == 2014);
}
}
}

@ -1,205 +0,0 @@
using System.Linq;
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Core.Datastore.Migration;
using NzbDrone.Core.Test.Framework;
namespace NzbDrone.Core.Test.Datastore.Migration
{
[TestFixture]
public class dedupe_tagsFixture : MigrationTest<dedupe_tags>
{
[Test]
public void should_not_fail_if_series_tags_are_null()
{
var db = WithMigrationTestDb(c =>
{
c.Insert.IntoTable("Series").Row(new
{
Tvdbid = 1,
TvRageId = 1,
Title = "Title1",
CleanTitle = "CleanTitle1",
Status = 1,
Images = "",
Path = "c:\\test",
Monitored = 1,
SeasonFolder = 1,
Runtime = 0,
SeriesType = 0,
UseSceneNumbering = 0,
LastInfoSync = "2000-01-01 00:00:00"
});
c.Insert.IntoTable("Tags").Row(new
{
Label = "test"
});
});
var tags = db.Query<Tag69>("SELECT * FROM Tags");
tags.Should().HaveCount(1);
}
[Test]
public void should_not_fail_if_series_tags_are_empty()
{
var db = WithMigrationTestDb(c =>
{
c.Insert.IntoTable("Series").Row(new
{
Tvdbid = 1,
TvRageId = 1,
Title = "Title1",
CleanTitle = "CleanTitle1",
Status = 1,
Images = "",
Path = "c:\\test",
Monitored = 1,
SeasonFolder = 1,
Runtime = 0,
SeriesType = 0,
UseSceneNumbering = 0,
LastInfoSync = "2000-01-01 00:00:00",
Tags = "[]"
});
c.Insert.IntoTable("Tags").Row(new
{
Label = "test"
});
});
var tags = db.Query<Tag69>("SELECT * FROM Tags");
tags.Should().HaveCount(1);
}
[Test]
public void should_remove_duplicate_labels_from_tags()
{
var db = WithMigrationTestDb(c =>
{
c.Insert.IntoTable("Tags").Row(new
{
Label = "test"
});
c.Insert.IntoTable("Tags").Row(new
{
Label = "test"
});
});
var tags = db.Query<Tag69>("SELECT * FROM Tags");
tags.Should().HaveCount(1);
}
[Test]
public void should_not_allow_duplicate_tag_to_be_inserted()
{
var db = WithMigrationTestDb(c =>
{
c.Insert.IntoTable("Tags").Row(new
{
Label = "test"
});
});
Assert.That(() => db.Query("INSERT INTO Tags (Label) VALUES ('test')"), Throws.Exception);
}
[Test]
public void should_replace_duplicated_tag_with_proper_tag()
{
var db = WithMigrationTestDb(c =>
{
c.Insert.IntoTable("Series").Row(new
{
Tvdbid = 1,
TvRageId = 1,
Title = "Title1",
CleanTitle = "CleanTitle1",
Status = 1,
Images = "",
Path = "c:\\test",
Monitored = 1,
SeasonFolder = 1,
Runtime = 0,
SeriesType = 0,
UseSceneNumbering = 0,
LastInfoSync = "2000-01-01 00:00:00",
Tags = "[2]"
});
c.Insert.IntoTable("Tags").Row(new
{
Label = "test"
});
c.Insert.IntoTable("Tags").Row(new
{
Label = "test"
});
});
var series = db.Query<Series69>("SELECT Tags FROM Series WHERE Id = 1").Single();
series.Tags.First().Should().Be(1);
}
[Test]
public void should_only_update_affected_series()
{
var db = WithMigrationTestDb(c =>
{
c.Insert.IntoTable("Series").Row(new
{
Tvdbid = 1,
TvRageId = 1,
Title = "Title1",
CleanTitle = "CleanTitle1",
Status = 1,
Images = "",
Path = "c:\\test",
Monitored = 1,
SeasonFolder = 1,
Runtime = 0,
SeriesType = 0,
UseSceneNumbering = 0,
LastInfoSync = "2000-01-01 00:00:00",
Tags = "[2]"
});
c.Insert.IntoTable("Series").Row(new
{
Tvdbid = 2,
TvRageId = 2,
Title = "Title2",
CleanTitle = "CleanTitle2",
Status = 1,
Images = "",
Path = "c:\\test",
Monitored = 1,
SeasonFolder = 1,
Runtime = 0,
SeriesType = 0,
UseSceneNumbering = 0,
LastInfoSync = "2000-01-01 00:00:00",
Tags = "[]"
});
c.Insert.IntoTable("Tags").Row(new
{
Label = "test"
});
c.Insert.IntoTable("Tags").Row(new
{
Label = "test"
});
});
var series = db.Query<Series69>("SELECT Tags FROM Series WHERE Id = 2").Single();
series.Tags.Should().BeEmpty();
}
}
}

@ -1,88 +0,0 @@
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 move_dot_prefix_to_transmission_categoryFixture : MigrationTest<move_dot_prefix_to_transmission_category>
{
[Test]
public void should_not_fail_if_no_transmission()
{
var db = WithMigrationTestDb(c =>
{
c.Insert.IntoTable("DownloadClients").Row(new
{
Enable = 1,
Name = "Sab",
Implementation = "Sabnzbd",
Settings = new
{
Host = "127.0.0.1",
TvCategory = "abc"
}.ToJson(),
ConfigContract = "SabnzbdSettings"
});
});
var downloadClients = db.Query<DownloadClientDefinition81>("SELECT Settings FROM DownloadClients");
downloadClients.Should().HaveCount(1);
downloadClients.First().Settings.ToObject<SabnzbdSettings81>().TvCategory.Should().Be("abc");
}
[Test]
public void should_be_updated_for_transmission()
{
var db = WithMigrationTestDb(c =>
{
c.Insert.IntoTable("DownloadClients").Row(new
{
Enable = 1,
Name = "Trans",
Implementation = "Transmission",
Settings = new
{
Host = "127.0.0.1",
TvCategory = "abc"
}.ToJson(),
ConfigContract = "TransmissionSettings"
});
});
var downloadClients = db.Query<DownloadClientDefinition81>("SELECT Settings FROM DownloadClients");
downloadClients.Should().HaveCount(1);
downloadClients.First().Settings.ToObject<TransmissionSettings81>().TvCategory.Should().Be(".abc");
}
[Test]
public void should_leave_empty_category_untouched()
{
var db = WithMigrationTestDb(c =>
{
c.Insert.IntoTable("DownloadClients").Row(new
{
Enable = 1,
Name = "Trans",
Implementation = "Transmission",
Settings = new
{
Host = "127.0.0.1",
TvCategory = ""
}.ToJson(),
ConfigContract = "TransmissionSettings"
});
});
var downloadClients = db.Query<DownloadClientDefinition81>("SELECT Settings FROM DownloadClients");
downloadClients.Should().HaveCount(1);
downloadClients.First().Settings.ToObject<TransmissionSettings81>().TvCategory.Should().Be("");
}
}
}

@ -1,96 +0,0 @@
using System.Linq;
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Core.Datastore.Migration;
using NzbDrone.Core.Test.Framework;
namespace NzbDrone.Core.Test.Datastore.Migration
{
[TestFixture]
public class update_quality_minmax_sizeFixture : MigrationTest<update_quality_minmax_size>
{
[Test]
public void should_not_fail_if_empty()
{
var db = WithMigrationTestDb();
var qualityDefinitions = db.Query<QualityDefinition84>("SELECT * FROM QualityDefinitions");
qualityDefinitions.Should().BeEmpty();
}
[Test]
public void should_set_rawhd_to_null()
{
var db = WithMigrationTestDb(c =>
{
c.Insert.IntoTable("QualityDefinitions").Row(new
{
Quality = 1,
Title = "SDTV",
MinSize = 0,
MaxSize = 100
})
.Row(new
{
Quality = 10,
Title = "RawHD",
MinSize = 0,
MaxSize = 100
});
});
var qualityDefinitions = db.Query<QualityDefinition84>("SELECT * FROM QualityDefinitions");
qualityDefinitions.Should().HaveCount(2);
qualityDefinitions.First(v => v.Quality == 10).MaxSize.Should().NotHaveValue();
}
[Test]
public void should_set_zero_maxsize_to_null()
{
var db = WithMigrationTestDb(c =>
{
c.Insert.IntoTable("QualityDefinitions").Row(new
{
Quality = 1,
Title = "SDTV",
MinSize = 0,
MaxSize = 0
});
});
var qualityDefinitions = db.Query<QualityDefinition84>("SELECT * FROM QualityDefinitions");
qualityDefinitions.Should().HaveCount(1);
qualityDefinitions.First(v => v.Quality == 1).MaxSize.Should().NotHaveValue();
}
[Test]
public void should_preserve_values()
{
var db = WithMigrationTestDb(c =>
{
c.Insert.IntoTable("QualityDefinitions").Row(new
{
Quality = 1,
Title = "SDTV",
MinSize = 0,
MaxSize = 100
})
.Row(new
{
Quality = 10,
Title = "RawHD",
MinSize = 0,
MaxSize = 100
});
});
var qualityDefinitions = db.Query<QualityDefinition84>("SELECT * FROM QualityDefinitions");
qualityDefinitions.Should().HaveCount(2);
qualityDefinitions.First(v => v.Quality == 1).MaxSize.Should().Be(100);
}
}
}

@ -1,90 +0,0 @@
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 expand_transmission_urlbaseFixture : MigrationTest<expand_transmission_urlbase>
{
[Test]
public void should_not_fail_if_no_transmission()
{
var db = WithMigrationTestDb(c =>
{
c.Insert.IntoTable("DownloadClients").Row(new
{
Enable = 1,
Name = "Deluge",
Implementation = "Deluge",
Settings = new DelugeSettings85
{
Host = "127.0.0.1",
TvCategory = "abc",
UrlBase = "/my/"
}.ToJson(),
ConfigContract = "DelugeSettings"
});
});
var items = db.Query<DownloadClientDefinition81>("SELECT * FROM DownloadClients");
items.Should().HaveCount(1);
items.First().Settings.ToObject<DelugeSettings85>().UrlBase.Should().Be("/my/");
}
[Test]
public void should_be_updated_for_transmission()
{
var db = WithMigrationTestDb(c =>
{
c.Insert.IntoTable("DownloadClients").Row(new
{
Enable = 1,
Name = "Trans",
Implementation = "Transmission",
Settings = new TransmissionSettings81
{
Host = "127.0.0.1",
TvCategory = "abc"
}.ToJson(),
ConfigContract = "TransmissionSettings"
});
});
var items = db.Query<DownloadClientDefinition81>("SELECT * FROM DownloadClients");
items.Should().HaveCount(1);
items.First().Settings.ToObject<TransmissionSettings81>().UrlBase.Should().Be("/transmission/");
}
[Test]
public void should_be_append_to_existing_urlbase()
{
var db = WithMigrationTestDb(c =>
{
c.Insert.IntoTable("DownloadClients").Row(new
{
Enable = 1,
Name = "Trans",
Implementation = "Transmission",
Settings = new TransmissionSettings81
{
Host = "127.0.0.1",
TvCategory = "abc",
UrlBase = "/my/url/"
}.ToJson(),
ConfigContract = "TransmissionSettings"
});
});
var items = db.Query<DownloadClientDefinition81>("SELECT * FROM DownloadClients");
items.Should().HaveCount(1);
items.First().Settings.ToObject<TransmissionSettings81>().UrlBase.Should().Be("/my/url/transmission/");
}
}
}

@ -1,89 +0,0 @@
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 pushbullet_device_idsFixture : MigrationTest<pushbullet_device_ids>
{
[Test]
public void should_not_fail_if_no_pushbullet()
{
var db = WithMigrationTestDb(c =>
{
c.Insert.IntoTable("Notifications").Row(new
{
OnGrab = false,
OnDownload = false,
OnUpgrade = false,
Name = "Pushover",
Implementation = "Pushover",
Settings = "{}",
ConfigContract = "PushoverSettings"
});
});
var items = db.Query<Notification86>("SELECT * FROM Notifications");
items.Should().HaveCount(1);
}
[Test]
public void should_not_fail_if_deviceId_is_not_set()
{
var db = WithMigrationTestDb(c =>
{
c.Insert.IntoTable("Notifications").Row(new
{
OnGrab = false,
OnDownload = false,
OnUpgrade = false,
Name = "PushBullet",
Implementation = "PushBullet",
Settings = new
{
ApiKey = "my_api_key"
}.ToJson(),
ConfigContract = "PushBulletSettings"
});
});
var items = db.Query<Notification86>("SELECT * FROM Notifications");
items.Should().HaveCount(1);
}
[Test]
public void should_add_deviceIds_setting_matching_deviceId()
{
var deviceId = "device_id";
var db = WithMigrationTestDb(c =>
{
c.Insert.IntoTable("Notifications").Row(new
{
OnGrab = false,
OnDownload = false,
OnUpgrade = false,
Name = "PushBullet",
Implementation = "PushBullet",
Settings = new
{
ApiKey = "my_api_key",
DeviceId = deviceId
}.ToJson(),
ConfigContract = "PushBulletSettings"
});
});
var items = db.Query<Notification86>("SELECT * FROM Notifications");
items.Should().HaveCount(1);
items.First().Settings.ToObject<PushBulletSettings86>().DeviceIds.First().Should().Be(deviceId);
}
}
}

@ -1,40 +0,0 @@
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 pushbullet_devices_channels_listFixture : MigrationTest<pushbullet_devices_channels_list>
{
[Test]
public void should_convert_comma_separted_string_to_list()
{
var db = WithMigrationTestDb(c =>
{
c.Insert.IntoTable("Notifications").Row(new
{
OnGrab = false,
OnDownload = false,
OnUpgrade = false,
Name = "PushBullet",
Implementation = "PushBullet",
Settings = new
{
ApiKey = "my_api_key",
ChannelTags = "channel1,channel2"
}.ToJson(),
ConfigContract = "PushBulletSettings"
});
});
var items = db.Query<Notification86>("SELECT * FROM Notifications");
items.Should().HaveCount(1);
items.First().Settings.ToObject<PushBulletSettings88>().ChannelTags.Should().HaveCount(2);
}
}
}

@ -1,65 +0,0 @@
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 update_kickass_url_migration_fixture : MigrationTest<update_kickass_url>
{
[TestCase("http://kickass.so")]
[TestCase("https://kickass.so")]
[TestCase("http://kickass.to")]
[TestCase("https://kickass.to")]
[TestCase("http://kat.cr")]
// [TestCase("HTTP://KICKASS.SO")] Not sure if there is an easy way to do this, not sure if worth it.
public void should_replace_old_url(string oldUrl)
{
var db = WithMigrationTestDb(c =>
{
c.Insert.IntoTable("Indexers").Row(new
{
Name = "Kickass_wrong_url",
Implementation = "KickassTorrents",
Settings = new KickassTorrentsSettings90
{
BaseUrl = oldUrl
}.ToJson(),
ConfigContract = "KickassTorrentsSettings"
});
});
var items = db.Query<IndexerDefinition90>("SELECT * FROM Indexers");
items.Should().HaveCount(1);
items.First().Settings.ToObject<KickassTorrentsSettings90>().BaseUrl.Should().Be("https://kat.cr");
}
[Test]
public void should_not_replace_other_indexers()
{
var db = WithMigrationTestDb(c =>
{
c.Insert.IntoTable("Indexers").Row(new
{
Name = "not_kickass",
Implementation = "NotKickassTorrents",
Settings = new KickassTorrentsSettings90
{
BaseUrl = "kickass.so",
}.ToJson(),
ConfigContract = "KickassTorrentsSettings"
});
});
var items = db.Query<IndexerDefinition90>("SELECT * FROM Indexers");
items.Should().HaveCount(1);
items.First().Settings.ToObject<KickassTorrentsSettings90>().BaseUrl.Should().Be("kickass.so");
}
}
}

@ -1,54 +0,0 @@
using System.Linq;
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Core.Datastore.Migration;
using NzbDrone.Core.Test.Framework;
namespace NzbDrone.Core.Test.Datastore.Migration
{
[TestFixture]
public class metadata_files_extensionFixture : MigrationTest<extra_and_subtitle_files>
{
[Test]
public void should_set_extension_using_relative_path()
{
var db = WithMigrationTestDb(c =>
{
c.Insert.IntoTable("MetadataFiles").Row(new
{
SeriesId = 1,
RelativePath = "banner.jpg",
LastUpdated = "2016-05-30 20:23:02.3725923",
Type = 3,
Consumer = "XbmcMetadata"
});
c.Insert.IntoTable("MetadataFiles").Row(new
{
SeriesId = 1,
SeasonNumber = 1,
EpisodeFileId = 1,
RelativePath = "Series.Title.S01E01.jpg",
LastUpdated = "2016-05-30 20:23:02.3725923",
Type = 5,
Consumer = "XbmcMetadata"
});
c.Insert.IntoTable("MetadataFiles").Row(new
{
SeriesId = 1,
RelativePath = "Series Title",
LastUpdated = "2016-05-30 20:23:02.3725923",
Type = 3,
Consumer = "RoksboxMetadata"
});
});
var items = db.Query<MetadataFile99>("SELECT * FROM MetadataFiles");
items.Should().HaveCount(2);
items.First().Extension.Should().Be(".jpg");
items.Last().Extension.Should().Be(".jpg");
}
}
}

@ -1,35 +0,0 @@
using System.Linq;
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Core.Datastore.Migration;
using NzbDrone.Core.Test.Framework;
namespace NzbDrone.Core.Test.Datastore.Migration
{
[TestFixture]
public class add_ultrahd_quality_in_profilesFixture : MigrationTest<add_ultrahd_quality_in_profiles>
{
[Test]
public void should_add_ultrahd_to_old_profile()
{
var db = WithMigrationTestDb(c =>
{
c.Insert.IntoTable("Profiles").Row(new
{
Id = 0,
Name = "SDTV",
Cutoff = 1,
Items = "[ { \"quality\": 1, \"allowed\": true } ]",
Language = 1
});
});
var profiles = db.Query<Profile70>("SELECT Items FROM Profiles LIMIT 1");
var items = profiles.First().Items;
items.Should().HaveCount(4);
items.Select(v => v.Quality).Should().BeEquivalentTo(1, 16, 18, 19);
items.Select(v => v.Allowed).Should().BeEquivalentTo(true, false, false, false);
}
}
}

@ -1,36 +0,0 @@
using System.Linq;
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Core.Datastore.Migration;
using NzbDrone.Core.Test.Framework;
namespace NzbDrone.Core.Test.Datastore.Migration
{
[TestFixture]
public class fix_metadata_file_extensionsFixture : MigrationTest<fix_metadata_file_extensions>
{
[Test]
public void should_fix_extension_when_relative_path_contained_multiple_periods()
{
var db = WithMigrationTestDb(c =>
{
c.Insert.IntoTable("MetadataFiles").Row(new
{
SeriesId = 1,
SeasonNumber = 1,
EpisodeFileId = 1,
RelativePath = "Series.Title.S01E01.jpg",
LastUpdated = "2016-05-30 20:23:02.3725923",
Type = 5,
Consumer = "XbmcMetadata",
Extension = ".S01E01.jpg"
});
});
var items = db.Query<MetadataFile99>("SELECT * FROM MetadataFiles");
items.Should().HaveCount(1);
items.First().Extension.Should().Be(".jpg");
}
}
}

@ -21,7 +21,7 @@ namespace NzbDrone.Core.Test.Datastore.Migration
Enable = 1,
Name = "Deluge",
Implementation = "Deluge",
Settings = new DelugeSettings85
Settings = new DelugeSettings156
{
Host = "127.0.0.1",
TvCategory = "abc",
@ -47,7 +47,7 @@ namespace NzbDrone.Core.Test.Datastore.Migration
Enable = 1,
Name = "Deluge",
Implementation = "Deluge",
Settings = new DelugeSettings85
Settings = new DelugeSettings156
{
Host = "127.0.0.1",
TvCategory = "abc",
@ -59,7 +59,7 @@ namespace NzbDrone.Core.Test.Datastore.Migration
Enable = 1,
Name = "Deluge2",
Implementation = "Deluge",
Settings = new DelugeSettings85
Settings = new DelugeSettings156
{
Host = "127.0.0.1",
TvCategory = "abc",
@ -71,7 +71,7 @@ namespace NzbDrone.Core.Test.Datastore.Migration
Enable = 1,
Name = "sab",
Implementation = "Sabnzbd",
Settings = new SabnzbdSettings81
Settings = new SabnzbdSettings156
{
Host = "127.0.0.1",
TvCategory = "abc"
@ -98,7 +98,7 @@ namespace NzbDrone.Core.Test.Datastore.Migration
Enable = 0,
Name = "Deluge",
Implementation = "Deluge",
Settings = new DelugeSettings85
Settings = new DelugeSettings156
{
Host = "127.0.0.1",
TvCategory = "abc",
@ -110,7 +110,7 @@ namespace NzbDrone.Core.Test.Datastore.Migration
Enable = 0,
Name = "Deluge2",
Implementation = "Deluge",
Settings = new DelugeSettings85
Settings = new DelugeSettings156
{
Host = "127.0.0.1",
TvCategory = "abc",
@ -122,7 +122,7 @@ namespace NzbDrone.Core.Test.Datastore.Migration
Enable = 0,
Name = "sab",
Implementation = "Sabnzbd",
Settings = new SabnzbdSettings81
Settings = new SabnzbdSettings156
{
Host = "127.0.0.1",
TvCategory = "abc"

@ -17,10 +17,10 @@ namespace NzbDrone.Core.Datastore.Migration
Create.TableForModel("Series")
.WithColumn("TvdbId").AsInt32().Unique()
.WithColumn("TvRageId").AsInt32().Unique()
.WithColumn("ImdbId").AsString().Unique()
.WithColumn("TvRageId").AsInt32()
.WithColumn("ImdbId").AsString().Nullable()
.WithColumn("Title").AsString()
.WithColumn("TitleSlug").AsString().Unique()
.WithColumn("TitleSlug").AsString().Nullable()
.WithColumn("CleanTitle").AsString()
.WithColumn("Status").AsInt32()
.WithColumn("Overview").AsString().Nullable()
@ -28,18 +28,27 @@ namespace NzbDrone.Core.Datastore.Migration
.WithColumn("Images").AsString()
.WithColumn("Path").AsString()
.WithColumn("Monitored").AsBoolean()
.WithColumn("QualityProfileId").AsInt32()
.WithColumn("SeasonFolder").AsBoolean()
.WithColumn("LastInfoSync").AsDateTime().Nullable()
.WithColumn("LastDiskSync").AsDateTime().Nullable()
.WithColumn("Runtime").AsInt32()
.WithColumn("SeriesType").AsInt32()
.WithColumn("BacklogSetting").AsInt32()
.WithColumn("Network").AsString().Nullable()
.WithColumn("CustomStartDate").AsDateTime().Nullable()
.WithColumn("UseSceneNumbering").AsBoolean()
.WithColumn("FirstAired").AsDateTime().Nullable()
.WithColumn("NextAiring").AsDateTime().Nullable();
.WithColumn("NextAiring").AsDateTime().Nullable()
.WithColumn("Year").AsInt32().Nullable()
.WithColumn("Seasons").AsString().Nullable()
.WithColumn("Actors").AsString().Nullable()
.WithColumn("Ratings").AsString().Nullable()
.WithColumn("Genres").AsString().Nullable()
.WithColumn("Certification").AsString().Nullable()
.WithColumn("SortTitle").AsString().Nullable()
.WithColumn("ProfileId").AsInt32().Nullable()
.WithColumn("Tags").AsString().Nullable()
.WithColumn("Added").AsDateTime().Nullable()
.WithColumn("AddOptions").AsString().Nullable()
.WithColumn("TvMazeId").AsInt32().WithDefaultValue(0);
Create.TableForModel("Movies")
.WithColumn("ImdbId").AsString().Unique()
@ -66,101 +75,236 @@ namespace NzbDrone.Core.Datastore.Migration
.WithColumn("Certification").AsString().Nullable()
.WithColumn("AddOptions").AsString().Nullable();
Create.TableForModel("Seasons")
.WithColumn("SeriesId").AsInt32()
.WithColumn("SeasonNumber").AsInt32()
.WithColumn("Ignored").AsBoolean();
Create.TableForModel("Episodes")
.WithColumn("TvDbEpisodeId").AsInt32().Unique()
.WithColumn("SeriesId").AsInt32()
.WithColumn("SeasonNumber").AsInt32()
.WithColumn("EpisodeNumber").AsInt32()
.WithColumn("Title").AsString().Nullable()
.WithColumn("Overview").AsString().Nullable()
.WithColumn("Ignored").AsBoolean().Nullable()
.WithColumn("EpisodeFileId").AsInt32().Nullable()
.WithColumn("AirDate").AsDateTime().Nullable()
.WithColumn("AirDate").AsString().Nullable()
.WithColumn("AirDateUtc").AsDateTime().Nullable()
.WithColumn("AbsoluteEpisodeNumber").AsInt32().Nullable()
.WithColumn("SceneAbsoluteEpisodeNumber").AsInt32().Nullable()
.WithColumn("SceneSeasonNumber").AsInt32().Nullable()
.WithColumn("SceneEpisodeNumber").AsInt32().Nullable();
.WithColumn("SceneEpisodeNumber").AsInt32().Nullable()
.WithColumn("Monitored").AsBoolean().Nullable() // Nullable?
.WithColumn("Ratings").AsString().Nullable()
.WithColumn("Images").AsString().Nullable()
.WithColumn("UnverifiedSceneNumbering").AsBoolean().WithDefaultValue(false);
Create.TableForModel("EpisodeFiles")
.WithColumn("SeriesId").AsInt32()
.WithColumn("Path").AsString().Unique()
.WithColumn("Quality").AsString()
.WithColumn("Size").AsInt64()
.WithColumn("DateAdded").AsDateTime()
.WithColumn("SeasonNumber").AsInt32()
.WithColumn("SceneName").AsString().Nullable()
.WithColumn("ReleaseGroup").AsString().Nullable();
.WithColumn("SeriesId").AsInt32()
.WithColumn("Quality").AsString()
.WithColumn("Size").AsInt64()
.WithColumn("DateAdded").AsDateTime()
.WithColumn("SeasonNumber").AsInt32()
.WithColumn("SceneName").AsString().Nullable()
.WithColumn("ReleaseGroup").AsString().Nullable()
.WithColumn("MediaInfo").AsString().Nullable()
.WithColumn("RelativePath").AsString().Nullable();
Create.TableForModel("History")
.WithColumn("EpisodeId").AsInt32()
.WithColumn("SeriesId").AsInt32()
.WithColumn("NzbTitle").AsString()
.WithColumn("Date").AsDateTime()
.WithColumn("Quality").AsString()
.WithColumn("Indexer").AsString()
.WithColumn("NzbInfoUrl").AsString().Nullable()
.WithColumn("ReleaseGroup").AsString().Nullable()
.WithColumn("MovieId").AsInt32().WithDefaultValue(0);
.WithColumn("EpisodeId").AsInt32()
.WithColumn("SeriesId").AsInt32()
.WithColumn("SourceTitle").AsString()
.WithColumn("Date").AsDateTime()
.WithColumn("Quality").AsString()
.WithColumn("Data").AsString()
.WithColumn("EventType").AsInt32().Nullable()
.WithColumn("DownloadId").AsString().Nullable().Indexed();
Create.TableForModel("Notifications")
.WithColumn("Name").AsString()
.WithColumn("OnGrab").AsBoolean()
.WithColumn("OnDownload").AsBoolean()
.WithColumn("Settings").AsString()
.WithColumn("Implementation").AsString();
.WithColumn("Name").AsString()
.WithColumn("OnGrab").AsBoolean()
.WithColumn("OnDownload").AsBoolean()
.WithColumn("Settings").AsString()
.WithColumn("Implementation").AsString()
.WithColumn("ConfigContract").AsString().Nullable()
.WithColumn("OnUpgrade").AsBoolean().Nullable()
.WithColumn("Tags").AsString().Nullable()
.WithColumn("OnRename").AsBoolean().NotNullable();
Create.TableForModel("ScheduledTasks")
.WithColumn("TypeName").AsString().Unique()
.WithColumn("Interval").AsInt32()
.WithColumn("LastExecution").AsDateTime();
.WithColumn("TypeName").AsString().Unique()
.WithColumn("Interval").AsInt32()
.WithColumn("LastExecution").AsDateTime();
Create.TableForModel("Indexers")
.WithColumn("Enable").AsBoolean()
.WithColumn("Name").AsString().Unique()
.WithColumn("Implementation").AsString()
.WithColumn("Settings").AsString().Nullable();
Create.TableForModel("QualityProfiles")
.WithColumn("Name").AsString().Unique()
.WithColumn("Cutoff").AsInt32()
.WithColumn("Allowed").AsString();
Create.TableForModel("QualitySizes")
.WithColumn("QualityId").AsInt32().Unique()
.WithColumn("Name").AsString().Unique()
.WithColumn("MinSize").AsInt32()
.WithColumn("MaxSize").AsInt32();
.WithColumn("Name").AsString().Unique()
.WithColumn("Implementation").AsString()
.WithColumn("Settings").AsString().Nullable()
.WithColumn("ConfigContract").AsString().Nullable()
.WithColumn("EnableRss").AsBoolean().Nullable()
.WithColumn("EnableSearch").AsBoolean().Nullable();
Create.TableForModel("Profiles")
.WithColumn("Name").AsString().Unique()
.WithColumn("Cutoff").AsInt32()
.WithColumn("Items").AsString().NotNullable()
.WithColumn("Language").AsInt32().Nullable();
Execute.Sql("UPDATE Profiles SET Language = 1");
Create.TableForModel("SceneMappings")
.WithColumn("CleanTitle").AsString()
.WithColumn("SceneName").AsString()
.WithColumn("TvdbId").AsInt32()
.WithColumn("SeasonNumber").AsInt32();
.WithColumn("TvdbId").AsInt32()
.WithColumn("SeasonNumber").AsInt32().Nullable()
.WithColumn("SearchTerm").AsString()
.WithColumn("ParseTerm").AsString()
.WithColumn("Title").AsString().Nullable()
.WithColumn("Type").AsString().Nullable()
.WithColumn("SceneSeasonNumber").AsInt32().Nullable();
Create.TableForModel("NamingConfig")
.WithColumn("UseSceneName").AsBoolean()
.WithColumn("Separator").AsString()
.WithColumn("NumberStyle").AsInt32()
.WithColumn("IncludeSeriesTitle").AsBoolean()
.WithColumn("MultiEpisodeStyle").AsInt32()
.WithColumn("IncludeEpisodeTitle").AsBoolean()
.WithColumn("IncludeQuality").AsBoolean()
.WithColumn("ReplaceSpaces").AsBoolean()
.WithColumn("SeasonFolderFormat").AsString();
.WithColumn("MultiEpisodeStyle").AsInt32()
.WithColumn("RenameEpisodes").AsBoolean().Nullable() // Set a default - Check Lidarr
.WithColumn("StandardEpisodeFormat").AsString().Nullable()
.WithColumn("DailyEpisodeFormat").AsString().Nullable()
.WithColumn("SeriesFolderFormat").AsString().Nullable()
.WithColumn("SeasonFolderFormat").AsString().Nullable()
.WithColumn("AnimeEpisodeFormat").AsString().Nullable()
.WithColumn("ReplaceIllegalCharacters").AsBoolean().WithDefaultValue(true);
Create.TableForModel("Blacklist")
.WithColumn("SeriesId").AsInt32()
.WithColumn("EpisodeIds").AsString()
.WithColumn("SourceTitle").AsString()
.WithColumn("Quality").AsString()
.WithColumn("Date").AsDateTime()
.WithColumn("PublishedDate").AsDateTime().Nullable()
.WithColumn("Size").AsInt64().Nullable()
.WithColumn("Protocol").AsInt32().Nullable()
.WithColumn("Indexer").AsString().Nullable()
.WithColumn("Message").AsString().Nullable()
.WithColumn("TorrentInfoHash").AsString().Nullable();
Create.TableForModel("QualityDefinitions")
.WithColumn("Quality").AsInt32().Unique()
.WithColumn("Title").AsString().Unique()
.WithColumn("MinSize").AsDouble().Nullable()
.WithColumn("MaxSize").AsDouble().Nullable();
Create.TableForModel("Metadata")
.WithColumn("Enable").AsBoolean().NotNullable()
.WithColumn("Name").AsString().NotNullable()
.WithColumn("Implementation").AsString().NotNullable()
.WithColumn("Settings").AsString().NotNullable()
.WithColumn("ConfigContract").AsString().NotNullable();
Create.TableForModel("MetadataFiles")
.WithColumn("SeriesId").AsInt32().NotNullable()
.WithColumn("Consumer").AsString().NotNullable()
.WithColumn("Type").AsInt32().NotNullable()
.WithColumn("RelativePath").AsString().NotNullable()
.WithColumn("LastUpdated").AsDateTime().NotNullable()
.WithColumn("SeasonNumber").AsInt32().Nullable()
.WithColumn("EpisodeFileId").AsInt32().Nullable()
.WithColumn("Added").AsDateTime().Nullable()
.WithColumn("Extension").AsString().NotNullable()
.WithColumn("Hash").AsString().Nullable();
Create.TableForModel("DownloadClients")
.WithColumn("Enable").AsBoolean().NotNullable()
.WithColumn("Name").AsString().NotNullable()
.WithColumn("Implementation").AsString().NotNullable()
.WithColumn("Settings").AsString().NotNullable()
.WithColumn("ConfigContract").AsString().NotNullable();
Create.TableForModel("PendingReleases")
.WithColumn("SeriesId").AsInt32().WithDefaultValue(0)
.WithColumn("Title").AsString()
.WithColumn("Added").AsDateTime()
.WithColumn("ParsedEpisodeInfo").AsString()
.WithColumn("Release").AsString()
.WithColumn("MovieId").AsInt32().WithDefaultValue(0);
Create.TableForModel("RemotePathMappings")
.WithColumn("Host").AsString()
.WithColumn("RemotePath").AsString()
.WithColumn("LocalPath").AsString();
Create.TableForModel("Tags")
.WithColumn("Label").AsString().Unique();
Create.TableForModel("Restrictions")
.WithColumn("Required").AsString().Nullable()
.WithColumn("Preferred").AsString().Nullable()
.WithColumn("Ignored").AsString().Nullable()
.WithColumn("Tags").AsString().NotNullable();
Create.TableForModel("DelayProfiles")
.WithColumn("EnableUsenet").AsBoolean().NotNullable()
.WithColumn("EnableTorrent").AsBoolean().NotNullable()
.WithColumn("PreferredProtocol").AsInt32().NotNullable()
.WithColumn("UsenetDelay").AsInt32().NotNullable()
.WithColumn("TorrentDelay").AsInt32().NotNullable()
.WithColumn("Order").AsInt32().NotNullable()
.WithColumn("Tags").AsString().NotNullable();
Insert.IntoTable("DelayProfiles").Row(new
{
EnableUsenet = 1,
EnableTorrent = 1,
PreferredProtocol = 1,
UsenetDelay = 0,
TorrentDelay = 0,
Order = int.MaxValue,
Tags = "[]"
});
Create.TableForModel("Users")
.WithColumn("Identifier").AsString().NotNullable().Unique()
.WithColumn("Username").AsString().NotNullable().Unique()
.WithColumn("Password").AsString().NotNullable();
Create.TableForModel("Commands")
.WithColumn("Name").AsString().NotNullable()
.WithColumn("Body").AsString().NotNullable()
.WithColumn("Priority").AsInt32().NotNullable()
.WithColumn("Status").AsInt32().NotNullable()
.WithColumn("QueuedAt").AsDateTime().NotNullable()
.WithColumn("StartedAt").AsDateTime().Nullable()
.WithColumn("EndedAt").AsDateTime().Nullable()
.WithColumn("Duration").AsString().Nullable()
.WithColumn("Exception").AsString().Nullable()
.WithColumn("Trigger").AsInt32().NotNullable();
Create.TableForModel("IndexerStatus")
.WithColumn("IndexerId").AsInt32().NotNullable().Unique()
.WithColumn("InitialFailure").AsDateTime().Nullable()
.WithColumn("MostRecentFailure").AsDateTime().Nullable()
.WithColumn("EscalationLevel").AsInt32().NotNullable()
.WithColumn("DisabledTill").AsDateTime().Nullable()
.WithColumn("LastRssSyncReleaseInfo").AsString().Nullable();
Create.TableForModel("ExtraFiles")
.WithColumn("SeriesId").AsInt32().NotNullable()
.WithColumn("SeasonNumber").AsInt32().NotNullable()
.WithColumn("EpisodeFileId").AsInt32().NotNullable()
.WithColumn("RelativePath").AsString().NotNullable()
.WithColumn("Extension").AsString().NotNullable()
.WithColumn("Added").AsDateTime().NotNullable()
.WithColumn("LastUpdated").AsDateTime().NotNullable();
Create.TableForModel("SubtitleFiles")
.WithColumn("SeriesId").AsInt32().NotNullable()
.WithColumn("SeasonNumber").AsInt32().NotNullable()
.WithColumn("EpisodeFileId").AsInt32().NotNullable()
.WithColumn("RelativePath").AsString().NotNullable()
.WithColumn("Extension").AsString().NotNullable()
.WithColumn("Added").AsDateTime().NotNullable()
.WithColumn("LastUpdated").AsDateTime().NotNullable()
.WithColumn("Language").AsInt32().NotNullable();
Create.Index().OnTable("History").OnColumn("Date");
}
protected override void LogDbUpgrade()
{
Create.TableForModel("Logs")
.WithColumn("Message").AsString()
.WithColumn("Time").AsDateTime()
.WithColumn("Time").AsDateTime().Indexed()
.WithColumn("Logger").AsString()
.WithColumn("Method").AsString().Nullable()
.WithColumn("Exception").AsString().Nullable()
.WithColumn("ExceptionType").AsString().Nullable()
.WithColumn("Level").AsString();

@ -0,0 +1,7 @@
namespace NzbDrone.Core.Datastore.Migration
{
//Migrations 002 - 103 were squashed in to 001, do not use these migration numbers, versions will be present in V1 migrated Radarr DBs
public class sonarr_squashed
{
}
}

@ -1,15 +0,0 @@
using FluentMigrator;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(2)]
public class remove_tvrage_imdb_unique_constraint : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Delete.Index().OnTable("Series").OnColumn("TvRageId");
Delete.Index().OnTable("Series").OnColumn("ImdbId");
}
}
}

@ -1,20 +0,0 @@
using FluentMigrator;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(3)]
public class remove_renamed_scene_mapping_columns : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Delete.Table("SceneMappings");
Create.TableForModel("SceneMappings")
.WithColumn("TvdbId").AsInt32()
.WithColumn("SeasonNumber").AsInt32()
.WithColumn("SearchTerm").AsString()
.WithColumn("ParseTerm").AsString();
}
}
}

@ -1,22 +0,0 @@
using FluentMigrator;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(4)]
public class updated_history : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Delete.Table("History");
Create.TableForModel("History")
.WithColumn("EpisodeId").AsInt32()
.WithColumn("SeriesId").AsInt32()
.WithColumn("SourceTitle").AsString()
.WithColumn("Date").AsDateTime()
.WithColumn("Quality").AsString()
.WithColumn("Data").AsString();
}
}
}

@ -1,17 +0,0 @@
using FluentMigrator;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(5)]
public class added_eventtype_to_history : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Alter.Table("History")
.AddColumn("EventType")
.AsInt32()
.Nullable();
}
}
}

@ -1,23 +0,0 @@
using FluentMigrator;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(6)]
public class add_index_to_log_time : NzbDroneMigrationBase
{
protected override void LogDbUpgrade()
{
Delete.Table("Logs");
Create.TableForModel("Logs")
.WithColumn("Message").AsString()
.WithColumn("Time").AsDateTime().Indexed()
.WithColumn("Logger").AsString()
.WithColumn("Method").AsString().Nullable()
.WithColumn("Exception").AsString().Nullable()
.WithColumn("ExceptionType").AsString().Nullable()
.WithColumn("Level").AsString();
}
}
}

@ -1,19 +0,0 @@
using FluentMigrator;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(7)]
public class add_renameEpisodes_to_naming : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Alter.Table("NamingConfig")
.AddColumn("RenameEpisodes")
.AsBoolean()
.Nullable();
Execute.Sql("UPDATE NamingConfig SET RenameEpisodes =~ UseSceneName");
}
}
}

@ -1,15 +0,0 @@
using FluentMigrator;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(8)]
public class remove_backlog : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Delete.Column("BacklogSetting").FromTable("Series");
Delete.Column("UseSceneName").FromTable("NamingConfig");
}
}
}

@ -1,17 +0,0 @@
using FluentMigrator;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(9)]
public class fix_rename_episodes : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Delete.Column("SeasonFolderFormat").FromTable("NamingConfig");
Execute.Sql("UPDATE NamingConfig SET RenameEpisodes = 1 WHERE RenameEpisodes = -1");
Execute.Sql("UPDATE NamingConfig SET RenameEpisodes = 0 WHERE RenameEpisodes = -2");
}
}
}

@ -1,21 +0,0 @@
using FluentMigrator;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(10)]
public class add_monitored : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Alter.Table("Episodes").AddColumn("Monitored").AsBoolean().Nullable();
Alter.Table("Seasons").AddColumn("Monitored").AsBoolean().Nullable();
Execute.Sql("UPDATE Episodes SET Monitored = 1 WHERE Ignored = 0");
Execute.Sql("UPDATE Episodes SET Monitored = 0 WHERE Ignored = 1");
Execute.Sql("UPDATE Seasons SET Monitored = 1 WHERE Ignored = 0");
Execute.Sql("UPDATE Seasons SET Monitored = 0 WHERE Ignored = 1");
}
}
}

@ -1,15 +0,0 @@
using FluentMigrator;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(11)]
public class remove_ignored : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Delete.Column("Ignored").FromTable("Seasons");
Delete.Column("Ignored").FromTable("Episodes");
}
}
}

@ -1,14 +0,0 @@
using FluentMigrator;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(12)]
public class remove_custom_start_date : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Delete.Column("CustomStartDate").FromTable("Series");
}
}
}

@ -1,16 +0,0 @@
using FluentMigrator;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(13)]
public class add_air_date_utc : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Alter.Table("Episodes").AddColumn("AirDateUtc").AsDateTime().Nullable();
Execute.Sql("UPDATE Episodes SET AirDateUtc = AirDate");
}
}
}

@ -1,14 +0,0 @@
using FluentMigrator;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(14)]
public class drop_air_date : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Delete.Column("AirDate").FromTable("Episodes");
}
}
}

@ -1,14 +0,0 @@
using FluentMigrator;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(15)]
public class add_air_date_as_string : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Alter.Table("Episodes").AddColumn("AirDate").AsString().Nullable();
}
}
}

@ -1,14 +0,0 @@
using FluentMigrator;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(16)]
public class updated_imported_history_item : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Execute.Sql(@"UPDATE HISTORY SET Data = replace( Data, '""Path""', '""ImportedPath""' ) WHERE EventType=3");
}
}
}

@ -1,15 +0,0 @@
using FluentMigrator;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(17)]
public class reset_scene_names : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
//we were storing new file name as scene name.
Execute.Sql(@"UPDATE EpisodeFiles SET SceneName = NULL where SceneName != NULL");
}
}
}

@ -1,99 +0,0 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using FluentMigrator;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(18)]
public class remove_duplicates : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Execute.WithConnection(RemoveDuplicates);
}
private void RemoveDuplicates(IDbConnection conn, IDbTransaction tran)
{
RemoveDuplicateSeries<int>(conn, tran, "TvdbId");
RemoveDuplicateSeries<string>(conn, tran, "TitleSlug");
var duplicatedEpisodes = GetDuplicates<int>(conn, tran, "Episodes", "TvDbEpisodeId");
foreach (var duplicate in duplicatedEpisodes)
{
foreach (var episodeId in duplicate.OrderBy(c => c.Key).Skip(1).Select(c => c.Key))
{
RemoveEpisodeRows(conn, tran, episodeId);
}
}
}
private IEnumerable<IGrouping<T, KeyValuePair<int, T>>> GetDuplicates<T>(IDbConnection conn, IDbTransaction tran, string tableName, string columnName)
{
var getDuplicates = conn.CreateCommand();
getDuplicates.Transaction = tran;
getDuplicates.CommandText = string.Format("select id, {0} from {1}", columnName, tableName);
var result = new List<KeyValuePair<int, T>>();
using (var reader = getDuplicates.ExecuteReader())
{
while (reader.Read())
{
result.Add(new KeyValuePair<int, T>(reader.GetInt32(0), (T)Convert.ChangeType(reader[1], typeof(T))));
}
}
return result.GroupBy(c => c.Value).Where(g => g.Count() > 1);
}
private void RemoveDuplicateSeries<T>(IDbConnection conn, IDbTransaction tran, string field)
{
var duplicatedSeries = GetDuplicates<T>(conn, tran, "Series", field);
foreach (var duplicate in duplicatedSeries)
{
foreach (var seriesId in duplicate.OrderBy(c => c.Key).Skip(1).Select(c => c.Key))
{
RemoveSeriesRows(conn, tran, seriesId);
}
}
}
private void RemoveSeriesRows(IDbConnection conn, IDbTransaction tran, int seriesId)
{
var deleteCmd = conn.CreateCommand();
deleteCmd.Transaction = tran;
deleteCmd.CommandText = string.Format("DELETE FROM Series WHERE Id = {0}", seriesId.ToString());
deleteCmd.ExecuteNonQuery();
deleteCmd.CommandText = string.Format("DELETE FROM Episodes WHERE SeriesId = {0}", seriesId.ToString());
deleteCmd.ExecuteNonQuery();
deleteCmd.CommandText = string.Format("DELETE FROM Seasons WHERE SeriesId = {0}", seriesId.ToString());
deleteCmd.ExecuteNonQuery();
deleteCmd.CommandText = string.Format("DELETE FROM History WHERE SeriesId = {0}", seriesId.ToString());
deleteCmd.ExecuteNonQuery();
deleteCmd.CommandText = string.Format("DELETE FROM EpisodeFiles WHERE SeriesId = {0}", seriesId.ToString());
deleteCmd.ExecuteNonQuery();
}
private void RemoveEpisodeRows(IDbConnection conn, IDbTransaction tran, int episodeId)
{
var deleteCmd = conn.CreateCommand();
deleteCmd.Transaction = tran;
deleteCmd.CommandText = string.Format("DELETE FROM Episodes WHERE Id = {0}", episodeId.ToString());
deleteCmd.ExecuteNonQuery();
deleteCmd.CommandText = string.Format("DELETE FROM History WHERE EpisodeId = {0}", episodeId.ToString());
deleteCmd.ExecuteNonQuery();
}
}
}

@ -1,21 +0,0 @@
using FluentMigrator;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(19)]
public class restore_unique_constraints : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
// During an earlier version of drone, the indexes weren't recreated during alter table.
Execute.Sql("DROP INDEX IF EXISTS \"IX_Series_TvdbId\"");
Execute.Sql("DROP INDEX IF EXISTS \"IX_Series_TitleSlug\"");
Execute.Sql("DROP INDEX IF EXISTS \"IX_Episodes_TvDbEpisodeId\"");
Create.Index().OnTable("Series").OnColumn("TvdbId").Unique();
Create.Index().OnTable("Series").OnColumn("TitleSlug").Unique();
Create.Index().OnTable("Episodes").OnColumn("TvDbEpisodeId").Unique();
}
}
}

@ -1,68 +0,0 @@
using System.Collections.Generic;
using System.Data;
using FluentMigrator;
using NzbDrone.Common.Serializer;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(20)]
public class add_year_and_seasons_to_series : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Alter.Table("Series").AddColumn("Year").AsInt32().Nullable();
Alter.Table("Series").AddColumn("Seasons").AsString().Nullable();
Execute.WithConnection(ConvertSeasons);
}
private void ConvertSeasons(IDbConnection conn, IDbTransaction tran)
{
using (IDbCommand allSeriesCmd = conn.CreateCommand())
{
allSeriesCmd.Transaction = tran;
allSeriesCmd.CommandText = @"SELECT Id FROM Series";
using (IDataReader allSeriesReader = allSeriesCmd.ExecuteReader())
{
while (allSeriesReader.Read())
{
int seriesId = allSeriesReader.GetInt32(0);
var seasons = new List<dynamic>();
using (IDbCommand seasonsCmd = conn.CreateCommand())
{
seasonsCmd.Transaction = tran;
seasonsCmd.CommandText = string.Format(@"SELECT SeasonNumber, Monitored FROM Seasons WHERE SeriesId = {0}", seriesId);
using (IDataReader seasonReader = seasonsCmd.ExecuteReader())
{
while (seasonReader.Read())
{
int seasonNumber = seasonReader.GetInt32(0);
bool monitored = seasonReader.GetBoolean(1);
if (seasonNumber == 0)
{
monitored = false;
}
seasons.Add(new { seasonNumber, monitored });
}
}
}
using (IDbCommand updateCmd = conn.CreateCommand())
{
var text = string.Format("UPDATE Series SET Seasons = '{0}' WHERE Id = {1}", seasons.ToJson(), seriesId);
updateCmd.Transaction = tran;
updateCmd.CommandText = text;
updateCmd.ExecuteNonQuery();
}
}
}
}
}
}
}

@ -1,14 +0,0 @@
using FluentMigrator;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(21)]
public class drop_seasons_table : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Delete.Table("Seasons");
}
}
}

@ -1,14 +0,0 @@
using FluentMigrator;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(22)]
public class move_indexer_to_generic_provider : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Alter.Table("Indexers").AddColumn("ConfigContract").AsString().Nullable();
}
}
}

@ -1,19 +0,0 @@
using FluentMigrator;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(23)]
public class add_config_contract_to_indexers : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Update.Table("Indexers").Set(new { ConfigContract = "NewznabSettings" }).Where(new { Implementation = "Newznab" });
Update.Table("Indexers").Set(new { ConfigContract = "OmgwtfnzbsSettings" }).Where(new { Implementation = "Omgwtfnzbs" });
Update.Table("Indexers").Set(new { ConfigContract = "NullConfig" }).Where(new { Implementation = "Wombles" });
Update.Table("Indexers").Set(new { ConfigContract = "NullConfig" }).Where(new { Implementation = "Eztv" });
Delete.FromTable("Indexers").IsNull("ConfigContract");
}
}
}

@ -1,14 +0,0 @@
using FluentMigrator;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(24)]
public class drop_tvdb_episodeid : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Delete.Column("TvDbEpisodeId").FromTable("Episodes");
}
}
}

@ -1,14 +0,0 @@
using FluentMigrator;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(25)]
public class move_notification_to_generic_provider : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Alter.Table("Notifications").AddColumn("ConfigContract").AsString().Nullable();
}
}
}

@ -1,24 +0,0 @@
using FluentMigrator;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(26)]
public class add_config_contract_to_notifications : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Update.Table("Notifications").Set(new { ConfigContract = "EmailSettings" }).Where(new { Implementation = "Email" });
Update.Table("Notifications").Set(new { ConfigContract = "GrowlSettings" }).Where(new { Implementation = "Growl" });
Update.Table("Notifications").Set(new { ConfigContract = "NotifyMyAndroidSettings" }).Where(new { Implementation = "NotifyMyAndroid" });
Update.Table("Notifications").Set(new { ConfigContract = "PlexClientSettings" }).Where(new { Implementation = "PlexClient" });
Update.Table("Notifications").Set(new { ConfigContract = "PlexServerSettings" }).Where(new { Implementation = "PlexServer" });
Update.Table("Notifications").Set(new { ConfigContract = "ProwlSettings" }).Where(new { Implementation = "Prowl" });
Update.Table("Notifications").Set(new { ConfigContract = "PushBulletSettings" }).Where(new { Implementation = "PushBullet" });
Update.Table("Notifications").Set(new { ConfigContract = "PushoverSettings" }).Where(new { Implementation = "Pushover" });
Update.Table("Notifications").Set(new { ConfigContract = "XbmcSettings" }).Where(new { Implementation = "Xbmc" });
Delete.FromTable("Notifications").IsNull("ConfigContract");
}
}
}

@ -1,24 +0,0 @@
using FluentMigrator;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(27)]
public class fix_omgwtfnzbs : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Update.Table("Indexers")
.Set(new { ConfigContract = "OmgwtfnzbsSettings" })
.Where(new { Implementation = "Omgwtfnzbs" });
Update.Table("Indexers")
.Set(new { Settings = "{}" })
.Where(new { Implementation = "Omgwtfnzbs", Settings = (string)null });
Update.Table("Indexers")
.Set(new { Settings = "{}" })
.Where(new { Implementation = "Omgwtfnzbs", Settings = "" });
}
}
}

@ -1,19 +0,0 @@
using FluentMigrator;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(28)]
public class add_blacklist_table : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Create.TableForModel("Blacklist")
.WithColumn("SeriesId").AsInt32()
.WithColumn("EpisodeIds").AsString()
.WithColumn("SourceTitle").AsString()
.WithColumn("Quality").AsString()
.WithColumn("Date").AsDateTime();
}
}
}

@ -1,153 +0,0 @@
using System.Collections.Generic;
using System.Data;
using System.Linq;
using FluentMigrator;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(29)]
public class add_formats_to_naming_config : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Alter.Table("NamingConfig").AddColumn("StandardEpisodeFormat").AsString().Nullable();
Alter.Table("NamingConfig").AddColumn("DailyEpisodeFormat").AsString().Nullable();
Execute.WithConnection(ConvertConfig);
}
private void ConvertConfig(IDbConnection conn, IDbTransaction tran)
{
using (IDbCommand namingConfigCmd = conn.CreateCommand())
{
namingConfigCmd.Transaction = tran;
namingConfigCmd.CommandText = @"SELECT * FROM NamingConfig LIMIT 1";
using (IDataReader namingConfigReader = namingConfigCmd.ExecuteReader())
{
var separatorIndex = namingConfigReader.GetOrdinal("Separator");
var numberStyleIndex = namingConfigReader.GetOrdinal("NumberStyle");
var includeSeriesTitleIndex = namingConfigReader.GetOrdinal("IncludeSeriesTitle");
var includeEpisodeTitleIndex = namingConfigReader.GetOrdinal("IncludeEpisodeTitle");
var includeQualityIndex = namingConfigReader.GetOrdinal("IncludeQuality");
var replaceSpacesIndex = namingConfigReader.GetOrdinal("ReplaceSpaces");
while (namingConfigReader.Read())
{
var separator = namingConfigReader.GetString(separatorIndex);
var numberStyle = namingConfigReader.GetInt32(numberStyleIndex);
var includeSeriesTitle = namingConfigReader.GetBoolean(includeSeriesTitleIndex);
var includeEpisodeTitle = namingConfigReader.GetBoolean(includeEpisodeTitleIndex);
var includeQuality = namingConfigReader.GetBoolean(includeQualityIndex);
var replaceSpaces = namingConfigReader.GetBoolean(replaceSpacesIndex);
//Output settings
var seriesTitlePattern = "";
var episodeTitlePattern = "";
var dailyEpisodePattern = "{Air-Date}";
var qualityFormat = " [{Quality Title}]";
if (includeSeriesTitle)
{
if (replaceSpaces)
{
seriesTitlePattern = "{Series.Title}";
}
else
{
seriesTitlePattern = "{Series Title}";
}
seriesTitlePattern += separator;
}
if (includeEpisodeTitle)
{
episodeTitlePattern = separator;
if (replaceSpaces)
{
episodeTitlePattern += "{Episode.Title}";
}
else
{
episodeTitlePattern += "{Episode Title}";
}
}
var standardEpisodeFormat = string.Format("{0}{1}{2}",
seriesTitlePattern,
GetNumberStyle(numberStyle).Pattern,
episodeTitlePattern);
var dailyEpisodeFormat = string.Format("{0}{1}{2}",
seriesTitlePattern,
dailyEpisodePattern,
episodeTitlePattern);
if (includeQuality)
{
if (replaceSpaces)
{
qualityFormat = ".[{Quality.Title}]";
}
standardEpisodeFormat += qualityFormat;
dailyEpisodeFormat += qualityFormat;
}
using (IDbCommand updateCmd = conn.CreateCommand())
{
var text = string.Format("UPDATE NamingConfig " +
"SET StandardEpisodeFormat = '{0}', " +
"DailyEpisodeFormat = '{1}'",
standardEpisodeFormat,
dailyEpisodeFormat);
updateCmd.Transaction = tran;
updateCmd.CommandText = text;
updateCmd.ExecuteNonQuery();
}
}
}
}
}
private static readonly List<dynamic> NumberStyles = new List<dynamic>
{
new
{
Id = 0,
Name = "1x05",
Pattern = "{season}x{episode:00}",
EpisodeSeparator = "x"
},
new
{
Id = 1,
Name = "01x05",
Pattern = "{season:00}x{episode:00}",
EpisodeSeparator = "x"
},
new
{
Id = 2,
Name = "S01E05",
Pattern = "S{season:00}E{episode:00}",
EpisodeSeparator = "E"
},
new
{
Id = 3,
Name = "s01e05",
Pattern = "s{season:00}e{episode:00}",
EpisodeSeparator = "e"
}
};
private static dynamic GetNumberStyle(int id)
{
return NumberStyles.Single(s => s.Id == id);
}
}
}

@ -1,55 +0,0 @@
using System.Data;
using FluentMigrator;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(30)]
public class add_season_folder_format_to_naming_config : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Alter.Table("NamingConfig").AddColumn("SeasonFolderFormat").AsString().Nullable();
Execute.WithConnection(ConvertConfig);
Execute.Sql("DELETE FROM Config WHERE [Key] = 'seasonfolderformat'");
Execute.Sql("DELETE FROM Config WHERE [Key] = 'useseasonfolder'");
}
private void ConvertConfig(IDbConnection conn, IDbTransaction tran)
{
using (IDbCommand namingConfigCmd = conn.CreateCommand())
{
namingConfigCmd.Transaction = tran;
namingConfigCmd.CommandText = @"SELECT [Value] FROM Config WHERE [Key] = 'seasonfolderformat'";
var seasonFormat = "Season {season}";
using (IDataReader namingConfigReader = namingConfigCmd.ExecuteReader())
{
while (namingConfigReader.Read())
{
//only getting one column, so its index is 0
seasonFormat = namingConfigReader.GetString(0);
seasonFormat = seasonFormat.Replace("%sn", "{Series Title}")
.Replace("%s.n", "{Series.Title}")
.Replace("%s", "{season}")
.Replace("%0s", "{season:00}")
.Replace("%e", "{episode}")
.Replace("%0e", "{episode:00}");
}
}
using (IDbCommand updateCmd = conn.CreateCommand())
{
var text = string.Format("UPDATE NamingConfig " +
"SET SeasonFolderFormat = '{0}'",
seasonFormat);
updateCmd.Transaction = tran;
updateCmd.CommandText = text;
updateCmd.ExecuteNonQuery();
}
}
}
}
}

@ -1,20 +0,0 @@
using FluentMigrator;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(31)]
public class delete_old_naming_config_columns : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Delete.Column("Separator")
.Column("NumberStyle")
.Column("IncludeSeriesTitle")
.Column("IncludeEpisodeTitle")
.Column("IncludeQuality")
.Column("ReplaceSpaces")
.FromTable("NamingConfig");
}
}
}

@ -1,14 +0,0 @@
using FluentMigrator;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(32)]
public class set_default_release_group : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Execute.Sql("UPDATE EpisodeFiles SET ReleaseGroup = 'DRONE' WHERE ReleaseGroup IS NULL");
}
}
}

@ -1,66 +0,0 @@
using System.Data;
using FluentMigrator;
using NzbDrone.Common.Serializer;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(33)]
public class add_api_key_to_pushover : NzbDroneMigrationBase
{
private const string API_KEY = "yz9b4U215iR4vrKFRfjNXP24NMNPKJ";
protected override void MainDbUpgrade()
{
Execute.WithConnection(UpdatePushoverSettings);
}
private void UpdatePushoverSettings(IDbConnection conn, IDbTransaction tran)
{
using (IDbCommand selectCommand = conn.CreateCommand())
{
selectCommand.Transaction = tran;
selectCommand.CommandText = @"SELECT * FROM Notifications WHERE ConfigContract = 'PushoverSettings'";
using (IDataReader reader = selectCommand.ExecuteReader())
{
while (reader.Read())
{
var idIndex = reader.GetOrdinal("Id");
var settingsIndex = reader.GetOrdinal("Settings");
var id = reader.GetInt32(idIndex);
var settings = Json.Deserialize<PushoverSettingsForV33>(reader.GetString(settingsIndex));
settings.ApiKey = API_KEY;
//Set priority to high if its currently emergency
if (settings.Priority == 2)
{
settings.Priority = 1;
}
using (IDbCommand updateCmd = conn.CreateCommand())
{
var text = string.Format("UPDATE Notifications " +
"SET Settings = '{0}'" +
"WHERE Id = {1}",
settings.ToJson(),
id);
updateCmd.Transaction = tran;
updateCmd.CommandText = text;
updateCmd.ExecuteNonQuery();
}
}
}
}
}
private class PushoverSettingsForV33
{
public string ApiKey { get; set; }
public string UserKey { get; set; }
public int Priority { get; set; }
}
}
}

@ -1,16 +0,0 @@
using FluentMigrator;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(34)]
public class remove_series_contraints : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Alter.Table("Series")
.AlterColumn("ImdbId").AsString().Nullable()
.AlterColumn("TitleSlug").AsString().Nullable();
}
}
}

@ -1,16 +0,0 @@
using FluentMigrator;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(35)]
public class add_series_folder_format_to_naming_config : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Alter.Table("NamingConfig").AddColumn("SeriesFolderFormat").AsString().Nullable();
Execute.Sql("UPDATE NamingConfig SET SeriesFolderFormat = '{Series Title}'");
}
}
}

@ -1,131 +0,0 @@
using System.Collections.Generic;
using System.Data;
using System.Linq;
using FluentMigrator;
using NzbDrone.Common.Serializer;
using NzbDrone.Core.Datastore.Converters;
using NzbDrone.Core.Datastore.Migration.Framework;
using NzbDrone.Core.Profiles;
using NzbDrone.Core.Qualities;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(36)]
public class update_with_quality_converters : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
if (!Schema.Table("QualityProfiles").Column("Items").Exists())
{
Alter.Table("QualityProfiles").AddColumn("Items").AsString().Nullable();
}
Execute.WithConnection(ConvertQualityProfiles);
Execute.WithConnection(ConvertQualityModels);
}
private void ConvertQualityProfiles(IDbConnection conn, IDbTransaction tran)
{
var qualityProfileItemConverter = new EmbeddedDocumentConverter<List<ProfileQualityItem>>(new QualityIntConverter());
// Convert 'Allowed' column in QualityProfiles from Json List<object> to Json List<int> (int = Quality)
using (IDbCommand qualityProfileCmd = conn.CreateCommand())
{
qualityProfileCmd.Transaction = tran;
qualityProfileCmd.CommandText = @"SELECT Id, Allowed FROM QualityProfiles";
using (IDataReader qualityProfileReader = qualityProfileCmd.ExecuteReader())
{
while (qualityProfileReader.Read())
{
var id = qualityProfileReader.GetInt32(0);
var allowedJson = qualityProfileReader.GetString(1);
var allowed = Json.Deserialize<List<Quality>>(allowedJson);
var items = Quality.DefaultQualityDefinitions.OrderBy(v => v.Weight).Select(v => new ProfileQualityItem { Quality = v.Quality, Allowed = allowed.Contains(v.Quality) }).ToList();
using (IDbCommand updateCmd = conn.CreateCommand())
{
updateCmd.Transaction = tran;
updateCmd.CommandText = "UPDATE QualityProfiles SET Items = ? WHERE Id = ?";
var param = updateCmd.CreateParameter();
qualityProfileItemConverter.SetValue(param, items);
updateCmd.Parameters.Add(param);
updateCmd.AddParameter(id);
updateCmd.ExecuteNonQuery();
}
}
}
}
}
private void ConvertQualityModels(IDbConnection conn, IDbTransaction tran)
{
// Converts the QualityModel JSON objects to their new format (only storing the QualityId instead of the entire object)
ConvertQualityModel(conn, tran, "Blacklist");
ConvertQualityModel(conn, tran, "EpisodeFiles");
ConvertQualityModel(conn, tran, "History");
}
private void ConvertQualityModel(IDbConnection conn, IDbTransaction tran, string tableName)
{
var qualityModelConverter = new EmbeddedDocumentConverter<DestinationQualityModel036>(new QualityIntConverter());
using (IDbCommand qualityModelCmd = conn.CreateCommand())
{
qualityModelCmd.Transaction = tran;
qualityModelCmd.CommandText = @"SELECT Distinct Quality FROM " + tableName;
using (IDataReader qualityModelReader = qualityModelCmd.ExecuteReader())
{
while (qualityModelReader.Read())
{
var qualityJson = qualityModelReader.GetString(0);
SourceQualityModel036 sourceQuality;
if (!Json.TryDeserialize<SourceQualityModel036>(qualityJson, out sourceQuality))
{
continue;
}
var qualityNew = new DestinationQualityModel036
{
Quality = sourceQuality.Quality.Id,
Proper = sourceQuality.Proper
};
using (IDbCommand updateCmd = conn.CreateCommand())
{
updateCmd.Transaction = tran;
updateCmd.CommandText = "UPDATE " + tableName + " SET Quality = ? WHERE Quality = ?";
var param = updateCmd.CreateParameter();
qualityModelConverter.SetValue(param, qualityNew);
updateCmd.Parameters.Add(param);
updateCmd.AddParameter(qualityJson);
updateCmd.ExecuteNonQuery();
}
}
}
}
}
private class DestinationQualityModel036
{
public int Quality { get; set; }
public bool Proper { get; set; }
}
private class SourceQualityModel036
{
public SourceQuality036 Quality { get; set; }
public bool Proper { get; set; }
}
private class SourceQuality036
{
public int Id { get; set; }
}
}
}

@ -1,64 +0,0 @@
using System.Data;
using System.Linq;
using FluentMigrator;
using NzbDrone.Core.Datastore.Migration.Framework;
using NzbDrone.Core.Qualities;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(37)]
public class add_configurable_qualities : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Delete.Column("Allowed").FromTable("QualityProfiles");
Alter.Column("Items").OnTable("QualityProfiles").AsString().NotNullable();
Create.TableForModel("QualityDefinitions")
.WithColumn("Quality").AsInt32().Unique()
.WithColumn("Title").AsString().Unique()
.WithColumn("Weight").AsInt32().Unique()
.WithColumn("MinSize").AsInt32()
.WithColumn("MaxSize").AsInt32();
Execute.WithConnection(ConvertQualities);
Delete.Table("QualitySizes");
}
private void ConvertQualities(IDbConnection conn, IDbTransaction tran)
{
// Convert QualitySizes to a more generic QualityDefinitions table.
using (IDbCommand qualitySizeCmd = conn.CreateCommand())
{
qualitySizeCmd.Transaction = tran;
qualitySizeCmd.CommandText = @"SELECT QualityId, MinSize, MaxSize FROM QualitySizes";
using (IDataReader qualitySizeReader = qualitySizeCmd.ExecuteReader())
{
while (qualitySizeReader.Read())
{
var qualityId = qualitySizeReader.GetInt32(0);
var minSize = qualitySizeReader.GetInt32(1);
var maxSize = qualitySizeReader.GetInt32(2);
var defaultConfig = Quality.DefaultQualityDefinitions.Single(p => (int)p.Quality == qualityId);
using (IDbCommand updateCmd = conn.CreateCommand())
{
updateCmd.Transaction = tran;
updateCmd.CommandText = "INSERT INTO QualityDefinitions (Quality, Title, Weight, MinSize, MaxSize) VALUES (?, ?, ?, ?, ?)";
updateCmd.AddParameter(qualityId);
updateCmd.AddParameter(defaultConfig.Title);
updateCmd.AddParameter(defaultConfig.Weight);
updateCmd.AddParameter(minSize);
updateCmd.AddParameter(maxSize);
updateCmd.ExecuteNonQuery();
}
}
}
}
}
}
}

@ -1,16 +0,0 @@
using FluentMigrator;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(38)]
public class add_on_upgrade_to_notifications : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Alter.Table("Notifications").AddColumn("OnUpgrade").AsBoolean().Nullable();
Execute.Sql("UPDATE Notifications SET OnUpgrade = OnDownload");
}
}
}

@ -1,28 +0,0 @@
using FluentMigrator;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(39)]
public class add_metadata_tables : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Create.TableForModel("Metadata")
.WithColumn("Enable").AsBoolean().NotNullable()
.WithColumn("Name").AsString().NotNullable()
.WithColumn("Implementation").AsString().NotNullable()
.WithColumn("Settings").AsString().NotNullable()
.WithColumn("ConfigContract").AsString().NotNullable();
Create.TableForModel("MetadataFiles")
.WithColumn("SeriesId").AsInt32().NotNullable()
.WithColumn("Consumer").AsString().NotNullable()
.WithColumn("Type").AsInt32().NotNullable()
.WithColumn("RelativePath").AsString().NotNullable()
.WithColumn("LastUpdated").AsDateTime().NotNullable()
.WithColumn("SeasonNumber").AsInt32().Nullable()
.WithColumn("EpisodeFileId").AsInt32().Nullable();
}
}
}

@ -1,22 +0,0 @@
using FluentMigrator;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(40)]
public class add_metadata_to_episodes_and_series : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Alter.Table("Series")
.AddColumn("Actors").AsString().Nullable()
.AddColumn("Ratings").AsString().Nullable()
.AddColumn("Genres").AsString().Nullable()
.AddColumn("Certification").AsString().Nullable();
Alter.Table("Episodes")
.AddColumn("Ratings").AsString().Nullable()
.AddColumn("Images").AsString().Nullable();
}
}
}

@ -1,14 +0,0 @@
using FluentMigrator;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(41)]
public class fix_xbmc_season_images_metadata : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Execute.Sql("UPDATE MetadataFiles SET Type = 4 WHERE Consumer = 'XbmcMetadata' AND SeasonNumber IS NOT NULL");
}
}
}

@ -1,20 +0,0 @@
using FluentMigrator;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(42)]
public class add_download_clients_table : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Create.TableForModel("DownloadClients")
.WithColumn("Enable").AsBoolean().NotNullable()
.WithColumn("Name").AsString().NotNullable()
.WithColumn("Implementation").AsString().NotNullable()
.WithColumn("Settings").AsString().NotNullable()
.WithColumn("ConfigContract").AsString().NotNullable()
.WithColumn("Protocol").AsInt32().NotNullable();
}
}
}

@ -1,199 +0,0 @@
using System;
using System.Collections.Generic;
using System.Data;
using FluentMigrator;
using NzbDrone.Common.Serializer;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(43)]
public class convert_config_to_download_clients : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Execute.WithConnection(ConvertToThingyProvder);
}
private void ConvertToThingyProvder(IDbConnection conn, IDbTransaction tran)
{
var config = new Dictionary<string, string>();
using (IDbCommand configCmd = conn.CreateCommand())
{
configCmd.Transaction = tran;
configCmd.CommandText = @"SELECT * FROM Config";
using (IDataReader configReader = configCmd.ExecuteReader())
{
var keyIndex = configReader.GetOrdinal("Key");
var valueIndex = configReader.GetOrdinal("Value");
while (configReader.Read())
{
var key = configReader.GetString(keyIndex);
var value = configReader.GetString(valueIndex);
config.Add(key.ToLowerInvariant(), value);
}
}
}
var client = GetConfigValue(config, "DownloadClient", "");
if (string.IsNullOrWhiteSpace(client))
{
return;
}
if (client.Equals("sabnzbd", StringComparison.InvariantCultureIgnoreCase))
{
var settings = new ClientSettingsForMigration
{
Host = GetConfigValue(config, "SabHost", "localhost"),
Port = GetConfigValue(config, "SabPort", 8080),
ApiKey = GetConfigValue(config, "SabApiKey", ""),
Username = GetConfigValue(config, "SabUsername", ""),
Password = GetConfigValue(config, "SabPassword", ""),
TvCategory = GetConfigValue(config, "SabTvCategory", "tv"),
RecentTvPriority = GetSabnzbdPriority(GetConfigValue(config, "NzbgetRecentTvPriority", "Default")),
OlderTvPriority = GetSabnzbdPriority(GetConfigValue(config, "NzbgetOlderTvPriority", "Default")),
UseSsl = GetConfigValue(config, "SabUseSsl", false)
};
AddDownloadClient(conn, tran, "Sabnzbd", "Sabnzbd", settings.ToJson(), "SabnzbdSettings", 1);
}
else if (client.Equals("nzbget", StringComparison.InvariantCultureIgnoreCase))
{
var settings = new ClientSettingsForMigration
{
Host = GetConfigValue(config, "NzbGetHost", "localhost"),
Port = GetConfigValue(config, "NzbgetPort", 6789),
Username = GetConfigValue(config, "NzbgetUsername", "nzbget"),
Password = GetConfigValue(config, "NzbgetPassword", ""),
TvCategory = GetConfigValue(config, "NzbgetTvCategory", "tv"),
RecentTvPriority = GetNzbgetPriority(GetConfigValue(config, "NzbgetRecentTvPriority", "Normal")),
OlderTvPriority = GetNzbgetPriority(GetConfigValue(config, "NzbgetOlderTvPriority", "Normal")),
};
AddDownloadClient(conn, tran, "Nzbget", "Nzbget", settings.ToJson(), "NzbgetSettings", 1);
}
else if (client.Equals("pneumatic", StringComparison.InvariantCultureIgnoreCase))
{
var settings = new FolderSettingsForMigration
{
Folder = GetConfigValue(config, "PneumaticFolder", "")
};
AddDownloadClient(conn, tran, "Pneumatic", "Pneumatic", settings.ToJson(), "FolderSettings", 1);
}
else if (client.Equals("blackhole", StringComparison.InvariantCultureIgnoreCase))
{
var settings = new FolderSettingsForMigration
{
Folder = GetConfigValue(config, "BlackholeFolder", "")
};
AddDownloadClient(conn, tran, "Blackhole", "Blackhole", settings.ToJson(), "FolderSettings", 1);
}
DeleteOldConfigValues(conn, tran);
}
private T GetConfigValue<T>(Dictionary<string, string> config, string key, T defaultValue)
{
key = key.ToLowerInvariant();
if (config.ContainsKey(key))
{
return (T)Convert.ChangeType(config[key], typeof(T));
}
return defaultValue;
}
private void AddDownloadClient(IDbConnection conn,
IDbTransaction tran,
string name,
string implementation,
string settings,
string configContract,
int protocol)
{
using (IDbCommand updateCmd = conn.CreateCommand())
{
var text = string.Format("INSERT INTO DownloadClients (Enable, Name, Implementation, Settings, ConfigContract, Protocol) VALUES (1, ?, ?, ?, ?, ?)");
updateCmd.AddParameter(name);
updateCmd.AddParameter(implementation);
updateCmd.AddParameter(settings);
updateCmd.AddParameter(configContract);
updateCmd.AddParameter(protocol);
updateCmd.Transaction = tran;
updateCmd.CommandText = text;
updateCmd.ExecuteNonQuery();
}
}
private void DeleteOldConfigValues(IDbConnection conn, IDbTransaction tran)
{
using (IDbCommand updateCmd = conn.CreateCommand())
{
var text = "DELETE FROM Config WHERE [KEY] IN ('nzbgetusername', 'nzbgetpassword', 'nzbgethost', 'nzbgetport', " +
"'nzbgettvcategory', 'nzbgetrecenttvpriority', 'nzbgetoldertvpriority', 'sabhost', 'sabport', " +
"'sabapikey', 'sabusername', 'sabpassword', 'sabtvcategory', 'sabrecenttvpriority', " +
"'saboldertvpriority', 'sabusessl', 'downloadclient', 'blackholefolder', 'pneumaticfolder')";
updateCmd.Transaction = tran;
updateCmd.CommandText = text;
updateCmd.ExecuteNonQuery();
}
}
private int GetSabnzbdPriority(string priority)
{
return (int)Enum.Parse(typeof(SabnzbdPriorityForMigration), priority, true);
}
private int GetNzbgetPriority(string priority)
{
return (int)Enum.Parse(typeof(NzbGetPriorityForMigration), priority, true);
}
private class ClientSettingsForMigration
{
public string Host { get; set; }
public int Port { get; set; }
public string ApiKey { get; set; }
public string Username { get; set; }
public string Password { get; set; }
public string TvCategory { get; set; }
public int RecentTvPriority { get; set; }
public int OlderTvPriority { get; set; }
public bool UseSsl { get; set; }
}
private class FolderSettingsForMigration
{
public string Folder { get; set; }
}
private enum SabnzbdPriorityForMigration
{
Default = -100,
Paused = -2,
Low = -1,
Normal = 0,
High = 1,
Force = 2
}
private enum NzbGetPriorityForMigration
{
VeryLow = -100,
Low = -50,
Normal = 0,
High = 50,
VeryHigh = 100
}
}
}

@ -1,27 +0,0 @@
using FluentMigrator;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(44)]
public class fix_xbmc_episode_metadata : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
//Convert Episode Metadata to proper type
Execute.Sql("UPDATE MetadataFiles " +
"SET Type = 2 " +
"WHERE Consumer = 'XbmcMetadata' " +
"AND EpisodeFileId IS NOT NULL " +
"AND Type = 4 " +
"AND RelativePath LIKE '%.nfo'");
//Convert Episode Images to proper type
Execute.Sql("UPDATE MetadataFiles " +
"SET Type = 5 " +
"WHERE Consumer = 'XbmcMetadata' " +
"AND EpisodeFileId IS NOT NULL " +
"AND Type = 4");
}
}
}

@ -1,26 +0,0 @@
using FluentMigrator;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(45)]
public class add_indexes : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Create.Index().OnTable("Blacklist").OnColumn("SeriesId");
Create.Index().OnTable("EpisodeFiles").OnColumn("SeriesId");
Create.Index().OnTable("Episodes").OnColumn("EpisodeFileId");
Create.Index().OnTable("Episodes").OnColumn("SeriesId");
Create.Index().OnTable("History").OnColumn("EpisodeId");
Create.Index().OnTable("History").OnColumn("Date");
Create.Index().OnTable("Series").OnColumn("Path");
Create.Index().OnTable("Series").OnColumn("CleanTitle");
Create.Index().OnTable("Series").OnColumn("TvRageId");
}
}
}

@ -1,16 +0,0 @@
using FluentMigrator;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(46)]
public class fix_nzb_su_url : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Execute.Sql("UPDATE Indexers SET Settings = replace(Settings, '//nzb.su', '//api.nzb.su')" +
"WHERE Implementation = 'Newznab'" +
"AND Settings LIKE '%//nzb.su%'");
}
}
}

@ -1,14 +0,0 @@
using FluentMigrator;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(47)]
public class add_temporary_blacklist_columns : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Alter.Table("Blacklist").AddColumn("PublishedDate").AsDateTime().Nullable();
}
}
}

@ -1,14 +0,0 @@
using FluentMigrator;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(48)]
public class add_title_to_scenemappings : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Alter.Table("SceneMappings").AddColumn("Title").AsString().Nullable();
}
}
}

@ -1,16 +0,0 @@
using FluentMigrator;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(49)]
public class fix_dognzb_url : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Execute.Sql("UPDATE Indexers SET Settings = replace(Settings, '//dognzb.cr', '//api.dognzb.cr')" +
"WHERE Implementation = 'Newznab'" +
"AND Settings LIKE '%//dognzb.cr%'");
}
}
}

@ -1,14 +0,0 @@
using FluentMigrator;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(50)]
public class add_hash_to_metadata_files : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Alter.Table("MetadataFiles").AddColumn("Hash").AsString().Nullable();
}
}
}

@ -1,253 +0,0 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using FluentMigrator;
using Newtonsoft.Json;
using NzbDrone.Common.Extensions;
using NzbDrone.Common.Serializer;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(51)]
public class download_client_import : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Execute.WithConnection(EnableCompletedDownloadHandlingForNewUsers);
Execute.WithConnection(ConvertFolderSettings);
Execute.WithConnection(AssociateImportedHistoryItems);
}
private void EnableCompletedDownloadHandlingForNewUsers(IDbConnection conn, IDbTransaction tran)
{
using (IDbCommand cmd = conn.CreateCommand())
{
cmd.Transaction = tran;
cmd.CommandText = @"SELECT Value FROM Config WHERE Key = 'downloadedepisodesfolder'";
var result = cmd.ExecuteScalar();
if (result == null)
{
cmd.CommandText = @"INSERT INTO Config (Key, Value) VALUES ('enablecompleteddownloadhandling', 'True')";
cmd.ExecuteNonQuery();
}
}
}
private void ConvertFolderSettings(IDbConnection conn, IDbTransaction tran)
{
using (IDbCommand downloadClientsCmd = conn.CreateCommand())
{
downloadClientsCmd.Transaction = tran;
downloadClientsCmd.CommandText = @"SELECT Value FROM Config WHERE Key = 'downloadedepisodesfolder'";
var downloadedEpisodesFolder = downloadClientsCmd.ExecuteScalar() as string;
downloadClientsCmd.Transaction = tran;
downloadClientsCmd.CommandText = @"SELECT Id, Implementation, Settings, ConfigContract FROM DownloadClients WHERE ConfigContract = 'FolderSettings'";
using (IDataReader downloadClientReader = downloadClientsCmd.ExecuteReader())
{
while (downloadClientReader.Read())
{
var id = downloadClientReader.GetInt32(0);
var implementation = downloadClientReader.GetString(1);
var settings = downloadClientReader.GetString(2);
var configContract = downloadClientReader.GetString(3);
var settingsJson = JsonConvert.DeserializeObject(settings) as Newtonsoft.Json.Linq.JObject;
if (implementation == "Blackhole")
{
var newSettings = new
{
NzbFolder = settingsJson.Value<string>("folder"),
WatchFolder = downloadedEpisodesFolder
}.ToJson();
using (IDbCommand updateCmd = conn.CreateCommand())
{
updateCmd.Transaction = tran;
updateCmd.CommandText = "UPDATE DownloadClients SET Implementation = ?, Settings = ?, ConfigContract = ? WHERE Id = ?";
updateCmd.AddParameter("UsenetBlackhole");
updateCmd.AddParameter(newSettings);
updateCmd.AddParameter("UsenetBlackholeSettings");
updateCmd.AddParameter(id);
updateCmd.ExecuteNonQuery();
}
}
else if (implementation == "Pneumatic")
{
var newSettings = new
{
NzbFolder = settingsJson.Value<string>("folder")
}.ToJson();
using (IDbCommand updateCmd = conn.CreateCommand())
{
updateCmd.Transaction = tran;
updateCmd.CommandText = "UPDATE DownloadClients SET Settings = ?, ConfigContract = ? WHERE Id = ?";
updateCmd.AddParameter(newSettings);
updateCmd.AddParameter("PneumaticSettings");
updateCmd.AddParameter(id);
updateCmd.ExecuteNonQuery();
}
}
else
{
using (IDbCommand updateCmd = conn.CreateCommand())
{
updateCmd.Transaction = tran;
updateCmd.CommandText = "DELETE FROM DownloadClients WHERE Id = ?";
updateCmd.AddParameter(id);
updateCmd.ExecuteNonQuery();
}
}
}
}
}
}
private sealed class MigrationHistoryItem
{
public int Id { get; set; }
public int EpisodeId { get; set; }
public int SeriesId { get; set; }
public string SourceTitle { get; set; }
public DateTime Date { get; set; }
public Dictionary<string, string> Data { get; set; }
public MigrationHistoryEventType EventType { get; set; }
}
private enum MigrationHistoryEventType
{
Unknown = 0,
Grabbed = 1,
SeriesFolderImported = 2,
DownloadFolderImported = 3,
DownloadFailed = 4
}
private void AssociateImportedHistoryItems(IDbConnection conn, IDbTransaction tran)
{
var historyItems = new List<MigrationHistoryItem>();
using (IDbCommand historyCmd = conn.CreateCommand())
{
historyCmd.Transaction = tran;
historyCmd.CommandText = @"SELECT Id, EpisodeId, SeriesId, SourceTitle, Date, Data, EventType FROM History WHERE EventType NOT NULL";
using (IDataReader historyRead = historyCmd.ExecuteReader())
{
while (historyRead.Read())
{
historyItems.Add(new MigrationHistoryItem
{
Id = historyRead.GetInt32(0),
EpisodeId = historyRead.GetInt32(1),
SeriesId = historyRead.GetInt32(2),
SourceTitle = historyRead.GetString(3),
Date = historyRead.GetDateTime(4),
Data = Json.Deserialize<Dictionary<string, string>>(historyRead.GetString(5)),
EventType = (MigrationHistoryEventType)historyRead.GetInt32(6)
});
}
}
}
var numHistoryItemsNotAssociated = historyItems.Count(v => v.EventType == MigrationHistoryEventType.DownloadFolderImported &&
v.Data.GetValueOrDefault("downloadClientId") == null);
if (numHistoryItemsNotAssociated == 0)
{
return;
}
var historyItemsToAssociate = new Dictionary<MigrationHistoryItem, MigrationHistoryItem>();
var historyItemsLookup = historyItems.ToLookup(v => v.EpisodeId);
foreach (var historyItemGroup in historyItemsLookup)
{
var list = historyItemGroup.ToList();
for (int i = 0; i < list.Count - 1; i++)
{
var grabbedEvent = list[i];
if (grabbedEvent.EventType != MigrationHistoryEventType.Grabbed)
{
continue;
}
if (grabbedEvent.Data.GetValueOrDefault("downloadClient") == null || grabbedEvent.Data.GetValueOrDefault("downloadClientId") == null)
{
continue;
}
// Check if it is already associated with a failed/imported event.
int j;
for (j = i + 1; j < list.Count; j++)
{
if (list[j].EventType != MigrationHistoryEventType.DownloadFolderImported &&
list[j].EventType != MigrationHistoryEventType.DownloadFailed)
{
continue;
}
if (list[j].Data.ContainsKey("downloadClient") && list[j].Data["downloadClient"] == grabbedEvent.Data["downloadClient"] &&
list[j].Data.ContainsKey("downloadClientId") && list[j].Data["downloadClientId"] == grabbedEvent.Data["downloadClientId"])
{
break;
}
}
if (j != list.Count)
{
list.RemoveAt(j);
list.RemoveAt(i--);
continue;
}
var importedEvent = list[i + 1];
if (importedEvent.EventType != MigrationHistoryEventType.DownloadFolderImported)
{
continue;
}
var droppedPath = importedEvent.Data.GetValueOrDefault("droppedPath");
if (droppedPath != null && new FileInfo(droppedPath).Directory.Name == grabbedEvent.SourceTitle)
{
historyItemsToAssociate[importedEvent] = grabbedEvent;
list.RemoveAt(i + 1);
list.RemoveAt(i--);
}
}
}
foreach (var pair in historyItemsToAssociate)
{
using (IDbCommand updateHistoryCmd = conn.CreateCommand())
{
pair.Key.Data["downloadClient"] = pair.Value.Data["downloadClient"];
pair.Key.Data["downloadClientId"] = pair.Value.Data["downloadClientId"];
updateHistoryCmd.Transaction = tran;
updateHistoryCmd.CommandText = "UPDATE History SET Data = ? WHERE Id = ?";
updateHistoryCmd.AddParameter(pair.Key.Data.ToJson());
updateHistoryCmd.AddParameter(pair.Key.Id);
updateHistoryCmd.ExecuteNonQuery();
}
}
_logger.Info("Updated old History items. {0}/{1} old ImportedEvents were associated with GrabbedEvents.", historyItemsToAssociate.Count, numHistoryItemsNotAssociated);
}
}
}

@ -1,20 +0,0 @@
using FluentMigrator;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(52)]
public class add_columns_for_anime : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
//Support XEM names
Alter.Table("SceneMappings").AddColumn("Type").AsString().Nullable();
Execute.Sql("DELETE FROM SceneMappings");
//Add AnimeEpisodeFormat (set to Stardard Episode format for now)
Alter.Table("NamingConfig").AddColumn("AnimeEpisodeFormat").AsString().Nullable();
Execute.Sql("UPDATE NamingConfig SET AnimeEpisodeFormat = StandardEpisodeFormat");
}
}
}

@ -1,46 +0,0 @@
using System.Data;
using FluentMigrator;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(53)]
public class add_series_sorttitle : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Create.Column("SortTitle").OnTable("Series").AsString().Nullable();
Execute.WithConnection(SetSortTitles);
}
private void SetSortTitles(IDbConnection conn, IDbTransaction tran)
{
using (IDbCommand getSeriesCmd = conn.CreateCommand())
{
getSeriesCmd.Transaction = tran;
getSeriesCmd.CommandText = @"SELECT Id, Title FROM Series";
using (IDataReader seriesReader = getSeriesCmd.ExecuteReader())
{
while (seriesReader.Read())
{
var id = seriesReader.GetInt32(0);
var title = seriesReader.GetString(1);
var sortTitle = Parser.Parser.NormalizeTitle(title).ToLower();
using (IDbCommand updateCmd = conn.CreateCommand())
{
updateCmd.Transaction = tran;
updateCmd.CommandText = "UPDATE Series SET SortTitle = ? WHERE Id = ?";
updateCmd.AddParameter(sortTitle);
updateCmd.AddParameter(id);
updateCmd.ExecuteNonQuery();
}
}
}
}
}
}
}

@ -1,32 +0,0 @@
using FluentMigrator;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(54)]
public class rename_profiles : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Rename.Table("QualityProfiles").To("Profiles");
Alter.Table("Profiles").AddColumn("Language").AsInt32().Nullable();
Alter.Table("Profiles").AddColumn("GrabDelay").AsInt32().Nullable();
Alter.Table("Profiles").AddColumn("GrabDelayMode").AsInt32().Nullable();
Execute.Sql("UPDATE Profiles SET Language = 1, GrabDelay = 0, GrabDelayMode = 0");
//Rename QualityProfileId in Series
Alter.Table("Series").AddColumn("ProfileId").AsInt32().Nullable();
Execute.Sql("UPDATE Series SET ProfileId = QualityProfileId");
//Add HeldReleases
Create.TableForModel("PendingReleases")
.WithColumn("SeriesId").AsInt32().WithDefaultValue(0)
.WithColumn("Title").AsString()
.WithColumn("Added").AsDateTime()
.WithColumn("ParsedEpisodeInfo").AsString()
.WithColumn("Release").AsString()
.WithColumn("MovieId").AsInt32().WithDefaultValue(0);
}
}
}

@ -1,14 +0,0 @@
using FluentMigrator;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(55)]
public class drop_old_profile_columns : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Delete.Column("QualityProfileId").FromTable("Series");
}
}
}

@ -1,14 +0,0 @@
using FluentMigrator;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(56)]
public class add_mediainfo_to_episodefile : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Alter.Table("EpisodeFiles").AddColumn("MediaInfo").AsString().Nullable();
}
}
}

@ -1,47 +0,0 @@
using System.Data;
using System.IO;
using FluentMigrator;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(57)]
public class convert_episode_file_path_to_relative : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Create.Column("RelativePath").OnTable("EpisodeFiles").AsString().Nullable();
//TODO: Add unique contraint for series ID and Relative Path
//TODO: Warn if multiple series share the same path
Execute.WithConnection(UpdateRelativePaths);
}
private void UpdateRelativePaths(IDbConnection conn, IDbTransaction tran)
{
using (IDbCommand getSeriesCmd = conn.CreateCommand())
{
getSeriesCmd.Transaction = tran;
getSeriesCmd.CommandText = @"SELECT Id, Path FROM Series";
using (IDataReader seriesReader = getSeriesCmd.ExecuteReader())
{
while (seriesReader.Read())
{
var seriesId = seriesReader.GetInt32(0);
var seriesPath = seriesReader.GetString(1) + Path.DirectorySeparatorChar;
using (IDbCommand updateCmd = conn.CreateCommand())
{
updateCmd.Transaction = tran;
updateCmd.CommandText = "UPDATE EpisodeFiles SET RelativePath = REPLACE(Path, ?, '') WHERE SeriesId = ?";
updateCmd.AddParameter(seriesPath);
updateCmd.AddParameter(seriesId);
updateCmd.ExecuteNonQuery();
}
}
}
}
}
}
}

@ -1,14 +0,0 @@
using FluentMigrator;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(58)]
public class drop_episode_file_path : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Delete.Column("Path").FromTable("EpisodeFiles");
}
}
}

@ -1,19 +0,0 @@
using FluentMigrator;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(59)]
public class add_enable_options_to_indexers : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Alter.Table("Indexers")
.AddColumn("EnableRss").AsBoolean().Nullable()
.AddColumn("EnableSearch").AsBoolean().Nullable();
Execute.Sql("UPDATE Indexers SET EnableRss = Enable, EnableSearch = Enable");
Execute.Sql("UPDATE Indexers SET EnableSearch = 0 WHERE Implementation = 'Wombles'");
}
}
}

@ -1,15 +0,0 @@
using FluentMigrator;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(60)]
public class remove_enable_from_indexers : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Delete.Column("Enable").FromTable("Indexers");
Delete.Column("Protocol").FromTable("DownloadClients");
}
}
}

@ -1,22 +0,0 @@
using FluentMigrator;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(61)]
public class clear_bad_scene_names : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Execute.Sql("UPDATE [EpisodeFiles] " +
"SET ReleaseGroup = NULL , SceneName = NULL " +
"WHERE " +
" ReleaseGroup IS NULL " +
" OR SceneName IS NULL " +
" OR ReleaseGroup =='DRONE' " +
" OR LENGTH(SceneName) <10 " +
" OR LENGTH(ReleaseGroup) > 20 " +
" OR SceneName NOT LIKE '%.%'");
}
}
}

@ -1,86 +0,0 @@
using System.Collections.Generic;
using System.Data;
using FluentMigrator;
using NzbDrone.Common.Serializer;
using NzbDrone.Core.Datastore.Migration.Framework;
using NzbDrone.Core.Qualities;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(62)]
public class convert_quality_models : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Execute.WithConnection(ConvertQualityModels);
}
private void ConvertQualityModels(IDbConnection conn, IDbTransaction tran)
{
ConvertQualityModelsOnTable(conn, tran, "EpisodeFiles");
ConvertQualityModelsOnTable(conn, tran, "Blacklist");
ConvertQualityModelsOnTable(conn, tran, "History");
}
private void ConvertQualityModelsOnTable(IDbConnection conn, IDbTransaction tran, string tableName)
{
var qualitiesToUpdate = new Dictionary<string, string>();
using (IDbCommand qualityModelCmd = conn.CreateCommand())
{
qualityModelCmd.Transaction = tran;
qualityModelCmd.CommandText = @"SELECT Distinct Quality FROM " + tableName;
using (IDataReader qualityModelReader = qualityModelCmd.ExecuteReader())
{
while (qualityModelReader.Read())
{
var qualityJson = qualityModelReader.GetString(0);
LegacyQualityModel062 quality;
if (!Json.TryDeserialize<LegacyQualityModel062>(qualityJson, out quality))
{
continue;
}
var newQualityModel = new QualityModel062 { Quality = quality.Quality, Revision = new Revision() };
if (quality.Proper)
{
newQualityModel.Revision.Version = 2;
}
var newQualityJson = newQualityModel.ToJson();
qualitiesToUpdate.Add(qualityJson, newQualityJson);
}
}
}
foreach (var quality in qualitiesToUpdate)
{
using (IDbCommand updateCmd = conn.CreateCommand())
{
updateCmd.Transaction = tran;
updateCmd.CommandText = "UPDATE " + tableName + " SET Quality = ? WHERE Quality = ?";
updateCmd.AddParameter(quality.Value);
updateCmd.AddParameter(quality.Key);
updateCmd.ExecuteNonQuery();
}
}
}
private class LegacyQualityModel062
{
public int Quality { get; set; }
public bool Proper { get; set; }
}
private class QualityModel062
{
public int Quality { get; set; }
public Revision Revision { get; set; }
}
}
}

@ -1,17 +0,0 @@
using FluentMigrator;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(63)]
public class add_remotepathmappings : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Create.TableForModel("RemotePathMappings")
.WithColumn("Host").AsString()
.WithColumn("RemotePath").AsString()
.WithColumn("LocalPath").AsString();
}
}
}

@ -1,14 +0,0 @@
using FluentMigrator;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(64)]
public class remove_method_from_logs : NzbDroneMigrationBase
{
protected override void LogDbUpgrade()
{
Delete.Column("Method").FromTable("Logs");
}
}
}

@ -1,16 +0,0 @@
using FluentMigrator;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(65)]
public class make_scene_numbering_nullable : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Execute.Sql("UPDATE Episodes SET AbsoluteEpisodeNumber = NULL WHERE AbsoluteEpisodeNumber = 0");
Execute.Sql("UPDATE Episodes SET SceneAbsoluteEpisodeNumber = NULL WHERE SceneAbsoluteEpisodeNumber = 0");
Execute.Sql("UPDATE Episodes SET SceneSeasonNumber = NULL, SceneEpisodeNumber = NULL WHERE SceneSeasonNumber = 0 AND SceneEpisodeNumber = 0");
}
}
}

@ -1,24 +0,0 @@
using FluentMigrator;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(66)]
public class add_tags : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Create.TableForModel("Tags")
.WithColumn("Label").AsString().NotNullable();
Alter.Table("Series")
.AddColumn("Tags").AsString().Nullable();
Alter.Table("Notifications")
.AddColumn("Tags").AsString().Nullable();
Execute.Sql("UPDATE Series SET Tags = '[]'");
Execute.Sql("UPDATE Notifications SET Tags = '[]'");
}
}
}

@ -1,14 +0,0 @@
using FluentMigrator;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(67)]
public class add_added_to_series : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Alter.Table("Series").AddColumn("Added").AsDateTime().Nullable();
}
}
}

@ -1,49 +0,0 @@
using System.Data;
using FluentMigrator;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(68)]
public class add_release_restrictions : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Create.TableForModel("Restrictions")
.WithColumn("Required").AsString().Nullable()
.WithColumn("Preferred").AsString().Nullable()
.WithColumn("Ignored").AsString().Nullable()
.WithColumn("Tags").AsString().NotNullable();
Execute.WithConnection(ConvertRestrictions);
Execute.Sql("DELETE FROM Config WHERE [Key] = 'releaserestrictions'");
}
private void ConvertRestrictions(IDbConnection conn, IDbTransaction tran)
{
using (IDbCommand getRestictionsCmd = conn.CreateCommand())
{
getRestictionsCmd.Transaction = tran;
getRestictionsCmd.CommandText = @"SELECT [Value] FROM Config WHERE [Key] = 'releaserestrictions'";
using (IDataReader configReader = getRestictionsCmd.ExecuteReader())
{
while (configReader.Read())
{
var restrictions = configReader.GetString(0);
restrictions = restrictions.Replace("\n", ",");
using (IDbCommand insertCmd = conn.CreateCommand())
{
insertCmd.Transaction = tran;
insertCmd.CommandText = "INSERT INTO Restrictions (Ignored, Tags) VALUES (?, '[]')";
insertCmd.AddParameter(restrictions);
insertCmd.ExecuteNonQuery();
}
}
}
}
}
}
}

@ -1,99 +0,0 @@
using System.Data;
using System.Linq;
using System.Text.RegularExpressions;
using FluentMigrator;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(69)]
public class quality_proper : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Execute.WithConnection(ConvertQualityTitle);
}
private static readonly Regex QualityTitleRegex = new Regex(@"\{(?<prefix>[- ._\[(]*)(?<token>(?:quality)(?:(?<separator>[- ._]+)(?:title))?)(?<suffix>[- ._)\]]*)\}",
RegexOptions.Compiled | RegexOptions.IgnoreCase);
private void ConvertQualityTitle(IDbConnection conn, IDbTransaction tran)
{
using (IDbCommand namingConfigCmd = conn.CreateCommand())
{
namingConfigCmd.Transaction = tran;
namingConfigCmd.CommandText = @"SELECT StandardEpisodeFormat, DailyEpisodeFormat, AnimeEpisodeFormat FROM NamingConfig LIMIT 1";
using (IDataReader configReader = namingConfigCmd.ExecuteReader())
{
while (configReader.Read())
{
var currentStandard = configReader.GetString(0);
var currentDaily = configReader.GetString(1);
var currentAnime = configReader.GetString(2);
var newStandard = GetNewFormat(currentStandard);
var newDaily = GetNewFormat(currentDaily);
var newAnime = GetNewFormat(currentAnime);
using (IDbCommand updateCmd = conn.CreateCommand())
{
updateCmd.Transaction = tran;
updateCmd.CommandText = "UPDATE NamingConfig SET StandardEpisodeFormat = ?, DailyEpisodeFormat = ?, AnimeEpisodeFormat = ?";
updateCmd.AddParameter(newStandard);
updateCmd.AddParameter(newDaily);
updateCmd.AddParameter(newAnime);
updateCmd.ExecuteNonQuery();
}
}
}
}
}
private string GetNewFormat(string currentFormat)
{
var matches = QualityTitleRegex.Matches(currentFormat);
var result = currentFormat;
foreach (Match match in matches)
{
var tokenMatch = GetTokenMatch(match);
var qualityFullToken = string.Format("Quality{0}Full", tokenMatch.Separator);
if (tokenMatch.Token.All(t => !char.IsLetter(t) || char.IsLower(t)))
{
qualityFullToken = string.Format("quality{0}full", tokenMatch.Separator);
}
else if (tokenMatch.Token.All(t => !char.IsLetter(t) || char.IsUpper(t)))
{
qualityFullToken = string.Format("QUALITY{0}FULL", tokenMatch.Separator);
}
result = result.Replace(match.Groups["token"].Value, qualityFullToken);
}
return result;
}
private TokenMatch69 GetTokenMatch(Match match)
{
return new TokenMatch69
{
Prefix = match.Groups["prefix"].Value,
Token = match.Groups["token"].Value,
Separator = match.Groups["separator"].Value,
Suffix = match.Groups["suffix"].Value,
};
}
private class TokenMatch69
{
public string Prefix { get; set; }
public string Token { get; set; }
public string Separator { get; set; }
public string Suffix { get; set; }
}
}
}

@ -1,185 +0,0 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using FluentMigrator;
using NzbDrone.Common.Extensions;
using NzbDrone.Common.Serializer;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(70)]
public class delay_profile : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Create.TableForModel("DelayProfiles")
.WithColumn("EnableUsenet").AsBoolean().NotNullable()
.WithColumn("EnableTorrent").AsBoolean().NotNullable()
.WithColumn("PreferredProtocol").AsInt32().NotNullable()
.WithColumn("UsenetDelay").AsInt32().NotNullable()
.WithColumn("TorrentDelay").AsInt32().NotNullable()
.WithColumn("Order").AsInt32().NotNullable()
.WithColumn("Tags").AsString().NotNullable();
Insert.IntoTable("DelayProfiles").Row(new
{
EnableUsenet = 1,
EnableTorrent = 1,
PreferredProtocol = 1,
UsenetDelay = 0,
TorrentDelay = 0,
Order = int.MaxValue,
Tags = "[]"
});
Execute.WithConnection(ConvertProfile);
Delete.Column("GrabDelay").FromTable("Profiles");
Delete.Column("GrabDelayMode").FromTable("Profiles");
}
private void ConvertProfile(IDbConnection conn, IDbTransaction tran)
{
var profiles = GetProfiles(conn, tran);
var order = 1;
foreach (var profileClosure in profiles.DistinctBy(p => p.GrabDelay))
{
var profile = profileClosure;
if (profile.GrabDelay == 0)
{
continue;
}
var tag = string.Format("delay-{0}", profile.GrabDelay);
var tagId = InsertTag(conn, tran, tag);
var tags = string.Format("[{0}]", tagId);
using (IDbCommand insertDelayProfileCmd = conn.CreateCommand())
{
insertDelayProfileCmd.Transaction = tran;
insertDelayProfileCmd.CommandText = "INSERT INTO DelayProfiles (EnableUsenet, EnableTorrent, PreferredProtocol, TorrentDelay, UsenetDelay, [Order], Tags) VALUES (1, 1, 1, 0, ?, ?, ?)";
insertDelayProfileCmd.AddParameter(profile.GrabDelay);
insertDelayProfileCmd.AddParameter(order);
insertDelayProfileCmd.AddParameter(tags);
insertDelayProfileCmd.ExecuteNonQuery();
}
var matchingProfileIds = profiles.Where(p => p.GrabDelay == profile.GrabDelay)
.Select(p => p.Id);
UpdateSeries(conn, tran, matchingProfileIds, tagId);
order++;
}
}
private List<Profile69> GetProfiles(IDbConnection conn, IDbTransaction tran)
{
var profiles = new List<Profile69>();
using (IDbCommand getProfilesCmd = conn.CreateCommand())
{
getProfilesCmd.Transaction = tran;
getProfilesCmd.CommandText = @"SELECT Id, GrabDelay FROM Profiles";
using (IDataReader profileReader = getProfilesCmd.ExecuteReader())
{
while (profileReader.Read())
{
var id = profileReader.GetInt32(0);
var delay = profileReader.GetInt32(1);
profiles.Add(new Profile69
{
Id = id,
GrabDelay = delay * 60
});
}
}
}
return profiles;
}
private int InsertTag(IDbConnection conn, IDbTransaction tran, string tagLabel)
{
using (IDbCommand insertCmd = conn.CreateCommand())
{
insertCmd.Transaction = tran;
insertCmd.CommandText = @"INSERT INTO Tags (Label) VALUES (?); SELECT last_insert_rowid()";
insertCmd.AddParameter(tagLabel);
var id = insertCmd.ExecuteScalar();
return Convert.ToInt32(id);
}
}
private void UpdateSeries(IDbConnection conn, IDbTransaction tran, IEnumerable<int> profileIds, int tagId)
{
using (IDbCommand getSeriesCmd = conn.CreateCommand())
{
getSeriesCmd.Transaction = tran;
getSeriesCmd.CommandText = "SELECT Id, Tags FROM Series WHERE ProfileId IN (?)";
getSeriesCmd.AddParameter(string.Join(",", profileIds));
using (IDataReader seriesReader = getSeriesCmd.ExecuteReader())
{
while (seriesReader.Read())
{
var id = seriesReader.GetInt32(0);
var tagString = seriesReader.GetString(1);
var tags = Json.Deserialize<List<int>>(tagString);
tags.Add(tagId);
using (IDbCommand updateSeriesCmd = conn.CreateCommand())
{
updateSeriesCmd.Transaction = tran;
updateSeriesCmd.CommandText = "UPDATE Series SET Tags = ? WHERE Id = ?";
updateSeriesCmd.AddParameter(tags.ToJson());
updateSeriesCmd.AddParameter(id);
updateSeriesCmd.ExecuteNonQuery();
}
}
}
}
}
}
public class Profile69
{
public int Id { get; set; }
public int GrabDelay { get; set; }
}
public class Series69
{
public int Id { get; set; }
public List<int> Tags { get; set; }
public DateTime? LastInfoSync { get; set; }
}
public class Tag69
{
public int Id { get; set; }
public string Label { get; set; }
}
public class DelayProfile70
{
public int Id { get; set; }
public bool EnableUsenet { get; set; }
public bool EnableTorrent { get; set; }
public int PreferredProtocol { get; set; }
public int UsenetDelay { get; set; }
public int TorrentDelay { get; set; }
public int Order { get; set; }
public List<int> Tags { get; set; }
}
}

@ -1,238 +0,0 @@
using System.Collections.Generic;
using System.Data;
using System.Linq;
using FluentMigrator;
using NzbDrone.Common.Serializer;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(71)]
public class unknown_quality_in_profile : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Delete.Column("Weight").FromTable("QualityDefinitions");
Execute.WithConnection(ConvertProfile);
}
private void ConvertProfile(IDbConnection conn, IDbTransaction tran)
{
var updater = new ProfileUpdater70(conn, tran);
updater.PrependQuality(0);
updater.Commit();
}
}
public class Profile70
{
public int Id { get; set; }
public string Name { get; set; }
public int Cutoff { get; set; }
public List<ProfileItem70> Items { get; set; }
public int Language { get; set; }
public List<string> PreferredTags { get; set; }
}
public class ProfileItem70
{
public int? QualityDefinition { get; set; }
public int? Quality { get; set; }
public bool Allowed { get; set; }
}
public class QualityDefinition70
{
public int Id { get; set; }
public int Quality { get; set; }
}
public class ProfileUpdater70
{
private readonly IDbConnection _connection;
private readonly IDbTransaction _transaction;
private List<Profile70> _profiles;
private HashSet<Profile70> _changedProfiles = new HashSet<Profile70>();
public ProfileUpdater70(IDbConnection conn, IDbTransaction tran)
{
_connection = conn;
_transaction = tran;
_profiles = GetProfiles();
}
public void Commit()
{
foreach (var profile in _changedProfiles)
{
using (var updateProfileCmd = _connection.CreateCommand())
{
updateProfileCmd.Transaction = _transaction;
updateProfileCmd.CommandText = "UPDATE Profiles SET Name = ?, Cutoff = ?, Items = ?, Language = ? WHERE Id = ?";
updateProfileCmd.AddParameter(profile.Name);
updateProfileCmd.AddParameter(profile.Cutoff);
updateProfileCmd.AddParameter(profile.Items.ToJson());
updateProfileCmd.AddParameter(profile.Language);
updateProfileCmd.AddParameter(profile.Id);
updateProfileCmd.ExecuteNonQuery();
}
}
_changedProfiles.Clear();
}
public void PrependQuality(int quality)
{
foreach (var profile in _profiles)
{
if (profile.Items.Any(v => v.Quality == quality))
{
continue;
}
profile.Items.Insert(0, new ProfileItem70
{
Quality = quality,
Allowed = false
});
_changedProfiles.Add(profile);
}
}
public void AppendQuality(int quality)
{
foreach (var profile in _profiles)
{
if (profile.Items.Any(v => v.Quality == quality))
{
continue;
}
profile.Items.Add(new ProfileItem70
{
Quality = quality,
Allowed = false
});
_changedProfiles.Add(profile);
}
}
public void SplitQualityPrepend(int find, int quality)
{
foreach (var profile in _profiles)
{
if (profile.Items.Any(v => v.Quality == quality))
{
continue;
}
var findIndex = profile.Items.FindIndex(v => v.Quality == find);
profile.Items.Insert(findIndex, new ProfileItem70
{
Quality = quality,
Allowed = profile.Items[findIndex].Allowed
});
if (profile.Cutoff == find)
{
profile.Cutoff = quality;
}
_changedProfiles.Add(profile);
}
}
public void SplitQualityAppend(int find, int quality)
{
foreach (var profile in _profiles)
{
if (profile.Items.Any(v => v.Quality == quality))
{
continue;
}
var findIndex = profile.Items.FindIndex(v => v.Quality == find);
profile.Items.Insert(findIndex + 1, new ProfileItem70
{
Quality = quality,
Allowed = false
});
_changedProfiles.Add(profile);
}
}
public void UpdateQualityToQualityDefinition()
{
var definitions = new List<QualityDefinition70>();
using (var getDefinitions = _connection.CreateCommand())
{
getDefinitions.Transaction = _transaction;
getDefinitions.CommandText = @"SELECT Id, Quality FROM QualityDefinitions";
using (var definitionsReader = getDefinitions.ExecuteReader())
{
while (definitionsReader.Read())
{
int id = definitionsReader.GetInt32(0);
int quality = definitionsReader.GetInt32(1);
definitions.Add(new QualityDefinition70 { Id = id, Quality = quality });
}
}
}
foreach (var profile in _profiles)
{
profile.Items = profile.Items.Select(i =>
{
return new ProfileItem70
{
Allowed = i.Allowed,
Quality = i.Quality,
QualityDefinition = definitions.Find(d => d.Quality == i.Quality).Id
};
}).ToList();
profile.Cutoff = definitions.Find(d => d.Quality == profile.Cutoff).Id;
_changedProfiles.Add(profile);
}
}
private List<Profile70> GetProfiles()
{
var profiles = new List<Profile70>();
using (var getProfilesCmd = _connection.CreateCommand())
{
getProfilesCmd.Transaction = _transaction;
getProfilesCmd.CommandText = @"SELECT Id, Name, Cutoff, Items, Language FROM Profiles";
using (var profileReader = getProfilesCmd.ExecuteReader())
{
while (profileReader.Read())
{
profiles.Add(new Profile70
{
Id = profileReader.GetInt32(0),
Name = profileReader.GetString(1),
Cutoff = profileReader.GetInt32(2),
Items = Json.Deserialize<List<ProfileItem70>>(profileReader.GetString(3)),
Language = profileReader.GetInt32(4)
});
}
}
}
return profiles;
}
}
}

@ -1,76 +0,0 @@
using System;
using System.Collections.Generic;
using System.Data;
using FluentMigrator;
using NzbDrone.Common.Serializer;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(72)]
public class history_downloadId : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Alter.Table("History")
.AddColumn("DownloadId").AsString()
.Nullable()
.Indexed();
Execute.WithConnection(MoveToColumn);
}
private void MoveToColumn(IDbConnection conn, IDbTransaction tran)
{
using (IDbCommand getHistory = conn.CreateCommand())
{
getHistory.Transaction = tran;
getHistory.CommandText = @"SELECT Id, Data FROM History WHERE Data LIKE '%downloadClientId%'";
using (var historyReader = getHistory.ExecuteReader())
{
while (historyReader.Read())
{
var id = historyReader.GetInt32(0);
var data = historyReader.GetString(1);
UpdateHistory(tran, conn, id, data);
}
}
}
}
private void UpdateHistory(IDbTransaction tran, IDbConnection conn, int id, string data)
{
var dic = Json.Deserialize<Dictionary<string, string>>(data);
var downloadId = dic["downloadClientId"];
dic.Remove("downloadClientId");
using (var updateHistoryCmd = conn.CreateCommand())
{
updateHistoryCmd.Transaction = tran;
updateHistoryCmd.CommandText = @"UPDATE History SET DownloadId = ?, Data = ? WHERE Id = ?";
updateHistoryCmd.AddParameter(downloadId);
updateHistoryCmd.AddParameter(dic.ToJson());
updateHistoryCmd.AddParameter(id);
updateHistoryCmd.ExecuteNonQuery();
}
}
}
public class History72
{
public int EpisodeId { get; set; }
public int SeriesId { get; set; }
public string SourceTitle { get; set; }
public string Quality { get; set; }
public DateTime Date { get; set; }
public int EventType { get; set; }
public Dictionary<string, string> Data { get; set; }
public string DownloadId { get; set; }
}
}

@ -1,20 +0,0 @@
using FluentMigrator;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(73)]
public class clear_ratings : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Update.Table("Series")
.Set(new { Ratings = "{}" })
.AllRows();
Update.Table("Episodes")
.Set(new { Ratings = "{}" })
.AllRows();
}
}
}

@ -1,14 +0,0 @@
using FluentMigrator;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(74)]
public class disable_eztv : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Execute.Sql("UPDATE Indexers SET EnableRss = 0, EnableSearch = 0 WHERE Implementation = 'Eztv' AND Settings LIKE '%ezrss.it%'");
}
}
}

@ -1,29 +0,0 @@
using System;
using FluentMigrator;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(75)]
public class force_lib_update : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Update.Table("ScheduledTasks")
.Set(new { LastExecution = "2014-01-01 00:00:00" })
.Where(new { TypeName = "NzbDrone.Core.Tv.Commands.RefreshSeriesCommand" });
Update.Table("Series")
.Set(new { LastInfoSync = "2014-01-01 00:00:00" })
.AllRows();
}
}
public class ScheduledTasks75
{
public int Id { get; set; }
public string TypeName { get; set; }
public int Interval { get; set; }
public DateTime LastExecution { get; set; }
}
}

@ -1,17 +0,0 @@
using FluentMigrator;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(76)]
public class add_users_table : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Create.TableForModel("Users")
.WithColumn("Identifier").AsString().NotNullable().Unique()
.WithColumn("Username").AsString().NotNullable().Unique()
.WithColumn("Password").AsString().NotNullable();
}
}
}

@ -1,14 +0,0 @@
using FluentMigrator;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(77)]
public class add_add_options_to_series : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Alter.Table("Series").AddColumn("AddOptions").AsString().Nullable();
}
}
}

@ -1,24 +0,0 @@
using FluentMigrator;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(78)]
public class add_commands_table : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Create.TableForModel("Commands")
.WithColumn("Name").AsString().NotNullable()
.WithColumn("Body").AsString().NotNullable()
.WithColumn("Priority").AsInt32().NotNullable()
.WithColumn("Status").AsInt32().NotNullable()
.WithColumn("QueuedAt").AsDateTime().NotNullable()
.WithColumn("StartedAt").AsDateTime().Nullable()
.WithColumn("EndedAt").AsDateTime().Nullable()
.WithColumn("Duration").AsString().Nullable()
.WithColumn("Exception").AsString().Nullable()
.WithColumn("Trigger").AsInt32().NotNullable();
}
}
}

@ -1,157 +0,0 @@
using System.Collections.Generic;
using System.Data;
using System.Linq;
using FluentMigrator;
using NzbDrone.Common.Extensions;
using NzbDrone.Common.Serializer;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(79)]
public class dedupe_tags : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Execute.WithConnection(CleanupTags);
Alter.Table("Tags").AlterColumn("Label").AsString().Unique();
}
private void CleanupTags(IDbConnection conn, IDbTransaction tran)
{
var tags = GetTags(conn, tran);
var grouped = tags.GroupBy(t => t.Label.ToLowerInvariant());
var replacements = new List<TagReplacement079>();
foreach (var group in grouped.Where(g => g.Count() > 1))
{
var first = group.First().Id;
foreach (var other in group.Skip(1).Select(t => t.Id))
{
replacements.Add(new TagReplacement079 { OldId = other, NewId = first });
}
}
UpdateTaggedModel(conn, tran, "Series", replacements);
UpdateTaggedModel(conn, tran, "Notifications", replacements);
UpdateTaggedModel(conn, tran, "DelayProfiles", replacements);
UpdateTaggedModel(conn, tran, "Restrictions", replacements);
DeleteTags(conn, tran, replacements);
}
private List<Tag079> GetTags(IDbConnection conn, IDbTransaction tran)
{
var tags = new List<Tag079>();
using (IDbCommand tagCmd = conn.CreateCommand())
{
tagCmd.Transaction = tran;
tagCmd.CommandText = @"SELECT Id, Label FROM Tags";
using (IDataReader tagReader = tagCmd.ExecuteReader())
{
while (tagReader.Read())
{
var id = tagReader.GetInt32(0);
var label = tagReader.GetString(1);
tags.Add(new Tag079 { Id = id, Label = label });
}
}
}
return tags;
}
private void UpdateTaggedModel(IDbConnection conn, IDbTransaction tran, string table, List<TagReplacement079> replacements)
{
var tagged = new List<TaggedModel079>();
using (IDbCommand tagCmd = conn.CreateCommand())
{
tagCmd.Transaction = tran;
tagCmd.CommandText = string.Format("SELECT Id, Tags FROM {0}", table);
using (IDataReader tagReader = tagCmd.ExecuteReader())
{
while (tagReader.Read())
{
if (!tagReader.IsDBNull(1))
{
var id = tagReader.GetInt32(0);
var tags = tagReader.GetString(1);
tagged.Add(new TaggedModel079
{
Id = id,
Tags = Json.Deserialize<HashSet<int>>(tags)
});
}
}
}
}
var toUpdate = new List<TaggedModel079>();
foreach (var model in tagged)
{
foreach (var replacement in replacements)
{
if (model.Tags.Contains(replacement.OldId))
{
model.Tags.Remove(replacement.OldId);
model.Tags.Add(replacement.NewId);
toUpdate.Add(model);
}
}
}
foreach (var model in toUpdate.DistinctBy(m => m.Id))
{
using (IDbCommand updateCmd = conn.CreateCommand())
{
updateCmd.Transaction = tran;
updateCmd.CommandText = string.Format(@"UPDATE {0} SET Tags = ? WHERE Id = ?", table);
updateCmd.AddParameter(model.Tags.ToJson());
updateCmd.AddParameter(model.Id);
updateCmd.ExecuteNonQuery();
}
}
}
private void DeleteTags(IDbConnection conn, IDbTransaction tran, List<TagReplacement079> replacements)
{
var idsToRemove = replacements.Select(r => r.OldId).Distinct();
using (IDbCommand removeCmd = conn.CreateCommand())
{
removeCmd.Transaction = tran;
removeCmd.CommandText = string.Format("DELETE FROM Tags WHERE Id IN ({0})", string.Join(",", idsToRemove));
removeCmd.ExecuteNonQuery();
}
}
private class Tag079
{
public int Id { get; set; }
public string Label { get; set; }
}
private class TagReplacement079
{
public int OldId { get; set; }
public int NewId { get; set; }
}
private class TaggedModel079
{
public int Id { get; set; }
public HashSet<int> Tags { get; set; }
}
}
}

@ -1,92 +0,0 @@
using System.Collections.Generic;
using System.Data;
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(81)]
public class move_dot_prefix_to_transmission_category : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Execute.WithConnection(UpdateTransmissionSettings);
}
private void UpdateTransmissionSettings(IDbConnection conn, IDbTransaction tran)
{
using (var cmd = conn.CreateCommand())
{
cmd.Transaction = tran;
cmd.CommandText = "SELECT Id, Settings FROM DownloadClients WHERE Implementation = 'Transmission'";
using (var reader = cmd.ExecuteReader())
{
while (reader.Read())
{
var id = reader.GetInt32(0);
var settingsJson = reader.GetString(1);
var settings = Json.Deserialize<Dictionary<string, object>>(settingsJson);
var tvCategory = settings.GetValueOrDefault("tvCategory") as string;
if (tvCategory.IsNotNullOrWhiteSpace())
{
settings["tvCategory"] = "." + tvCategory;
using (var updateCmd = conn.CreateCommand())
{
updateCmd.Transaction = tran;
updateCmd.CommandText = "UPDATE DownloadClients SET Settings = ? WHERE Id = ?";
updateCmd.AddParameter(settings.ToJson());
updateCmd.AddParameter(id);
updateCmd.ExecuteNonQuery();
}
}
}
}
}
}
}
public class DownloadClientDefinition81
{
public int Id { get; set; }
public bool Enable { get; set; }
public string Name { get; set; }
public string Implementation { get; set; }
public JObject Settings { get; set; }
public string ConfigContract { get; set; }
}
public class SabnzbdSettings81
{
public string Host { get; set; }
public int Port { get; set; }
public string ApiKey { get; set; }
public string Username { get; set; }
public string Password { get; set; }
public string TvCategory { get; set; }
public int RecentTvPriority { get; set; }
public int OlderTvPriority { get; set; }
public bool UseSsl { get; set; }
}
public class TransmissionSettings81
{
public string Host { get; set; }
public int Port { get; set; }
public string UrlBase { get; set; }
public string Username { get; set; }
public string Password { get; set; }
public string TvCategory { get; set; }
public string TvDirectory { get; set; }
public int RecentTvPriority { get; set; }
public int OlderTvPriority { get; set; }
public bool UseSsl { get; set; }
}
}

@ -1,14 +0,0 @@
using FluentMigrator;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(82)]
public class add_fanzub_settings : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Execute.Sql("UPDATE Indexers SET ConfigContract = 'FanzubSettings' WHERE Implementation = 'Fanzub' AND ConfigContract = 'NullConfig'");
}
}
}

@ -1,22 +0,0 @@
using FluentMigrator;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(83)]
public class additonal_blacklist_columns : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Alter.Table("Blacklist").AddColumn("Size").AsInt64().Nullable();
Alter.Table("Blacklist").AddColumn("Protocol").AsInt32().Nullable();
Alter.Table("Blacklist").AddColumn("Indexer").AsString().Nullable();
Alter.Table("Blacklist").AddColumn("Message").AsString().Nullable();
Alter.Table("Blacklist").AddColumn("TorrentInfoHash").AsString().Nullable();
Update.Table("Blacklist")
.Set(new { Protocol = 1 })
.AllRows();
}
}
}

@ -1,26 +0,0 @@
using FluentMigrator;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(84)]
public class update_quality_minmax_size : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Alter.Table("QualityDefinitions").AlterColumn("MinSize").AsDouble().Nullable();
Alter.Table("QualityDefinitions").AlterColumn("MaxSize").AsDouble().Nullable();
Execute.Sql("UPDATE QualityDefinitions SET MaxSize = NULL WHERE Quality = 10 OR MaxSize = 0");
}
}
public class QualityDefinition84
{
public int Id { get; set; }
public int Quality { get; set; }
public string Title { get; set; }
public int? MinSize { get; set; }
public int? MaxSize { get; set; }
}
}

@ -1,75 +0,0 @@
using System.Collections.Generic;
using System.Data;
using FluentMigrator;
using NzbDrone.Common.Serializer;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
// this is here to resolve ambiguity in GetValueOrDefault extension method in net core 3
#pragma warning disable SA1200
using NzbDrone.Common.Extensions;
#pragma warning restore SA1200
[Migration(85)]
public class expand_transmission_urlbase : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Execute.WithConnection(UpdateTransmissionSettings);
}
private void UpdateTransmissionSettings(IDbConnection conn, IDbTransaction tran)
{
using (var cmd = conn.CreateCommand())
{
cmd.Transaction = tran;
cmd.CommandText = "SELECT Id, Settings FROM DownloadClients WHERE Implementation = 'Transmission'";
using (var reader = cmd.ExecuteReader())
{
while (reader.Read())
{
var id = reader.GetInt32(0);
var settingsJson = reader.GetString(1);
var settings = Json.Deserialize<Dictionary<string, object>>(settingsJson);
var urlBase = settings.GetValueOrDefault("urlBase", "") as string;
if (urlBase.IsNullOrWhiteSpace())
{
settings["urlBase"] = "/transmission/";
}
else
{
settings["urlBase"] = string.Format("/{0}/transmission/", urlBase.Trim('/'));
}
using (var updateCmd = conn.CreateCommand())
{
updateCmd.Transaction = tran;
updateCmd.CommandText = "UPDATE DownloadClients SET Settings = ? WHERE Id = ?";
updateCmd.AddParameter(settings.ToJson());
updateCmd.AddParameter(id);
updateCmd.ExecuteNonQuery();
}
}
}
}
}
}
public class DelugeSettings85
{
public string Host { get; set; }
public int Port { get; set; }
public string UrlBase { get; set; }
public string Password { get; set; }
public string TvCategory { get; set; }
public int RecentTvPriority { get; set; }
public int OlderTvPriority { get; set; }
public bool UseSsl { get; set; }
}
}

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save