mirror of
https://github.com/Radarr/Radarr.git
synced 2024-10-05 15:47:20 +02:00
New: Postgres Support
Co-Authored-By: Qstick <376117+Qstick@users.noreply.github.com>
This commit is contained in:
parent
df863a08a1
commit
80b1aa9a2c
@ -23,6 +23,8 @@ class About extends Component {
|
|||||||
isDocker,
|
isDocker,
|
||||||
runtimeVersion,
|
runtimeVersion,
|
||||||
migrationVersion,
|
migrationVersion,
|
||||||
|
databaseVersion,
|
||||||
|
databaseType,
|
||||||
appData,
|
appData,
|
||||||
startupPath,
|
startupPath,
|
||||||
mode,
|
mode,
|
||||||
@ -68,6 +70,11 @@ class About extends Component {
|
|||||||
data={migrationVersion}
|
data={migrationVersion}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<DescriptionListItem
|
||||||
|
title={translate('Database')}
|
||||||
|
data={`${titleCase(databaseType)} ${databaseVersion}`}
|
||||||
|
/>
|
||||||
|
|
||||||
<DescriptionListItem
|
<DescriptionListItem
|
||||||
title={translate('AppDataDirectory')}
|
title={translate('AppDataDirectory')}
|
||||||
data={appData}
|
data={appData}
|
||||||
@ -108,6 +115,8 @@ About.propTypes = {
|
|||||||
runtimeVersion: PropTypes.string.isRequired,
|
runtimeVersion: PropTypes.string.isRequired,
|
||||||
isDocker: PropTypes.bool.isRequired,
|
isDocker: PropTypes.bool.isRequired,
|
||||||
migrationVersion: PropTypes.number.isRequired,
|
migrationVersion: PropTypes.number.isRequired,
|
||||||
|
databaseType: PropTypes.string.isRequired,
|
||||||
|
databaseVersion: PropTypes.string.isRequired,
|
||||||
appData: PropTypes.string.isRequired,
|
appData: PropTypes.string.isRequired,
|
||||||
startupPath: PropTypes.string.isRequired,
|
startupPath: PropTypes.string.isRequired,
|
||||||
mode: PropTypes.string.isRequired,
|
mode: PropTypes.string.isRequired,
|
||||||
|
@ -63,6 +63,7 @@ public class CleanseLogMessageFixture
|
|||||||
[TestCase("Hardlink '/home/mySecret/Downloads/abs.mkv' to '/media/abc.mkv' failed.")]
|
[TestCase("Hardlink '/home/mySecret/Downloads/abs.mkv' to '/media/abc.mkv' failed.")]
|
||||||
[TestCase("https://notifiarr.com/notifier.php: api=1234530f-422f-4aac-b6b3-01233210aaaa&radarr_health_issue_message=Download")]
|
[TestCase("https://notifiarr.com/notifier.php: api=1234530f-422f-4aac-b6b3-01233210aaaa&radarr_health_issue_message=Download")]
|
||||||
[TestCase("/readarr/signalr/messages/negotiate?access_token=1234530f422f4aacb6b301233210aaaa&negotiateVersion=1")]
|
[TestCase("/readarr/signalr/messages/negotiate?access_token=1234530f422f4aacb6b301233210aaaa&negotiateVersion=1")]
|
||||||
|
[TestCase(@"[Info] MigrationController: *** Migrating Database=radarr-main;Host=postgres14;Username=mySecret;Password=mySecret;Port=5432;Enlist=False ***")]
|
||||||
|
|
||||||
// Announce URLs (passkeys) Magnet & Tracker
|
// Announce URLs (passkeys) Magnet & Tracker
|
||||||
[TestCase(@"magnet_uri"":""magnet:?xt=urn:btih:9pr04sgkillroyimaveql2tyu8xyui&dn=&tr=https%3a%2f%2fxxx.yyy%2f9pr04sg601233210imaveql2tyu8xyui%2fannounce""}")]
|
[TestCase(@"magnet_uri"":""magnet:?xt=urn:btih:9pr04sgkillroyimaveql2tyu8xyui&dn=&tr=https%3a%2f%2fxxx.yyy%2f9pr04sg601233210imaveql2tyu8xyui%2fannounce""}")]
|
||||||
|
@ -18,6 +18,7 @@ public class CleanseLogMessage
|
|||||||
new Regex(@"iptorrents\.com/[/a-z0-9?&;]*?(?:[?&;](u|tp)=(?<secret>[^&=;]+?))+(?= |;|&|$)", RegexOptions.Compiled | RegexOptions.IgnoreCase),
|
new Regex(@"iptorrents\.com/[/a-z0-9?&;]*?(?:[?&;](u|tp)=(?<secret>[^&=;]+?))+(?= |;|&|$)", RegexOptions.Compiled | RegexOptions.IgnoreCase),
|
||||||
new Regex(@"/fetch/[a-z0-9]{32}/(?<secret>[a-z0-9]{32})", RegexOptions.Compiled),
|
new Regex(@"/fetch/[a-z0-9]{32}/(?<secret>[a-z0-9]{32})", RegexOptions.Compiled),
|
||||||
new Regex(@"getnzb.*?(?<=\?|&)(r)=(?<secret>[^&=]+?)(?= |&|$)", RegexOptions.Compiled | RegexOptions.IgnoreCase),
|
new Regex(@"getnzb.*?(?<=\?|&)(r)=(?<secret>[^&=]+?)(?= |&|$)", RegexOptions.Compiled | RegexOptions.IgnoreCase),
|
||||||
|
new Regex(@"(?<=[?& ;])[^=]*?(_?(?<!use|get_)token|username|passwo?rd)=(?<secret>[^&=]+?)(?= |&|$|;)", RegexOptions.Compiled | RegexOptions.IgnoreCase),
|
||||||
|
|
||||||
// Trackers Announce Keys; Designed for Qbit Json; should work for all in theory
|
// Trackers Announce Keys; Designed for Qbit Json; should work for all in theory
|
||||||
new Regex(@"announce(\.php)?(/|%2f|%3fpasskey%3d)(?<secret>[a-z0-9]{16,})|(?<secret>[a-z0-9]{16,})(/|%2f)announce"),
|
new Regex(@"announce(\.php)?(/|%2f|%3fpasskey%3d)(?<secret>[a-z0-9]{16,})|(?<secret>[a-z0-9]{16,})(/|%2f)announce"),
|
||||||
|
@ -15,7 +15,7 @@ public class DatabaseFixture : DbTest
|
|||||||
public void SingleOrDefault_should_return_null_on_empty_db()
|
public void SingleOrDefault_should_return_null_on_empty_db()
|
||||||
{
|
{
|
||||||
Mocker.Resolve<IDatabase>()
|
Mocker.Resolve<IDatabase>()
|
||||||
.OpenConnection().Query<Movie>("SELECT * FROM Movies")
|
.OpenConnection().Query<Movie>("SELECT * FROM \"Movies\"")
|
||||||
.SingleOrDefault()
|
.SingleOrDefault()
|
||||||
.Should()
|
.Should()
|
||||||
.BeNull();
|
.BeNull();
|
||||||
|
@ -135,9 +135,9 @@ private void ShouldHaveAddedDefaultFormat(IDirectDataMapper db)
|
|||||||
|
|
||||||
private List<Profile147> QueryItems(IDirectDataMapper db)
|
private List<Profile147> QueryItems(IDirectDataMapper db)
|
||||||
{
|
{
|
||||||
var test = db.Query("SELECT * FROM Profiles");
|
var test = db.Query("SELECT * FROM \"Profiles\"");
|
||||||
|
|
||||||
var items = db.Query<Profile147>("SELECT FormatItems, FormatCutoff FROM Profiles");
|
var items = db.Query<Profile147>("SELECT \"FormatItems\", \"FormatCutoff\" FROM \"Profiles\"");
|
||||||
|
|
||||||
return items.Select(i =>
|
return items.Select(i =>
|
||||||
{
|
{
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
@ -77,7 +77,7 @@ public void should_correctly_convert_multiple_formats()
|
|||||||
|
|
||||||
private List<CustomFormatTest149> QueryItems(IDirectDataMapper db)
|
private List<CustomFormatTest149> QueryItems(IDirectDataMapper db)
|
||||||
{
|
{
|
||||||
var items = db.Query<CustomFormatTest149>("SELECT Name, FormatTags FROM CustomFormats");
|
var items = db.Query<CustomFormatTest149>("SELECT \"Name\", \"FormatTags\" FROM \"CustomFormats\"");
|
||||||
|
|
||||||
return items.Select(i =>
|
return items.Select(i =>
|
||||||
{
|
{
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
@ -40,7 +40,7 @@ public void should_correctly_convert_format_tag(string original, string converte
|
|||||||
|
|
||||||
private List<regex_required_tagsFixture.CustomFormatTest149> QueryItems(IDirectDataMapper db)
|
private List<regex_required_tagsFixture.CustomFormatTest149> QueryItems(IDirectDataMapper db)
|
||||||
{
|
{
|
||||||
var items = db.Query<regex_required_tagsFixture.CustomFormatTest149>("SELECT Name, FormatTags FROM CustomFormats");
|
var items = db.Query<regex_required_tagsFixture.CustomFormatTest149>("SELECT \"Name\", \"FormatTags\" FROM \"CustomFormats\"");
|
||||||
|
|
||||||
return items.Select(i =>
|
return items.Select(i =>
|
||||||
{
|
{
|
||||||
|
@ -32,8 +32,8 @@ private void AddDefaultProfile(add_language_to_files_history_blacklist m, string
|
|||||||
Monitored = true,
|
Monitored = true,
|
||||||
Title = "My Movie",
|
Title = "My Movie",
|
||||||
CleanTitle = "mytitle",
|
CleanTitle = "mytitle",
|
||||||
Status = MovieStatusType.Announced,
|
Status = (int)MovieStatusType.Announced,
|
||||||
MinimumAvailability = MovieStatusType.Announced,
|
MinimumAvailability = (int)MovieStatusType.Announced,
|
||||||
Images = new[] { new { CoverType = "Poster" } }.ToJson(),
|
Images = new[] { new { CoverType = "Poster" } }.ToJson(),
|
||||||
HasPreDBEntry = false,
|
HasPreDBEntry = false,
|
||||||
PathState = 1,
|
PathState = 1,
|
||||||
@ -112,7 +112,7 @@ public void should_add_languages_from_media_info_if_available()
|
|||||||
AddMovieFile(c, "My.Movie.2018.German.BluRay-Radarr", "Japanese");
|
AddMovieFile(c, "My.Movie.2018.German.BluRay-Radarr", "Japanese");
|
||||||
});
|
});
|
||||||
|
|
||||||
var items = db.Query<ModelWithLanguages154>("SELECT Id, Languages FROM MovieFiles");
|
var items = db.Query<ModelWithLanguages154>("SELECT \"Id\", \"Languages\" FROM \"MovieFiles\"");
|
||||||
|
|
||||||
items.Should().HaveCount(1);
|
items.Should().HaveCount(1);
|
||||||
items.First().Languages.Count.Should().Be(1);
|
items.First().Languages.Count.Should().Be(1);
|
||||||
@ -130,7 +130,7 @@ public void should_add_languages_from_media_info_with_multiple_language()
|
|||||||
AddMovieFile(c, "My.Movie.2018.German.BluRay-Radarr", "Japanese / French");
|
AddMovieFile(c, "My.Movie.2018.German.BluRay-Radarr", "Japanese / French");
|
||||||
});
|
});
|
||||||
|
|
||||||
var items = db.Query<ModelWithLanguages154>("SELECT Id, Languages FROM MovieFiles");
|
var items = db.Query<ModelWithLanguages154>("SELECT \"Id\", \"Languages\" FROM \"MovieFiles\"");
|
||||||
|
|
||||||
items.Should().HaveCount(1);
|
items.Should().HaveCount(1);
|
||||||
items.First().Languages.Count.Should().Be(2);
|
items.First().Languages.Count.Should().Be(2);
|
||||||
@ -149,7 +149,7 @@ public void should_fallback_to_scenename_if_no_mediainfo_languages()
|
|||||||
AddMovieFile(c, "My.Movie.2018.German.BluRay-Radarr", "");
|
AddMovieFile(c, "My.Movie.2018.German.BluRay-Radarr", "");
|
||||||
});
|
});
|
||||||
|
|
||||||
var items = db.Query<ModelWithLanguages154>("SELECT Id, Languages FROM MovieFiles");
|
var items = db.Query<ModelWithLanguages154>("SELECT \"Id\", \"Languages\" FROM \"MovieFiles\"");
|
||||||
|
|
||||||
items.Should().HaveCount(1);
|
items.Should().HaveCount(1);
|
||||||
items.First().Languages.Count.Should().Be(1);
|
items.First().Languages.Count.Should().Be(1);
|
||||||
@ -166,7 +166,7 @@ public void should_fallback_to_scenename_if_mediainfo_language_invalid()
|
|||||||
AddMovieFile(c, "My.Movie.2018.German.BluRay-Radarr", "English (USA)");
|
AddMovieFile(c, "My.Movie.2018.German.BluRay-Radarr", "English (USA)");
|
||||||
});
|
});
|
||||||
|
|
||||||
var items = db.Query<ModelWithLanguages154>("SELECT Id, Languages FROM MovieFiles");
|
var items = db.Query<ModelWithLanguages154>("SELECT \"Id\", \"Languages\" FROM \"MovieFiles\"");
|
||||||
|
|
||||||
items.Should().HaveCount(1);
|
items.Should().HaveCount(1);
|
||||||
items.First().Languages.Count.Should().Be(1);
|
items.First().Languages.Count.Should().Be(1);
|
||||||
@ -184,7 +184,7 @@ public void should_fallback_to_profile_if_no_mediainfo_no_scene_name()
|
|||||||
AddMovieFile(c, "", "");
|
AddMovieFile(c, "", "");
|
||||||
});
|
});
|
||||||
|
|
||||||
var items = db.Query<ModelWithLanguages154>("SELECT Id, Languages FROM MovieFiles");
|
var items = db.Query<ModelWithLanguages154>("SELECT \"Id\", \"Languages\" FROM \"MovieFiles\"");
|
||||||
|
|
||||||
items.Should().HaveCount(1);
|
items.Should().HaveCount(1);
|
||||||
items.First().Languages.Count.Should().Be(1);
|
items.First().Languages.Count.Should().Be(1);
|
||||||
@ -201,7 +201,7 @@ public void should_handle_if_null_mediainfo_and_null_scenename()
|
|||||||
AddMovieFile(c, null, null);
|
AddMovieFile(c, null, null);
|
||||||
});
|
});
|
||||||
|
|
||||||
var items = db.Query<ModelWithLanguages154>("SELECT Id, Languages FROM MovieFiles");
|
var items = db.Query<ModelWithLanguages154>("SELECT \"Id\", \"Languages\" FROM \"MovieFiles\"");
|
||||||
|
|
||||||
items.Should().HaveCount(1);
|
items.Should().HaveCount(1);
|
||||||
items.First().Languages.Count.Should().Be(1);
|
items.First().Languages.Count.Should().Be(1);
|
||||||
@ -218,7 +218,7 @@ public void should_fallback_to_profile_if_unknown_language_from_scene_name()
|
|||||||
AddMovieFile(c, "My.Movie.2018.BluRay-Radarr", "");
|
AddMovieFile(c, "My.Movie.2018.BluRay-Radarr", "");
|
||||||
});
|
});
|
||||||
|
|
||||||
var items = db.Query<ModelWithLanguages154>("SELECT Id, Languages FROM MovieFiles");
|
var items = db.Query<ModelWithLanguages154>("SELECT \"Id\", \"Languages\" FROM \"MovieFiles\"");
|
||||||
|
|
||||||
items.Should().HaveCount(1);
|
items.Should().HaveCount(1);
|
||||||
items.First().Languages.Count.Should().Be(1);
|
items.First().Languages.Count.Should().Be(1);
|
||||||
@ -235,7 +235,7 @@ public void should_use_english_if_fallback_to_profile_and_profile_is_any()
|
|||||||
AddMovieFile(c, "", "");
|
AddMovieFile(c, "", "");
|
||||||
});
|
});
|
||||||
|
|
||||||
var items = db.Query<ModelWithLanguages154>("SELECT Id, Languages FROM MovieFiles");
|
var items = db.Query<ModelWithLanguages154>("SELECT \"Id\", \"Languages\" FROM \"MovieFiles\"");
|
||||||
|
|
||||||
items.Should().HaveCount(1);
|
items.Should().HaveCount(1);
|
||||||
items.First().Languages.Count.Should().Be(1);
|
items.First().Languages.Count.Should().Be(1);
|
||||||
@ -253,7 +253,7 @@ public void should_assign_history_languages_from_sourceTitle()
|
|||||||
AddHistory(c, "My.Movie.2018.Italian.BluRay-Radarr");
|
AddHistory(c, "My.Movie.2018.Italian.BluRay-Radarr");
|
||||||
});
|
});
|
||||||
|
|
||||||
var items = db.Query<ModelWithLanguages154>("SELECT Id, Languages FROM History");
|
var items = db.Query<ModelWithLanguages154>("SELECT \"Id\", \"Languages\" FROM \"History\"");
|
||||||
|
|
||||||
items.Should().HaveCount(1);
|
items.Should().HaveCount(1);
|
||||||
items.First().Languages.Count.Should().Be(1);
|
items.First().Languages.Count.Should().Be(1);
|
||||||
@ -270,7 +270,7 @@ public void should_assign_history_languages_from_profile_if_no_sourceTitle()
|
|||||||
AddHistory(c, "");
|
AddHistory(c, "");
|
||||||
});
|
});
|
||||||
|
|
||||||
var items = db.Query<ModelWithLanguages154>("SELECT Id, Languages FROM History");
|
var items = db.Query<ModelWithLanguages154>("SELECT \"Id\", \"Languages\" FROM \"History\"");
|
||||||
|
|
||||||
items.Should().HaveCount(1);
|
items.Should().HaveCount(1);
|
||||||
items.First().Languages.Count.Should().Be(1);
|
items.First().Languages.Count.Should().Be(1);
|
||||||
@ -287,7 +287,7 @@ public void should_assign_history_languages_from_profile_if_unknown_sourceTitle(
|
|||||||
AddHistory(c, "Man on Fire");
|
AddHistory(c, "Man on Fire");
|
||||||
});
|
});
|
||||||
|
|
||||||
var items = db.Query<ModelWithLanguages154>("SELECT Id, Languages FROM History");
|
var items = db.Query<ModelWithLanguages154>("SELECT \"Id\", \"Languages\" FROM \"History\"");
|
||||||
|
|
||||||
items.Should().HaveCount(1);
|
items.Should().HaveCount(1);
|
||||||
items.First().Languages.Count.Should().Be(1);
|
items.First().Languages.Count.Should().Be(1);
|
||||||
@ -305,7 +305,7 @@ public void should_assign_history_languages_from_moviefile_release_mapping_with_
|
|||||||
AddHistory(c, "My.Movie.2018.Italian.BluRay-Radarr");
|
AddHistory(c, "My.Movie.2018.Italian.BluRay-Radarr");
|
||||||
});
|
});
|
||||||
|
|
||||||
var items = db.Query<ModelWithLanguages154>("SELECT Id, Languages FROM History");
|
var items = db.Query<ModelWithLanguages154>("SELECT \"Id\", \"Languages\" FROM \"History\"");
|
||||||
|
|
||||||
items.Should().HaveCount(1);
|
items.Should().HaveCount(1);
|
||||||
items.First().Languages.Count.Should().Be(3);
|
items.First().Languages.Count.Should().Be(3);
|
||||||
@ -324,7 +324,7 @@ public void should_assign_blacklist_languages_from_sourceTitle()
|
|||||||
AddBlacklist(c, "My.Movie.2018.Italian.BluRay-Radarr");
|
AddBlacklist(c, "My.Movie.2018.Italian.BluRay-Radarr");
|
||||||
});
|
});
|
||||||
|
|
||||||
var items = db.Query<ModelWithLanguages154>("SELECT Id, Languages FROM Blacklist");
|
var items = db.Query<ModelWithLanguages154>("SELECT \"Id\", \"Languages\" FROM \"Blacklist\"");
|
||||||
|
|
||||||
items.Should().HaveCount(1);
|
items.Should().HaveCount(1);
|
||||||
items.First().Languages.Count.Should().Be(1);
|
items.First().Languages.Count.Should().Be(1);
|
||||||
@ -341,7 +341,7 @@ public void should_assign_blacklist_languages_from_profile_if_no_sourceTitle()
|
|||||||
AddBlacklist(c, "");
|
AddBlacklist(c, "");
|
||||||
});
|
});
|
||||||
|
|
||||||
var items = db.Query<ModelWithLanguages154>("SELECT Id, Languages FROM Blacklist");
|
var items = db.Query<ModelWithLanguages154>("SELECT \"Id\", \"Languages\" FROM \"Blacklist\"");
|
||||||
|
|
||||||
items.Should().HaveCount(1);
|
items.Should().HaveCount(1);
|
||||||
items.First().Languages.Count.Should().Be(1);
|
items.First().Languages.Count.Should().Be(1);
|
||||||
@ -358,7 +358,7 @@ public void should_assign_blacklist_languages_from_profile_if_unknown_sourceTitl
|
|||||||
AddBlacklist(c, "Man on Fire");
|
AddBlacklist(c, "Man on Fire");
|
||||||
});
|
});
|
||||||
|
|
||||||
var items = db.Query<ModelWithLanguages154>("SELECT Id, Languages FROM Blacklist");
|
var items = db.Query<ModelWithLanguages154>("SELECT \"Id\", \"Languages\" FROM \"Blacklist\"");
|
||||||
|
|
||||||
items.Should().HaveCount(1);
|
items.Should().HaveCount(1);
|
||||||
items.First().Languages.Count.Should().Be(1);
|
items.First().Languages.Count.Should().Be(1);
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
@ -18,7 +18,7 @@ public void should_set_prio_to_one()
|
|||||||
{
|
{
|
||||||
c.Insert.IntoTable("DownloadClients").Row(new
|
c.Insert.IntoTable("DownloadClients").Row(new
|
||||||
{
|
{
|
||||||
Enable = 1,
|
Enable = true,
|
||||||
Name = "Deluge",
|
Name = "Deluge",
|
||||||
Implementation = "Deluge",
|
Implementation = "Deluge",
|
||||||
Settings = new DelugeSettings156
|
Settings = new DelugeSettings156
|
||||||
@ -31,7 +31,7 @@ public void should_set_prio_to_one()
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
var items = db.Query<DownloadClientDefinition132>("SELECT * FROM DownloadClients");
|
var items = db.Query<DownloadClientDefinition132>("SELECT * FROM \"DownloadClients\"");
|
||||||
|
|
||||||
items.Should().HaveCount(1);
|
items.Should().HaveCount(1);
|
||||||
items.First().Priority.Should().Be(1);
|
items.First().Priority.Should().Be(1);
|
||||||
@ -44,7 +44,7 @@ public void should_renumber_prio_for_enabled_clients()
|
|||||||
{
|
{
|
||||||
c.Insert.IntoTable("DownloadClients").Row(new
|
c.Insert.IntoTable("DownloadClients").Row(new
|
||||||
{
|
{
|
||||||
Enable = 1,
|
Enable = true,
|
||||||
Name = "Deluge",
|
Name = "Deluge",
|
||||||
Implementation = "Deluge",
|
Implementation = "Deluge",
|
||||||
Settings = new DelugeSettings156
|
Settings = new DelugeSettings156
|
||||||
@ -56,7 +56,7 @@ public void should_renumber_prio_for_enabled_clients()
|
|||||||
ConfigContract = "DelugeSettings"
|
ConfigContract = "DelugeSettings"
|
||||||
}).Row(new
|
}).Row(new
|
||||||
{
|
{
|
||||||
Enable = 1,
|
Enable = true,
|
||||||
Name = "Deluge2",
|
Name = "Deluge2",
|
||||||
Implementation = "Deluge",
|
Implementation = "Deluge",
|
||||||
Settings = new DelugeSettings156
|
Settings = new DelugeSettings156
|
||||||
@ -68,7 +68,7 @@ public void should_renumber_prio_for_enabled_clients()
|
|||||||
ConfigContract = "DelugeSettings"
|
ConfigContract = "DelugeSettings"
|
||||||
}).Row(new
|
}).Row(new
|
||||||
{
|
{
|
||||||
Enable = 1,
|
Enable = true,
|
||||||
Name = "sab",
|
Name = "sab",
|
||||||
Implementation = "Sabnzbd",
|
Implementation = "Sabnzbd",
|
||||||
Settings = new SabnzbdSettings156
|
Settings = new SabnzbdSettings156
|
||||||
@ -80,7 +80,7 @@ public void should_renumber_prio_for_enabled_clients()
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
var items = db.Query<DownloadClientDefinition132>("SELECT * FROM DownloadClients");
|
var items = db.Query<DownloadClientDefinition132>("SELECT * FROM \"DownloadClients\"");
|
||||||
|
|
||||||
items.Should().HaveCount(3);
|
items.Should().HaveCount(3);
|
||||||
items[0].Priority.Should().Be(1);
|
items[0].Priority.Should().Be(1);
|
||||||
@ -95,7 +95,7 @@ public void should_not_renumber_prio_for_disabled_clients()
|
|||||||
{
|
{
|
||||||
c.Insert.IntoTable("DownloadClients").Row(new
|
c.Insert.IntoTable("DownloadClients").Row(new
|
||||||
{
|
{
|
||||||
Enable = 0,
|
Enable = false,
|
||||||
Name = "Deluge",
|
Name = "Deluge",
|
||||||
Implementation = "Deluge",
|
Implementation = "Deluge",
|
||||||
Settings = new DelugeSettings156
|
Settings = new DelugeSettings156
|
||||||
@ -107,7 +107,7 @@ public void should_not_renumber_prio_for_disabled_clients()
|
|||||||
ConfigContract = "DelugeSettings"
|
ConfigContract = "DelugeSettings"
|
||||||
}).Row(new
|
}).Row(new
|
||||||
{
|
{
|
||||||
Enable = 0,
|
Enable = false,
|
||||||
Name = "Deluge2",
|
Name = "Deluge2",
|
||||||
Implementation = "Deluge",
|
Implementation = "Deluge",
|
||||||
Settings = new DelugeSettings156
|
Settings = new DelugeSettings156
|
||||||
@ -119,7 +119,7 @@ public void should_not_renumber_prio_for_disabled_clients()
|
|||||||
ConfigContract = "DelugeSettings"
|
ConfigContract = "DelugeSettings"
|
||||||
}).Row(new
|
}).Row(new
|
||||||
{
|
{
|
||||||
Enable = 0,
|
Enable = false,
|
||||||
Name = "sab",
|
Name = "sab",
|
||||||
Implementation = "Sabnzbd",
|
Implementation = "Sabnzbd",
|
||||||
Settings = new SabnzbdSettings156
|
Settings = new SabnzbdSettings156
|
||||||
@ -131,7 +131,7 @@ public void should_not_renumber_prio_for_disabled_clients()
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
var items = db.Query<DownloadClientDefinition132>("SELECT * FROM DownloadClients");
|
var items = db.Query<DownloadClientDefinition132>("SELECT * FROM \"DownloadClients\"");
|
||||||
|
|
||||||
items.Should().HaveCount(3);
|
items.Should().HaveCount(3);
|
||||||
items[0].Priority.Should().Be(1);
|
items[0].Priority.Should().Be(1);
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using NzbDrone.Core.Datastore.Migration;
|
using NzbDrone.Core.Datastore.Migration;
|
||||||
@ -34,7 +34,7 @@ public void should_add_webrip_qualities_and_group_with_webdl()
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
var profiles = db.Query<Profile159>("SELECT Items FROM Profiles LIMIT 1");
|
var profiles = db.Query<Profile159>("SELECT \"Items\" FROM \"Profiles\" LIMIT 1");
|
||||||
|
|
||||||
var items = profiles.First().Items;
|
var items = profiles.First().Items;
|
||||||
items.Should().HaveCount(5);
|
items.Should().HaveCount(5);
|
||||||
@ -57,7 +57,7 @@ public void should_add_webrip_and_webdl_if_webdl_is_missing()
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
var profiles = db.Query<Profile159>("SELECT Items FROM Profiles LIMIT 1");
|
var profiles = db.Query<Profile159>("SELECT \"Items\" FROM \"Profiles\" LIMIT 1");
|
||||||
|
|
||||||
var items = profiles.First().Items;
|
var items = profiles.First().Items;
|
||||||
items.Should().HaveCount(5);
|
items.Should().HaveCount(5);
|
||||||
@ -80,7 +80,7 @@ public void should_add_webrip_beside_webdl_is_grouped()
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
var profiles = db.Query<Profile159>("SELECT Items FROM Profiles LIMIT 1");
|
var profiles = db.Query<Profile159>("SELECT \"Items\" FROM \"Profiles\" LIMIT 1");
|
||||||
|
|
||||||
var items = profiles.First().Items;
|
var items = profiles.First().Items;
|
||||||
items.Count(c => c.Id == 1001).Should().Be(1);
|
items.Count(c => c.Id == 1001).Should().Be(1);
|
||||||
@ -104,7 +104,7 @@ public void should_group_webrip_and_webdl_with_the_same_resolution()
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
var profiles = db.Query<Profile159>("SELECT Items FROM Profiles LIMIT 1");
|
var profiles = db.Query<Profile159>("SELECT \"Items\" FROM \"Profiles\" LIMIT 1");
|
||||||
var items = profiles.First().Items;
|
var items = profiles.First().Items;
|
||||||
|
|
||||||
items[1].Items.First().Quality.Should().Be((int)Quality.WEBRip480p);
|
items[1].Items.First().Quality.Should().Be((int)Quality.WEBRip480p);
|
||||||
|
@ -81,14 +81,14 @@ public void should_remove_custom_format_from_pending_releases()
|
|||||||
""imdbId"": """"
|
""imdbId"": """"
|
||||||
}",
|
}",
|
||||||
Release = "{}",
|
Release = "{}",
|
||||||
Reason = PendingReleaseReason.Delay
|
Reason = (int)PendingReleaseReason.Delay
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
var json = db.Query<string>("SELECT ParsedMovieInfo FROM PendingReleases").First();
|
var json = db.Query<string>("SELECT \"ParsedMovieInfo\" FROM \"PendingReleases\"").First();
|
||||||
json.Should().NotContain("customFormats");
|
json.Should().NotContain("customFormats");
|
||||||
|
|
||||||
var pending = db.Query<ParsedMovieInfo>("SELECT ParsedMovieInfo FROM PendingReleases").First();
|
var pending = db.Query<ParsedMovieInfo>("SELECT \"ParsedMovieInfo\" FROM \"PendingReleases\"").First();
|
||||||
pending.Quality.Quality.Should().Be(Quality.Bluray1080p);
|
pending.Quality.Quality.Should().Be(Quality.Bluray1080p);
|
||||||
pending.Languages.Should().BeEmpty();
|
pending.Languages.Should().BeEmpty();
|
||||||
}
|
}
|
||||||
@ -129,15 +129,15 @@ public void should_fix_quality_for_pending_releases()
|
|||||||
""imdbId"": """"
|
""imdbId"": """"
|
||||||
}",
|
}",
|
||||||
Release = "{}",
|
Release = "{}",
|
||||||
Reason = PendingReleaseReason.Delay
|
Reason = (int)PendingReleaseReason.Delay
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
var json = db.Query<string>("SELECT ParsedMovieInfo FROM PendingReleases").First();
|
var json = db.Query<string>("SELECT \"ParsedMovieInfo\" FROM \"PendingReleases\"").First();
|
||||||
json.Should().NotContain("customFormats");
|
json.Should().NotContain("customFormats");
|
||||||
json.Should().NotContain("resolution");
|
json.Should().NotContain("resolution");
|
||||||
|
|
||||||
var pending = db.Query<ParsedMovieInfo>("SELECT ParsedMovieInfo FROM PendingReleases").First();
|
var pending = db.Query<ParsedMovieInfo>("SELECT \"ParsedMovieInfo\" FROM \"PendingReleases\"").First();
|
||||||
pending.Quality.Quality.Should().Be(Quality.Bluray1080p);
|
pending.Quality.Quality.Should().Be(Quality.Bluray1080p);
|
||||||
pending.Languages.Should().BeEquivalentTo(new List<Language> { Language.English });
|
pending.Languages.Should().BeEquivalentTo(new List<Language> { Language.English });
|
||||||
}
|
}
|
||||||
|
@ -80,7 +80,7 @@ public void should_convert_custom_format_row_with_one_spec()
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
var json = db.Query<string>("SELECT Specifications FROM CustomFormats").First();
|
var json = db.Query<string>("SELECT \"Specifications\" FROM \"CustomFormats\"").First();
|
||||||
|
|
||||||
ValidateFormatTag(json, "ReleaseTitleSpecification", false, false);
|
ValidateFormatTag(json, "ReleaseTitleSpecification", false, false);
|
||||||
json.Should().Contain($"\"name\": \"Test\"");
|
json.Should().Contain($"\"name\": \"Test\"");
|
||||||
@ -99,7 +99,7 @@ public void should_convert_custom_format_row_with_two_specs()
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
var json = db.Query<string>("SELECT Specifications FROM CustomFormats").First();
|
var json = db.Query<string>("SELECT \"Specifications\" FROM \"CustomFormats\"").First();
|
||||||
|
|
||||||
ValidateFormatTag(json, "ReleaseTitleSpecification", false, false);
|
ValidateFormatTag(json, "ReleaseTitleSpecification", false, false);
|
||||||
ValidateFormatTag(json, "EditionSpecification", false, false);
|
ValidateFormatTag(json, "EditionSpecification", false, false);
|
||||||
|
@ -19,12 +19,12 @@ public void should_change_implementation_contract_on_radarr_lists()
|
|||||||
{
|
{
|
||||||
c.Insert.IntoTable("NetImport").Row(new
|
c.Insert.IntoTable("NetImport").Row(new
|
||||||
{
|
{
|
||||||
Enabled = 1,
|
Enabled = true,
|
||||||
EnableAuto = 1,
|
EnableAuto = true,
|
||||||
RootFolderPath = "D:\\Movies",
|
RootFolderPath = "D:\\Movies",
|
||||||
ProfileId = 1,
|
ProfileId = 1,
|
||||||
MinimumAvailability = 1,
|
MinimumAvailability = 1,
|
||||||
ShouldMonitor = 1,
|
ShouldMonitor = true,
|
||||||
Name = "IMDB List",
|
Name = "IMDB List",
|
||||||
Implementation = "RadarrLists",
|
Implementation = "RadarrLists",
|
||||||
Settings = new RadarrListSettings169
|
Settings = new RadarrListSettings169
|
||||||
@ -36,7 +36,7 @@ public void should_change_implementation_contract_on_radarr_lists()
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
var items = db.Query<ListDefinition169>("SELECT * FROM NetImport");
|
var items = db.Query<ListDefinition169>("SELECT * FROM \"NetImport\"");
|
||||||
|
|
||||||
items.Should().HaveCount(1);
|
items.Should().HaveCount(1);
|
||||||
items.First().Implementation.Should().Be("RadarrListImport");
|
items.First().Implementation.Should().Be("RadarrListImport");
|
||||||
@ -52,12 +52,12 @@ public void should_change_implementation_contract_type_on_trakt_user()
|
|||||||
{
|
{
|
||||||
c.Insert.IntoTable("NetImport").Row(new
|
c.Insert.IntoTable("NetImport").Row(new
|
||||||
{
|
{
|
||||||
Enabled = 1,
|
Enabled = true,
|
||||||
EnableAuto = 1,
|
EnableAuto = true,
|
||||||
RootFolderPath = "D:\\Movies",
|
RootFolderPath = "D:\\Movies",
|
||||||
ProfileId = 1,
|
ProfileId = 1,
|
||||||
MinimumAvailability = 1,
|
MinimumAvailability = 1,
|
||||||
ShouldMonitor = 1,
|
ShouldMonitor = true,
|
||||||
Name = "TraktImport",
|
Name = "TraktImport",
|
||||||
Implementation = "TraktImport",
|
Implementation = "TraktImport",
|
||||||
Settings = new TraktSettings169
|
Settings = new TraktSettings169
|
||||||
@ -72,7 +72,7 @@ public void should_change_implementation_contract_type_on_trakt_user()
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
var items = db.Query<ListDefinition169>("SELECT * FROM NetImport");
|
var items = db.Query<ListDefinition169>("SELECT * FROM \"NetImport\"");
|
||||||
|
|
||||||
items.Should().HaveCount(1);
|
items.Should().HaveCount(1);
|
||||||
items.First().Implementation.Should().Be("TraktUserImport");
|
items.First().Implementation.Should().Be("TraktUserImport");
|
||||||
@ -90,12 +90,12 @@ public void should_change_implementation_contract_type_on_trakt_popular()
|
|||||||
{
|
{
|
||||||
c.Insert.IntoTable("NetImport").Row(new
|
c.Insert.IntoTable("NetImport").Row(new
|
||||||
{
|
{
|
||||||
Enabled = 1,
|
Enabled = true,
|
||||||
EnableAuto = 1,
|
EnableAuto = true,
|
||||||
RootFolderPath = "D:\\Movies",
|
RootFolderPath = "D:\\Movies",
|
||||||
ProfileId = 1,
|
ProfileId = 1,
|
||||||
MinimumAvailability = 1,
|
MinimumAvailability = 1,
|
||||||
ShouldMonitor = 1,
|
ShouldMonitor = true,
|
||||||
Name = "TraktImport",
|
Name = "TraktImport",
|
||||||
Implementation = "TraktImport",
|
Implementation = "TraktImport",
|
||||||
Settings = new TraktSettings169
|
Settings = new TraktSettings169
|
||||||
@ -110,7 +110,7 @@ public void should_change_implementation_contract_type_on_trakt_popular()
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
var items = db.Query<ListDefinition169>("SELECT * FROM NetImport");
|
var items = db.Query<ListDefinition169>("SELECT * FROM \"NetImport\"");
|
||||||
|
|
||||||
items.Should().HaveCount(1);
|
items.Should().HaveCount(1);
|
||||||
items.First().Implementation.Should().Be("TraktPopularImport");
|
items.First().Implementation.Should().Be("TraktPopularImport");
|
||||||
@ -128,12 +128,12 @@ public void should_change_implementation_contract_type_on_trakt_list()
|
|||||||
{
|
{
|
||||||
c.Insert.IntoTable("NetImport").Row(new
|
c.Insert.IntoTable("NetImport").Row(new
|
||||||
{
|
{
|
||||||
Enabled = 1,
|
Enabled = true,
|
||||||
EnableAuto = 1,
|
EnableAuto = true,
|
||||||
RootFolderPath = "D:\\Movies",
|
RootFolderPath = "D:\\Movies",
|
||||||
ProfileId = 1,
|
ProfileId = 1,
|
||||||
MinimumAvailability = 1,
|
MinimumAvailability = 1,
|
||||||
ShouldMonitor = 1,
|
ShouldMonitor = true,
|
||||||
Name = "TraktImport",
|
Name = "TraktImport",
|
||||||
Implementation = "TraktImport",
|
Implementation = "TraktImport",
|
||||||
Settings = new TraktSettings169
|
Settings = new TraktSettings169
|
||||||
@ -149,7 +149,7 @@ public void should_change_implementation_contract_type_on_trakt_list()
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
var items = db.Query<ListDefinition169>("SELECT * FROM NetImport");
|
var items = db.Query<ListDefinition169>("SELECT * FROM \"NetImport\"");
|
||||||
|
|
||||||
items.Should().HaveCount(1);
|
items.Should().HaveCount(1);
|
||||||
items.First().Implementation.Should().Be("TraktListImport");
|
items.First().Implementation.Should().Be("TraktListImport");
|
||||||
|
@ -37,7 +37,7 @@ public void should_convert_to_list_on_email_lists()
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
var items = db.Query<ProviderDefinition166>("SELECT * FROM Notifications");
|
var items = db.Query<ProviderDefinition166>("SELECT * FROM \"Notifications\"");
|
||||||
|
|
||||||
items.Should().HaveCount(1);
|
items.Should().HaveCount(1);
|
||||||
items.First().Implementation.Should().Be("Email");
|
items.First().Implementation.Should().Be("Email");
|
||||||
|
@ -96,7 +96,7 @@ public void should_switch_some_radarr_to_imdb(string url)
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
var items = db.Query<new_list_server.NetImportDefinition178>("SELECT * FROM NetImport");
|
var items = db.Query<new_list_server.NetImportDefinition178>("SELECT * FROM \"NetImport\"");
|
||||||
|
|
||||||
items.Should().HaveCount(7);
|
items.Should().HaveCount(7);
|
||||||
|
|
||||||
@ -157,7 +157,7 @@ public void should_switch_some_stevenlu_stevenlu2()
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
var items = db.Query<new_list_server.NetImportDefinition178>("SELECT * FROM NetImport");
|
var items = db.Query<new_list_server.NetImportDefinition178>("SELECT * FROM \"NetImport\"");
|
||||||
|
|
||||||
items.Should().HaveCount(5);
|
items.Should().HaveCount(5);
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ private void AddDefaultProfile(fix_invalid_profile_references m, string name, in
|
|||||||
Items = items.ToJson(),
|
Items = items.ToJson(),
|
||||||
Language = (int)Language.English,
|
Language = (int)Language.English,
|
||||||
MinFormatScore = 0,
|
MinFormatScore = 0,
|
||||||
CutOffFormatScore = 0
|
CutoffFormatScore = 0
|
||||||
};
|
};
|
||||||
|
|
||||||
m.Insert.IntoTable("Profiles").Row(profile);
|
m.Insert.IntoTable("Profiles").Row(profile);
|
||||||
@ -50,8 +50,8 @@ private void AddMovie(fix_invalid_profile_references m, string movieTitle, int t
|
|||||||
Monitored = true,
|
Monitored = true,
|
||||||
Title = movieTitle,
|
Title = movieTitle,
|
||||||
CleanTitle = movieTitle,
|
CleanTitle = movieTitle,
|
||||||
Status = MovieStatusType.Announced,
|
Status = (int)MovieStatusType.Announced,
|
||||||
MinimumAvailability = MovieStatusType.Announced,
|
MinimumAvailability = (int)MovieStatusType.Announced,
|
||||||
Images = new[] { new { CoverType = "Poster" } }.ToJson(),
|
Images = new[] { new { CoverType = "Poster" } }.ToJson(),
|
||||||
Recommendations = new[] { 1 }.ToJson(),
|
Recommendations = new[] { 1 }.ToJson(),
|
||||||
HasPreDBEntry = false,
|
HasPreDBEntry = false,
|
||||||
@ -89,8 +89,8 @@ public void should_add_default_profiles_if_none_exist_but_movies_exist()
|
|||||||
AddMovie(c, "movie", 123456, profileId);
|
AddMovie(c, "movie", 123456, profileId);
|
||||||
});
|
});
|
||||||
|
|
||||||
var items = db.Query<Movie179>("SELECT Id, ProfileId FROM Movies");
|
var items = db.Query<Movie179>("SELECT \"Id\", \"ProfileId\" FROM \"Movies\"");
|
||||||
var profiles = db.Query<Profile179>("SELECT Id FROM Profiles");
|
var profiles = db.Query<Profile179>("SELECT \"Id\" FROM \"Profiles\"");
|
||||||
|
|
||||||
items.Should().HaveCount(1);
|
items.Should().HaveCount(1);
|
||||||
profiles.Should().HaveCount(6);
|
profiles.Should().HaveCount(6);
|
||||||
@ -108,8 +108,8 @@ public void should_not_add_default_profiles_if_one_exist()
|
|||||||
AddMovie(c, "movie", 123456, 17);
|
AddMovie(c, "movie", 123456, 17);
|
||||||
});
|
});
|
||||||
|
|
||||||
var items = db.Query<Movie179>("SELECT Id, ProfileId FROM Movies");
|
var items = db.Query<Movie179>("SELECT \"Id\", \"ProfileId\" FROM \"Movies\"");
|
||||||
var profiles = db.Query<Profile179>("SELECT Id FROM Profiles");
|
var profiles = db.Query<Profile179>("SELECT \"Id\" FROM \"Profiles\"");
|
||||||
|
|
||||||
items.Should().HaveCount(1);
|
items.Should().HaveCount(1);
|
||||||
profiles.Should().HaveCount(1);
|
profiles.Should().HaveCount(1);
|
||||||
@ -128,8 +128,8 @@ public void should_add_custom_formats_to_default_profiles_if_some_exist()
|
|||||||
AddMovie(c, "movie", 123456, profileId);
|
AddMovie(c, "movie", 123456, profileId);
|
||||||
});
|
});
|
||||||
|
|
||||||
var items = db.Query<Movie179>("SELECT Id, ProfileId FROM Movies");
|
var items = db.Query<Movie179>("SELECT \"Id\", \"ProfileId\" FROM \"Movies\"");
|
||||||
var profiles = db.Query<Profile179>("SELECT Id, FormatItems FROM Profiles");
|
var profiles = db.Query<Profile179>("SELECT \"Id\", \"FormatItems\" FROM \"Profiles\"");
|
||||||
|
|
||||||
items.Should().HaveCount(1);
|
items.Should().HaveCount(1);
|
||||||
profiles.Should().HaveCount(6);
|
profiles.Should().HaveCount(6);
|
||||||
@ -149,7 +149,7 @@ public void should_not_change_movies_with_valid_profile()
|
|||||||
AddMovie(c, "movie", 123456, profileId);
|
AddMovie(c, "movie", 123456, profileId);
|
||||||
});
|
});
|
||||||
|
|
||||||
var items = db.Query<Movie179>("SELECT Id, ProfileId FROM Movies");
|
var items = db.Query<Movie179>("SELECT \"Id\", \"ProfileId\" FROM \"Movies\"");
|
||||||
|
|
||||||
items.Should().HaveCount(1);
|
items.Should().HaveCount(1);
|
||||||
items.First().ProfileId.Should().Be(profileId);
|
items.First().ProfileId.Should().Be(profileId);
|
||||||
@ -166,7 +166,7 @@ public void should_change_movies_with_bad_profile_id()
|
|||||||
AddMovie(c, "movie", 123456, 1);
|
AddMovie(c, "movie", 123456, 1);
|
||||||
});
|
});
|
||||||
|
|
||||||
var items = db.Query<Movie179>("SELECT Id, ProfileId FROM Movies");
|
var items = db.Query<Movie179>("SELECT \"Id\", \"ProfileId\" FROM \"Movies\"");
|
||||||
|
|
||||||
items.Should().HaveCount(1);
|
items.Should().HaveCount(1);
|
||||||
items.First().ProfileId.Should().Be(profileId);
|
items.First().ProfileId.Should().Be(profileId);
|
||||||
@ -193,7 +193,7 @@ public void should_change_to_most_common_valid_profile_in_library()
|
|||||||
AddMovie(c, "movie9", 123459, otherProfileId);
|
AddMovie(c, "movie9", 123459, otherProfileId);
|
||||||
});
|
});
|
||||||
|
|
||||||
var items = db.Query<Movie179>("SELECT Id, ProfileId FROM Movies");
|
var items = db.Query<Movie179>("SELECT \"Id\", \"ProfileId\" FROM \"Movies\"");
|
||||||
|
|
||||||
items.Should().HaveCount(9);
|
items.Should().HaveCount(9);
|
||||||
items.Where(x => x.ProfileId == commonProfileId).Should().HaveCount(7);
|
items.Where(x => x.ProfileId == commonProfileId).Should().HaveCount(7);
|
||||||
|
@ -20,8 +20,8 @@ private void AddMovie(fix_tmdb_duplicates m, int id, string movieTitle, string t
|
|||||||
Monitored = true,
|
Monitored = true,
|
||||||
Title = movieTitle,
|
Title = movieTitle,
|
||||||
CleanTitle = movieTitle,
|
CleanTitle = movieTitle,
|
||||||
Status = MovieStatusType.Announced,
|
Status = (int)MovieStatusType.Announced,
|
||||||
MinimumAvailability = MovieStatusType.Announced,
|
MinimumAvailability = (int)MovieStatusType.Announced,
|
||||||
Images = new[] { new { CoverType = "Poster" } }.ToJson(),
|
Images = new[] { new { CoverType = "Poster" } }.ToJson(),
|
||||||
Recommendations = new[] { 1 }.ToJson(),
|
Recommendations = new[] { 1 }.ToJson(),
|
||||||
HasPreDBEntry = false,
|
HasPreDBEntry = false,
|
||||||
@ -53,7 +53,7 @@ public void should_clean_duplicate_movies()
|
|||||||
AddMovie(c, 4, "movie", "slug3", tmdbId, 0, dateAdded, dateAdded);
|
AddMovie(c, 4, "movie", "slug3", tmdbId, 0, dateAdded, dateAdded);
|
||||||
});
|
});
|
||||||
|
|
||||||
var items = db.Query<Movie185>("SELECT Id, TmdbId, MovieFileId FROM Movies");
|
var items = db.Query<Movie185>("SELECT \"Id\", \"TmdbId\", \"MovieFileId\" FROM \"Movies\"");
|
||||||
|
|
||||||
items.Should().HaveCount(1);
|
items.Should().HaveCount(1);
|
||||||
}
|
}
|
||||||
@ -73,7 +73,7 @@ public void should_not_clean_non_duplicate_movies()
|
|||||||
AddMovie(c, 5, "movie2", "slug4", 123457, 0, dateAdded, dateAdded);
|
AddMovie(c, 5, "movie2", "slug4", 123457, 0, dateAdded, dateAdded);
|
||||||
});
|
});
|
||||||
|
|
||||||
var items = db.Query<Movie185>("SELECT Id, TmdbId, MovieFileId FROM Movies");
|
var items = db.Query<Movie185>("SELECT \"Id\", \"TmdbId\", \"MovieFileId\" FROM \"Movies\"");
|
||||||
|
|
||||||
items.Should().HaveCount(2);
|
items.Should().HaveCount(2);
|
||||||
items.Where(i => i.TmdbId == tmdbId).Should().HaveCount(1);
|
items.Where(i => i.TmdbId == tmdbId).Should().HaveCount(1);
|
||||||
@ -93,7 +93,7 @@ public void should_not_clean_any_if_no_duplicate_movies()
|
|||||||
AddMovie(c, 5, "movie5", "slug4", 123457, 0, dateAdded, dateAdded);
|
AddMovie(c, 5, "movie5", "slug4", 123457, 0, dateAdded, dateAdded);
|
||||||
});
|
});
|
||||||
|
|
||||||
var items = db.Query<Movie185>("SELECT Id, TmdbId, MovieFileId FROM Movies");
|
var items = db.Query<Movie185>("SELECT \"Id\", \"TmdbId\", \"MovieFileId\" FROM \"Movies\"");
|
||||||
|
|
||||||
items.Should().HaveCount(5);
|
items.Should().HaveCount(5);
|
||||||
}
|
}
|
||||||
@ -112,7 +112,7 @@ public void should_keep_movie_with_file_when_duplicates()
|
|||||||
AddMovie(c, 4, "movie", "slug3", tmdbId, 0, dateAdded, dateAdded);
|
AddMovie(c, 4, "movie", "slug3", tmdbId, 0, dateAdded, dateAdded);
|
||||||
});
|
});
|
||||||
|
|
||||||
var items = db.Query<Movie185>("SELECT Id, TmdbId, MovieFileId FROM Movies");
|
var items = db.Query<Movie185>("SELECT \"Id\", \"TmdbId\", \"MovieFileId\" FROM \"Movies\"");
|
||||||
|
|
||||||
items.Should().HaveCount(1);
|
items.Should().HaveCount(1);
|
||||||
items.First().Id.Should().Be(2);
|
items.First().Id.Should().Be(2);
|
||||||
@ -132,7 +132,7 @@ public void should_keep_earliest_added_a_movie_with_file_when_duplicates_and_mul
|
|||||||
AddMovie(c, 4, "movie", "slug3", tmdbId, 2, dateAdded, dateAdded);
|
AddMovie(c, 4, "movie", "slug3", tmdbId, 2, dateAdded, dateAdded);
|
||||||
});
|
});
|
||||||
|
|
||||||
var items = db.Query<Movie185>("SELECT Id, TmdbId, MovieFileId FROM Movies");
|
var items = db.Query<Movie185>("SELECT \"Id\", \"TmdbId\", \"MovieFileId\" FROM \"Movies\"");
|
||||||
|
|
||||||
items.Should().HaveCount(1);
|
items.Should().HaveCount(1);
|
||||||
items.First().MovieFileId.Should().BeGreaterThan(0);
|
items.First().MovieFileId.Should().BeGreaterThan(0);
|
||||||
@ -153,7 +153,7 @@ public void should_keep_a_movie_with_info_when_duplicates_and_no_file()
|
|||||||
AddMovie(c, 4, "movie", "slug3", tmdbId, 0, null, dateAdded);
|
AddMovie(c, 4, "movie", "slug3", tmdbId, 0, null, dateAdded);
|
||||||
});
|
});
|
||||||
|
|
||||||
var items = db.Query<Movie185>("SELECT Id, LastInfoSync, TmdbId, MovieFileId FROM Movies");
|
var items = db.Query<Movie185>("SELECT \"Id\", \"LastInfoSync\", \"TmdbId\", \"MovieFileId\" FROM \"Movies\"");
|
||||||
|
|
||||||
items.Should().HaveCount(1);
|
items.Should().HaveCount(1);
|
||||||
items.First().LastInfoSync.Should().NotBeNull();
|
items.First().LastInfoSync.Should().NotBeNull();
|
||||||
|
@ -67,7 +67,7 @@ public void should_change_property_names_for_audio_channels()
|
|||||||
AddMovieFile(c, 1);
|
AddMovieFile(c, 1);
|
||||||
});
|
});
|
||||||
|
|
||||||
var items = db.Query<MovieFile188>("SELECT MediaInfo FROM MovieFiles");
|
var items = db.Query<MovieFile188>("SELECT \"MediaInfo\" FROM \"MovieFiles\"");
|
||||||
|
|
||||||
items.Should().HaveCount(1);
|
items.Should().HaveCount(1);
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ public void should_set_cdh_to_enabled()
|
|||||||
{
|
{
|
||||||
c.Insert.IntoTable("DownloadClients").Row(new
|
c.Insert.IntoTable("DownloadClients").Row(new
|
||||||
{
|
{
|
||||||
Enable = 1,
|
Enable = true,
|
||||||
Name = "Deluge",
|
Name = "Deluge",
|
||||||
Implementation = "Deluge",
|
Implementation = "Deluge",
|
||||||
Priority = 1,
|
Priority = 1,
|
||||||
@ -34,7 +34,7 @@ public void should_set_cdh_to_enabled()
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
var items = db.Query<DownloadClientDefinition158>("SELECT * FROM DownloadClients");
|
var items = db.Query<DownloadClientDefinition158>("SELECT * FROM \"DownloadClients\"");
|
||||||
|
|
||||||
items.Should().HaveCount(1);
|
items.Should().HaveCount(1);
|
||||||
items.First().RemoveCompletedDownloads.Should().BeFalse();
|
items.First().RemoveCompletedDownloads.Should().BeFalse();
|
||||||
@ -54,7 +54,7 @@ public void should_set_cdh_to_disabled_when_globally_disabled()
|
|||||||
|
|
||||||
c.Insert.IntoTable("DownloadClients").Row(new
|
c.Insert.IntoTable("DownloadClients").Row(new
|
||||||
{
|
{
|
||||||
Enable = 1,
|
Enable = true,
|
||||||
Name = "Deluge",
|
Name = "Deluge",
|
||||||
Implementation = "Deluge",
|
Implementation = "Deluge",
|
||||||
Priority = 1,
|
Priority = 1,
|
||||||
@ -68,7 +68,7 @@ public void should_set_cdh_to_disabled_when_globally_disabled()
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
var items = db.Query<DownloadClientDefinition158>("SELECT * FROM DownloadClients");
|
var items = db.Query<DownloadClientDefinition158>("SELECT * FROM \"DownloadClients\"");
|
||||||
|
|
||||||
items.Should().HaveCount(1);
|
items.Should().HaveCount(1);
|
||||||
items.First().RemoveCompletedDownloads.Should().BeTrue();
|
items.First().RemoveCompletedDownloads.Should().BeTrue();
|
||||||
@ -82,7 +82,7 @@ public void should_disable_remove_for_existing_rtorrent()
|
|||||||
{
|
{
|
||||||
c.Insert.IntoTable("DownloadClients").Row(new
|
c.Insert.IntoTable("DownloadClients").Row(new
|
||||||
{
|
{
|
||||||
Enable = 1,
|
Enable = true,
|
||||||
Name = "RTorrent",
|
Name = "RTorrent",
|
||||||
Implementation = "RTorrent",
|
Implementation = "RTorrent",
|
||||||
Priority = 1,
|
Priority = 1,
|
||||||
@ -96,7 +96,7 @@ public void should_disable_remove_for_existing_rtorrent()
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
var items = db.Query<DownloadClientDefinition158>("SELECT * FROM DownloadClients");
|
var items = db.Query<DownloadClientDefinition158>("SELECT * FROM \"DownloadClients\"");
|
||||||
|
|
||||||
items.Should().HaveCount(1);
|
items.Should().HaveCount(1);
|
||||||
items.First().RemoveCompletedDownloads.Should().BeFalse();
|
items.First().RemoveCompletedDownloads.Should().BeFalse();
|
||||||
|
@ -58,7 +58,7 @@ public void should_replace_old_url()
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
var items = db.Query<NotificationEntity201>("SELECT Id,ConfigContract,Implementation,Name,Settings FROM Notifications");
|
var items = db.Query<NotificationEntity201>("SELECT \"Id\",\"ConfigContract\",\"Implementation\",\"Name\",\"Settings\" FROM \"Notifications\"");
|
||||||
|
|
||||||
items.Should().HaveCount(1);
|
items.Should().HaveCount(1);
|
||||||
items.First().ConfigContract.Should().Be("DiscordSettings");
|
items.First().ConfigContract.Should().Be("DiscordSettings");
|
||||||
|
@ -20,12 +20,12 @@ public void should_change_min_avail_from_predb_on_list()
|
|||||||
{
|
{
|
||||||
c.Insert.IntoTable("ImportLists").Row(new
|
c.Insert.IntoTable("ImportLists").Row(new
|
||||||
{
|
{
|
||||||
Enabled = 1,
|
Enabled = true,
|
||||||
EnableAuto = 1,
|
EnableAuto = true,
|
||||||
RootFolderPath = "D:\\Movies",
|
RootFolderPath = "D:\\Movies",
|
||||||
ProfileId = 1,
|
ProfileId = 1,
|
||||||
MinimumAvailability = 4,
|
MinimumAvailability = 4,
|
||||||
ShouldMonitor = 1,
|
ShouldMonitor = true,
|
||||||
Name = "IMDB List",
|
Name = "IMDB List",
|
||||||
Implementation = "RadarrLists",
|
Implementation = "RadarrLists",
|
||||||
Settings = new RadarrListSettings169
|
Settings = new RadarrListSettings169
|
||||||
@ -37,7 +37,7 @@ public void should_change_min_avail_from_predb_on_list()
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
var items = db.Query<ListDefinition201>("SELECT Id, MinimumAvailability FROM ImportLists");
|
var items = db.Query<ListDefinition201>("SELECT \"Id\", \"MinimumAvailability\" FROM \"ImportLists\"");
|
||||||
|
|
||||||
items.Should().HaveCount(1);
|
items.Should().HaveCount(1);
|
||||||
items.First().MinimumAvailability.Should().Be(3);
|
items.First().MinimumAvailability.Should().Be(3);
|
||||||
@ -70,7 +70,7 @@ public void should_change_min_avail_from_predb_on_movie()
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
var items = db.Query<Movie201>("SELECT Id, MinimumAvailability FROM Movies");
|
var items = db.Query<Movie201>("SELECT \"Id\", \"MinimumAvailability\" FROM \"Movies\"");
|
||||||
|
|
||||||
items.Should().HaveCount(1);
|
items.Should().HaveCount(1);
|
||||||
items.First().MinimumAvailability.Should().Be(3);
|
items.First().MinimumAvailability.Should().Be(3);
|
||||||
|
@ -11,9 +11,9 @@
|
|||||||
namespace NzbDrone.Core.Test.Datastore
|
namespace NzbDrone.Core.Test.Datastore
|
||||||
{
|
{
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
public class WhereBuilderFixture : CoreTest
|
public class WhereBuilderSqliteFixture : CoreTest
|
||||||
{
|
{
|
||||||
private WhereBuilder _subject;
|
private WhereBuilderSqlite _subject;
|
||||||
|
|
||||||
[OneTimeSetUp]
|
[OneTimeSetUp]
|
||||||
public void MapTables()
|
public void MapTables()
|
||||||
@ -22,9 +22,9 @@ public void MapTables()
|
|||||||
Mocker.Resolve<DbFactory>();
|
Mocker.Resolve<DbFactory>();
|
||||||
}
|
}
|
||||||
|
|
||||||
private WhereBuilder Where(Expression<Func<Movie, bool>> filter)
|
private WhereBuilderSqlite Where(Expression<Func<Movie, bool>> filter)
|
||||||
{
|
{
|
||||||
return new WhereBuilder(filter, true, 0);
|
return new WhereBuilderSqlite(filter, true, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@ -71,7 +71,7 @@ public void where_equal_joined_property()
|
|||||||
public void where_throws_without_concrete_condition_if_requiresConcreteCondition()
|
public void where_throws_without_concrete_condition_if_requiresConcreteCondition()
|
||||||
{
|
{
|
||||||
Expression<Func<Movie, Movie, bool>> filter = (x, y) => x.Id == y.Id;
|
Expression<Func<Movie, Movie, bool>> filter = (x, y) => x.Id == y.Id;
|
||||||
_subject = new WhereBuilder(filter, true, 0);
|
_subject = new WhereBuilderSqlite(filter, true, 0);
|
||||||
Assert.Throws<InvalidOperationException>(() => _subject.ToString());
|
Assert.Throws<InvalidOperationException>(() => _subject.ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,7 +79,7 @@ public void where_throws_without_concrete_condition_if_requiresConcreteCondition
|
|||||||
public void where_allows_abstract_condition_if_not_requiresConcreteCondition()
|
public void where_allows_abstract_condition_if_not_requiresConcreteCondition()
|
||||||
{
|
{
|
||||||
Expression<Func<Movie, Movie, bool>> filter = (x, y) => x.Id == y.Id;
|
Expression<Func<Movie, Movie, bool>> filter = (x, y) => x.Id == y.Id;
|
||||||
_subject = new WhereBuilder(filter, false, 0);
|
_subject = new WhereBuilderSqlite(filter, false, 0);
|
||||||
_subject.ToString().Should().Be($"(\"Movies\".\"Id\" = \"Movies\".\"Id\")");
|
_subject.ToString().Should().Be($"(\"Movies\".\"Id\" = \"Movies\".\"Id\")");
|
||||||
}
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
using FizzWare.NBuilder;
|
using FizzWare.NBuilder;
|
||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using NzbDrone.Core.Housekeeping.Housekeepers;
|
using NzbDrone.Core.Housekeeping.Housekeepers;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using FizzWare.NBuilder;
|
using FizzWare.NBuilder;
|
||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
@ -41,7 +41,8 @@ public void should_not_change_last_execution_time_when_its_in_the_past()
|
|||||||
|
|
||||||
Subject.Clean();
|
Subject.Clean();
|
||||||
|
|
||||||
AllStoredModels.ToList().ForEach(t => t.LastExecution.Should().Be(expectedTime));
|
// BeCloseTo handles Postgres rounding times
|
||||||
|
AllStoredModels.ToList().ForEach(t => t.LastExecution.Should().BeCloseTo(expectedTime));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -190,9 +190,12 @@ private void Cleanup()
|
|||||||
|
|
||||||
private void BackupDatabase()
|
private void BackupDatabase()
|
||||||
{
|
{
|
||||||
_logger.ProgressDebug("Backing up database");
|
if (_maindDb.DatabaseType == DatabaseType.SQLite)
|
||||||
|
{
|
||||||
|
_logger.ProgressDebug("Backing up database");
|
||||||
|
|
||||||
_makeDatabaseBackup.BackupDatabase(_maindDb, _backupTempFolder);
|
_makeDatabaseBackup.BackupDatabase(_maindDb, _backupTempFolder);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void BackupConfigFile()
|
private void BackupConfigFile()
|
||||||
|
@ -40,7 +40,7 @@ public void DeleteForMovies(List<int> movieIds)
|
|||||||
Delete(x => movieIds.Contains(x.MovieId));
|
Delete(x => movieIds.Contains(x.MovieId));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override SqlBuilder PagedBuilder() => new SqlBuilder().Join<Blocklist, Movie>((b, m) => b.MovieId == m.Id);
|
protected override SqlBuilder PagedBuilder() => new SqlBuilder(_database.DatabaseType).Join<Blocklist, Movie>((b, m) => b.MovieId == m.Id);
|
||||||
protected override IEnumerable<Blocklist> PagedQuery(SqlBuilder sql) => _database.QueryJoined<Blocklist, Movie>(sql, (bl, movie) =>
|
protected override IEnumerable<Blocklist> PagedQuery(SqlBuilder sql) => _database.QueryJoined<Blocklist, Movie>(sql, (bl, movie) =>
|
||||||
{
|
{
|
||||||
bl.Movie = movie;
|
bl.Movie = movie;
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
namespace NzbDrone.Core.Configuration
|
namespace NzbDrone.Core.Configuration
|
||||||
{
|
{
|
||||||
public interface IConfigFileProvider : IHandleAsync<ApplicationStartedEvent>,
|
public interface IConfigFileProvider : IHandleAsync<ApplicationStartedEvent>,
|
||||||
IExecute<ResetApiKeyCommand>
|
IExecute<ResetApiKeyCommand>
|
||||||
{
|
{
|
||||||
XDocument LoadConfigFile();
|
XDocument LoadConfigFile();
|
||||||
Dictionary<string, object> GetConfigDictionary();
|
Dictionary<string, object> GetConfigDictionary();
|
||||||
@ -48,6 +48,12 @@ public interface IConfigFileProvider : IHandleAsync<ApplicationStartedEvent>,
|
|||||||
string UpdateScriptPath { get; }
|
string UpdateScriptPath { get; }
|
||||||
string SyslogServer { get; }
|
string SyslogServer { get; }
|
||||||
int SyslogPort { get; }
|
int SyslogPort { get; }
|
||||||
|
string PostgresHost { get; }
|
||||||
|
int PostgresPort { get; }
|
||||||
|
string PostgresUser { get; }
|
||||||
|
string PostgresPassword { get; }
|
||||||
|
string PostgresMainDb { get; }
|
||||||
|
string PostgresLogDb { get; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ConfigFileProvider : IConfigFileProvider
|
public class ConfigFileProvider : IConfigFileProvider
|
||||||
@ -184,6 +190,12 @@ public AuthenticationType AuthenticationMethod
|
|||||||
|
|
||||||
public string LogLevel => GetValue("LogLevel", "info").ToLowerInvariant();
|
public string LogLevel => GetValue("LogLevel", "info").ToLowerInvariant();
|
||||||
public string ConsoleLogLevel => GetValue("ConsoleLogLevel", string.Empty, persist: false);
|
public string ConsoleLogLevel => GetValue("ConsoleLogLevel", string.Empty, persist: false);
|
||||||
|
public string PostgresHost => GetValue("PostgresHost", string.Empty, persist: false);
|
||||||
|
public string PostgresUser => GetValue("PostgresUser", string.Empty, persist: false);
|
||||||
|
public string PostgresPassword => GetValue("PostgresPassword", string.Empty, persist: false);
|
||||||
|
public string PostgresMainDb => GetValue("PostgresMainDb", "radarr-main", persist: false);
|
||||||
|
public string PostgresLogDb => GetValue("PostgresLogDb", "radarr-log", persist: false);
|
||||||
|
public int PostgresPort => GetValueInt("PostgresPort", 5432, persist: false);
|
||||||
public bool LogSql => GetValueBoolean("LogSql", false, persist: false);
|
public bool LogSql => GetValueBoolean("LogSql", false, persist: false);
|
||||||
public int LogRotate => GetValueInt("LogRotate", 50, persist: false);
|
public int LogRotate => GetValueInt("LogRotate", 50, persist: false);
|
||||||
public bool FilterSentryEvents => GetValueBoolean("FilterSentryEvents", true, persist: false);
|
public bool FilterSentryEvents => GetValueBoolean("FilterSentryEvents", true, persist: false);
|
||||||
|
@ -67,7 +67,7 @@ public BasicRepository(IDatabase database, IEventAggregator eventAggregator)
|
|||||||
_updateSql = GetUpdateSql(_properties);
|
_updateSql = GetUpdateSql(_properties);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual SqlBuilder Builder() => new SqlBuilder();
|
protected virtual SqlBuilder Builder() => new SqlBuilder(_database.DatabaseType);
|
||||||
|
|
||||||
protected virtual List<TModel> Query(SqlBuilder builder) => _database.Query<TModel>(builder).ToList();
|
protected virtual List<TModel> Query(SqlBuilder builder) => _database.Query<TModel>(builder).ToList();
|
||||||
|
|
||||||
@ -79,7 +79,7 @@ public int Count()
|
|||||||
{
|
{
|
||||||
using (var conn = _database.OpenConnection())
|
using (var conn = _database.OpenConnection())
|
||||||
{
|
{
|
||||||
return conn.ExecuteScalar<int>($"SELECT COUNT(*) FROM {_table}");
|
return conn.ExecuteScalar<int>($"SELECT COUNT(*) FROM \"{_table}\"");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -175,6 +175,11 @@ private string GetInsertSql()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (_database.DatabaseType == DatabaseType.PostgreSQL)
|
||||||
|
{
|
||||||
|
return $"INSERT INTO \"{_table}\" ({sbColumnList.ToString()}) VALUES ({sbParameterList.ToString()}) RETURNING \"Id\"";
|
||||||
|
}
|
||||||
|
|
||||||
return $"INSERT INTO {_table} ({sbColumnList.ToString()}) VALUES ({sbParameterList.ToString()}); SELECT last_insert_rowid() id";
|
return $"INSERT INTO {_table} ({sbColumnList.ToString()}) VALUES ({sbParameterList.ToString()}); SELECT last_insert_rowid() id";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -182,7 +187,8 @@ private TModel Insert(IDbConnection connection, IDbTransaction transaction, TMod
|
|||||||
{
|
{
|
||||||
SqlBuilderExtensions.LogQuery(_insertSql, model);
|
SqlBuilderExtensions.LogQuery(_insertSql, model);
|
||||||
var multi = connection.QueryMultiple(_insertSql, model, transaction);
|
var multi = connection.QueryMultiple(_insertSql, model, transaction);
|
||||||
var id = (int)multi.Read().First().id;
|
var multiRead = multi.Read();
|
||||||
|
var id = (int)(multiRead.First().id ?? multiRead.First().Id);
|
||||||
_keyProperty.SetValue(model, id);
|
_keyProperty.SetValue(model, id);
|
||||||
|
|
||||||
return model;
|
return model;
|
||||||
@ -293,7 +299,7 @@ public void Purge(bool vacuum = false)
|
|||||||
{
|
{
|
||||||
using (var conn = _database.OpenConnection())
|
using (var conn = _database.OpenConnection())
|
||||||
{
|
{
|
||||||
conn.Execute($"DELETE FROM [{_table}]");
|
conn.Execute($"DELETE FROM \"{_table}\"");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (vacuum)
|
if (vacuum)
|
||||||
@ -352,7 +358,7 @@ public void SetFields(IList<TModel> models, params Expression<Func<TModel, objec
|
|||||||
private string GetUpdateSql(List<PropertyInfo> propertiesToUpdate)
|
private string GetUpdateSql(List<PropertyInfo> propertiesToUpdate)
|
||||||
{
|
{
|
||||||
var sb = new StringBuilder();
|
var sb = new StringBuilder();
|
||||||
sb.AppendFormat("UPDATE {0} SET ", _table);
|
sb.AppendFormat("UPDATE \"{0}\" SET ", _table);
|
||||||
|
|
||||||
for (var i = 0; i < propertiesToUpdate.Count; i++)
|
for (var i = 0; i < propertiesToUpdate.Count; i++)
|
||||||
{
|
{
|
||||||
@ -420,9 +426,10 @@ protected List<TModel> GetPagedRecords(SqlBuilder builder, PagingSpec<TModel> pa
|
|||||||
pagingSpec.SortKey = $"{_table}.{_keyProperty.Name}";
|
pagingSpec.SortKey = $"{_table}.{_keyProperty.Name}";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var sortKey = TableMapping.Mapper.GetSortKey(pagingSpec.SortKey);
|
||||||
var sortDirection = pagingSpec.SortDirection == SortDirection.Descending ? "DESC" : "ASC";
|
var sortDirection = pagingSpec.SortDirection == SortDirection.Descending ? "DESC" : "ASC";
|
||||||
var pagingOffset = (pagingSpec.Page - 1) * pagingSpec.PageSize;
|
var pagingOffset = Math.Max(pagingSpec.Page - 1, 0) * pagingSpec.PageSize;
|
||||||
builder.OrderBy($"{pagingSpec.SortKey} {sortDirection} LIMIT {pagingSpec.PageSize} OFFSET {pagingOffset}");
|
builder.OrderBy($"\"{sortKey}\" {sortDirection} LIMIT {pagingSpec.PageSize} OFFSET {pagingOffset}");
|
||||||
|
|
||||||
return queryFunc(builder).ToList();
|
return queryFunc(builder).ToList();
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Data.SQLite;
|
using System.Data.SQLite;
|
||||||
|
using Npgsql;
|
||||||
using NzbDrone.Common.EnvironmentInfo;
|
using NzbDrone.Common.EnvironmentInfo;
|
||||||
using NzbDrone.Common.Extensions;
|
using NzbDrone.Common.Extensions;
|
||||||
|
using NzbDrone.Core.Configuration;
|
||||||
|
|
||||||
namespace NzbDrone.Core.Datastore
|
namespace NzbDrone.Core.Datastore
|
||||||
{
|
{
|
||||||
@ -14,10 +16,17 @@ public interface IConnectionStringFactory
|
|||||||
|
|
||||||
public class ConnectionStringFactory : IConnectionStringFactory
|
public class ConnectionStringFactory : IConnectionStringFactory
|
||||||
{
|
{
|
||||||
public ConnectionStringFactory(IAppFolderInfo appFolderInfo)
|
private readonly IConfigFileProvider _configFileProvider;
|
||||||
|
|
||||||
|
public ConnectionStringFactory(IAppFolderInfo appFolderInfo, IConfigFileProvider configFileProvider)
|
||||||
{
|
{
|
||||||
MainDbConnectionString = GetConnectionString(appFolderInfo.GetDatabase());
|
_configFileProvider = configFileProvider;
|
||||||
LogDbConnectionString = GetConnectionString(appFolderInfo.GetLogDatabase());
|
|
||||||
|
MainDbConnectionString = _configFileProvider.PostgresHost.IsNotNullOrWhiteSpace() ? GetPostgresConnectionString(_configFileProvider.PostgresMainDb) :
|
||||||
|
GetConnectionString(appFolderInfo.GetDatabase());
|
||||||
|
|
||||||
|
LogDbConnectionString = _configFileProvider.PostgresHost.IsNotNullOrWhiteSpace() ? GetPostgresConnectionString(_configFileProvider.PostgresLogDb) :
|
||||||
|
GetConnectionString(appFolderInfo.GetLogDatabase());
|
||||||
}
|
}
|
||||||
|
|
||||||
public string MainDbConnectionString { get; private set; }
|
public string MainDbConnectionString { get; private set; }
|
||||||
@ -48,5 +57,19 @@ private static string GetConnectionString(string dbPath)
|
|||||||
|
|
||||||
return connectionBuilder.ConnectionString;
|
return connectionBuilder.ConnectionString;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private string GetPostgresConnectionString(string dbName)
|
||||||
|
{
|
||||||
|
var connectionBuilder = new NpgsqlConnectionStringBuilder();
|
||||||
|
|
||||||
|
connectionBuilder.Database = dbName;
|
||||||
|
connectionBuilder.Host = _configFileProvider.PostgresHost;
|
||||||
|
connectionBuilder.Username = _configFileProvider.PostgresUser;
|
||||||
|
connectionBuilder.Password = _configFileProvider.PostgresPassword;
|
||||||
|
connectionBuilder.Port = _configFileProvider.PostgresPort;
|
||||||
|
connectionBuilder.Enlist = false;
|
||||||
|
|
||||||
|
return connectionBuilder.ConnectionString;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
using Dapper;
|
using Dapper;
|
||||||
using NLog;
|
using NLog;
|
||||||
using NzbDrone.Common.Instrumentation;
|
using NzbDrone.Common.Instrumentation;
|
||||||
@ -11,6 +12,7 @@ public interface IDatabase
|
|||||||
IDbConnection OpenConnection();
|
IDbConnection OpenConnection();
|
||||||
Version Version { get; }
|
Version Version { get; }
|
||||||
int Migration { get; }
|
int Migration { get; }
|
||||||
|
DatabaseType DatabaseType { get; }
|
||||||
void Vacuum();
|
void Vacuum();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,13 +34,44 @@ public IDbConnection OpenConnection()
|
|||||||
return _datamapperFactory();
|
return _datamapperFactory();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public DatabaseType DatabaseType
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
using (var db = _datamapperFactory())
|
||||||
|
{
|
||||||
|
if (db.ConnectionString.Contains(".db"))
|
||||||
|
{
|
||||||
|
return DatabaseType.SQLite;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return DatabaseType.PostgreSQL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public Version Version
|
public Version Version
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
using (var db = _datamapperFactory())
|
using (var db = _datamapperFactory())
|
||||||
{
|
{
|
||||||
var version = db.QueryFirstOrDefault<string>("SELECT sqlite_version()");
|
string version;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
version = db.QueryFirstOrDefault<string>("SHOW server_version");
|
||||||
|
|
||||||
|
//Postgres can return extra info about operating system on version call, ignore this
|
||||||
|
version = Regex.Replace(version, @"\(.*?\)", "");
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
version = db.QueryFirstOrDefault<string>("SELECT sqlite_version()");
|
||||||
|
}
|
||||||
|
|
||||||
return new Version(version);
|
return new Version(version);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -50,7 +83,7 @@ public int Migration
|
|||||||
{
|
{
|
||||||
using (var db = _datamapperFactory())
|
using (var db = _datamapperFactory())
|
||||||
{
|
{
|
||||||
return db.QueryFirstOrDefault<int>("SELECT version from VersionInfo ORDER BY version DESC LIMIT 1");
|
return db.QueryFirstOrDefault<int>("SELECT \"Version\" from \"VersionInfo\" ORDER BY \"Version\" DESC LIMIT 1");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -73,4 +106,10 @@ public void Vacuum()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum DatabaseType
|
||||||
|
{
|
||||||
|
SQLite,
|
||||||
|
PostgreSQL
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,13 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Data.Common;
|
||||||
using System.Data.SQLite;
|
using System.Data.SQLite;
|
||||||
using NLog;
|
using NLog;
|
||||||
|
using Npgsql;
|
||||||
using NzbDrone.Common.Disk;
|
using NzbDrone.Common.Disk;
|
||||||
using NzbDrone.Common.EnvironmentInfo;
|
using NzbDrone.Common.EnvironmentInfo;
|
||||||
using NzbDrone.Common.Exceptions;
|
using NzbDrone.Common.Exceptions;
|
||||||
using NzbDrone.Common.Instrumentation;
|
using NzbDrone.Common.Instrumentation;
|
||||||
|
using NzbDrone.Core.Configuration;
|
||||||
using NzbDrone.Core.Datastore.Migration.Framework;
|
using NzbDrone.Core.Datastore.Migration.Framework;
|
||||||
|
|
||||||
namespace NzbDrone.Core.Datastore
|
namespace NzbDrone.Core.Datastore
|
||||||
@ -85,10 +88,19 @@ public IDatabase Create(MigrationContext migrationContext)
|
|||||||
|
|
||||||
var db = new Database(migrationContext.MigrationType.ToString(), () =>
|
var db = new Database(migrationContext.MigrationType.ToString(), () =>
|
||||||
{
|
{
|
||||||
var conn = SQLiteFactory.Instance.CreateConnection();
|
DbConnection conn;
|
||||||
conn.ConnectionString = connectionString;
|
|
||||||
conn.Open();
|
|
||||||
|
|
||||||
|
if (connectionString.Contains(".db"))
|
||||||
|
{
|
||||||
|
conn = SQLiteFactory.Instance.CreateConnection();
|
||||||
|
conn.ConnectionString = connectionString;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
conn = new NpgsqlConnection(connectionString);
|
||||||
|
}
|
||||||
|
|
||||||
|
conn.Open();
|
||||||
return conn;
|
return conn;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ public static class SqlBuilderExtensions
|
|||||||
|
|
||||||
public static SqlBuilder Select(this SqlBuilder builder, params Type[] types)
|
public static SqlBuilder Select(this SqlBuilder builder, params Type[] types)
|
||||||
{
|
{
|
||||||
return builder.Select(types.Select(x => TableMapping.Mapper.TableNameMapping(x) + ".*").Join(", "));
|
return builder.Select(types.Select(x => $"\"{TableMapping.Mapper.TableNameMapping(x)}\".*").Join(", "));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SqlBuilder SelectDistinct(this SqlBuilder builder, params Type[] types)
|
public static SqlBuilder SelectDistinct(this SqlBuilder builder, params Type[] types)
|
||||||
@ -42,41 +42,48 @@ public static SqlBuilder SelectCountDistinct<TModel>(this SqlBuilder builder, Ex
|
|||||||
|
|
||||||
public static SqlBuilder Where<TModel>(this SqlBuilder builder, Expression<Func<TModel, bool>> filter)
|
public static SqlBuilder Where<TModel>(this SqlBuilder builder, Expression<Func<TModel, bool>> filter)
|
||||||
{
|
{
|
||||||
var wb = new WhereBuilder(filter, true, builder.Sequence);
|
var wb = GetWhereBuilder(builder.DatabaseType, filter, true, builder.Sequence);
|
||||||
|
|
||||||
|
return builder.Where(wb.ToString(), wb.Parameters);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static SqlBuilder WherePostgres<TModel>(this SqlBuilder builder, Expression<Func<TModel, bool>> filter)
|
||||||
|
{
|
||||||
|
var wb = new WhereBuilderPostgres(filter, true, builder.Sequence);
|
||||||
|
|
||||||
return builder.Where(wb.ToString(), wb.Parameters);
|
return builder.Where(wb.ToString(), wb.Parameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SqlBuilder OrWhere<TModel>(this SqlBuilder builder, Expression<Func<TModel, bool>> filter)
|
public static SqlBuilder OrWhere<TModel>(this SqlBuilder builder, Expression<Func<TModel, bool>> filter)
|
||||||
{
|
{
|
||||||
var wb = new WhereBuilder(filter, true, builder.Sequence);
|
var wb = GetWhereBuilder(builder.DatabaseType, filter, true, builder.Sequence);
|
||||||
|
|
||||||
return builder.OrWhere(wb.ToString(), wb.Parameters);
|
return builder.OrWhere(wb.ToString(), wb.Parameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SqlBuilder Join<TLeft, TRight>(this SqlBuilder builder, Expression<Func<TLeft, TRight, bool>> filter)
|
public static SqlBuilder Join<TLeft, TRight>(this SqlBuilder builder, Expression<Func<TLeft, TRight, bool>> filter)
|
||||||
{
|
{
|
||||||
var wb = new WhereBuilder(filter, false, builder.Sequence);
|
var wb = GetWhereBuilder(builder.DatabaseType, filter, false, builder.Sequence);
|
||||||
|
|
||||||
var rightTable = TableMapping.Mapper.TableNameMapping(typeof(TRight));
|
var rightTable = TableMapping.Mapper.TableNameMapping(typeof(TRight));
|
||||||
|
|
||||||
return builder.Join($"{rightTable} ON {wb.ToString()}");
|
return builder.Join($"\"{rightTable}\" ON {wb.ToString()}");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SqlBuilder LeftJoin<TLeft, TRight>(this SqlBuilder builder, Expression<Func<TLeft, TRight, bool>> filter)
|
public static SqlBuilder LeftJoin<TLeft, TRight>(this SqlBuilder builder, Expression<Func<TLeft, TRight, bool>> filter)
|
||||||
{
|
{
|
||||||
var wb = new WhereBuilder(filter, false, builder.Sequence);
|
var wb = GetWhereBuilder(builder.DatabaseType, filter, false, builder.Sequence);
|
||||||
|
|
||||||
var rightTable = TableMapping.Mapper.TableNameMapping(typeof(TRight));
|
var rightTable = TableMapping.Mapper.TableNameMapping(typeof(TRight));
|
||||||
|
|
||||||
return builder.LeftJoin($"{rightTable} ON {wb.ToString()}");
|
return builder.LeftJoin($"\"{rightTable}\" ON {wb.ToString()}");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SqlBuilder GroupBy<TModel>(this SqlBuilder builder, Expression<Func<TModel, object>> property)
|
public static SqlBuilder GroupBy<TModel>(this SqlBuilder builder, Expression<Func<TModel, object>> property)
|
||||||
{
|
{
|
||||||
var table = TableMapping.Mapper.TableNameMapping(typeof(TModel));
|
var table = TableMapping.Mapper.TableNameMapping(typeof(TModel));
|
||||||
var propName = property.GetMemberName().Name;
|
var propName = property.GetMemberName().Name;
|
||||||
return builder.GroupBy($"{table}.{propName}");
|
return builder.GroupBy($"\"{table}\".\"{propName}\"");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SqlBuilder.Template AddSelectTemplate(this SqlBuilder builder, Type type)
|
public static SqlBuilder.Template AddSelectTemplate(this SqlBuilder builder, Type type)
|
||||||
@ -138,6 +145,18 @@ public static string GetSqlLogString(string sql, object paramsObject)
|
|||||||
return sb.ToString();
|
return sb.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static WhereBuilder GetWhereBuilder(DatabaseType databaseType, Expression filter, bool requireConcrete, int seq)
|
||||||
|
{
|
||||||
|
if (databaseType == DatabaseType.PostgreSQL)
|
||||||
|
{
|
||||||
|
return new WhereBuilderPostgres(filter, requireConcrete, seq);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return new WhereBuilderSqlite(filter, requireConcrete, seq);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static Dictionary<string, object> ToDictionary(this DynamicParameters dynamicParams)
|
private static Dictionary<string, object> ToDictionary(this DynamicParameters dynamicParams)
|
||||||
{
|
{
|
||||||
var argsDictionary = new Dictionary<string, object>();
|
var argsDictionary = new Dictionary<string, object>();
|
||||||
|
@ -10,10 +10,12 @@ public interface ILogDatabase : IDatabase
|
|||||||
public class LogDatabase : ILogDatabase
|
public class LogDatabase : ILogDatabase
|
||||||
{
|
{
|
||||||
private readonly IDatabase _database;
|
private readonly IDatabase _database;
|
||||||
|
private readonly DatabaseType _databaseType;
|
||||||
|
|
||||||
public LogDatabase(IDatabase database)
|
public LogDatabase(IDatabase database)
|
||||||
{
|
{
|
||||||
_database = database;
|
_database = database;
|
||||||
|
_databaseType = _database == null ? DatabaseType.SQLite : _database.DatabaseType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IDbConnection OpenConnection()
|
public IDbConnection OpenConnection()
|
||||||
@ -25,6 +27,8 @@ public IDbConnection OpenConnection()
|
|||||||
|
|
||||||
public int Migration => _database.Migration;
|
public int Migration => _database.Migration;
|
||||||
|
|
||||||
|
public DatabaseType DatabaseType => _databaseType;
|
||||||
|
|
||||||
public void Vacuum()
|
public void Vacuum()
|
||||||
{
|
{
|
||||||
_database.Vacuum();
|
_database.Vacuum();
|
||||||
|
@ -10,10 +10,12 @@ public interface IMainDatabase : IDatabase
|
|||||||
public class MainDatabase : IMainDatabase
|
public class MainDatabase : IMainDatabase
|
||||||
{
|
{
|
||||||
private readonly IDatabase _database;
|
private readonly IDatabase _database;
|
||||||
|
private readonly DatabaseType _databaseType;
|
||||||
|
|
||||||
public MainDatabase(IDatabase database)
|
public MainDatabase(IDatabase database)
|
||||||
{
|
{
|
||||||
_database = database;
|
_database = database;
|
||||||
|
_databaseType = _database == null ? DatabaseType.SQLite : _database.DatabaseType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IDbConnection OpenConnection()
|
public IDbConnection OpenConnection()
|
||||||
@ -25,6 +27,8 @@ public IDbConnection OpenConnection()
|
|||||||
|
|
||||||
public int Migration => _database.Migration;
|
public int Migration => _database.Migration;
|
||||||
|
|
||||||
|
public DatabaseType DatabaseType => _databaseType;
|
||||||
|
|
||||||
public void Vacuum()
|
public void Vacuum()
|
||||||
{
|
{
|
||||||
_database.Vacuum();
|
_database.Vacuum();
|
||||||
|
@ -144,7 +144,7 @@ protected override void MainDbUpgrade()
|
|||||||
.WithColumn("Items").AsString().NotNullable()
|
.WithColumn("Items").AsString().NotNullable()
|
||||||
.WithColumn("Language").AsInt32().Nullable();
|
.WithColumn("Language").AsInt32().Nullable();
|
||||||
|
|
||||||
Execute.Sql("UPDATE Profiles SET Language = 1");
|
Execute.Sql("UPDATE \"Profiles\" SET \"Language\" = 1");
|
||||||
|
|
||||||
Create.TableForModel("SceneMappings")
|
Create.TableForModel("SceneMappings")
|
||||||
.WithColumn("TvdbId").AsInt32()
|
.WithColumn("TvdbId").AsInt32()
|
||||||
@ -243,8 +243,8 @@ protected override void MainDbUpgrade()
|
|||||||
|
|
||||||
Insert.IntoTable("DelayProfiles").Row(new
|
Insert.IntoTable("DelayProfiles").Row(new
|
||||||
{
|
{
|
||||||
EnableUsenet = 1,
|
EnableUsenet = true,
|
||||||
EnableTorrent = 1,
|
EnableTorrent = true,
|
||||||
PreferredProtocol = 1,
|
PreferredProtocol = 1,
|
||||||
UsenetDelay = 0,
|
UsenetDelay = 0,
|
||||||
TorrentDelay = 0,
|
TorrentDelay = 0,
|
||||||
|
@ -9,7 +9,7 @@ public class update_schedule_intervale : NzbDroneMigrationBase
|
|||||||
protected override void MainDbUpgrade()
|
protected override void MainDbUpgrade()
|
||||||
{
|
{
|
||||||
Alter.Table("ScheduledTasks").AlterColumn("Interval").AsDouble();
|
Alter.Table("ScheduledTasks").AlterColumn("Interval").AsDouble();
|
||||||
Execute.Sql("UPDATE ScheduledTasks SET Interval=0.25 WHERE TypeName='NzbDrone.Core.Download.CheckForFinishedDownloadCommand'");
|
Execute.Sql("UPDATE \"ScheduledTasks\" SET \"Interval\" = 0.25 WHERE \"TypeName\" = 'NzbDrone.Core.Download.CheckForFinishedDownloadCommand'");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ private void ConvertConfig(IDbConnection conn, IDbTransaction tran)
|
|||||||
using (IDbCommand namingConfigCmd = conn.CreateCommand())
|
using (IDbCommand namingConfigCmd = conn.CreateCommand())
|
||||||
{
|
{
|
||||||
namingConfigCmd.Transaction = tran;
|
namingConfigCmd.Transaction = tran;
|
||||||
namingConfigCmd.CommandText = @"SELECT * FROM NamingConfig LIMIT 1";
|
namingConfigCmd.CommandText = @"SELECT * FROM ""NamingConfig"" LIMIT 1";
|
||||||
using (IDataReader namingConfigReader = namingConfigCmd.ExecuteReader())
|
using (IDataReader namingConfigReader = namingConfigCmd.ExecuteReader())
|
||||||
{
|
{
|
||||||
while (namingConfigReader.Read())
|
while (namingConfigReader.Read())
|
||||||
@ -38,9 +38,9 @@ private void ConvertConfig(IDbConnection conn, IDbTransaction tran)
|
|||||||
|
|
||||||
using (IDbCommand updateCmd = conn.CreateCommand())
|
using (IDbCommand updateCmd = conn.CreateCommand())
|
||||||
{
|
{
|
||||||
var text = string.Format("UPDATE NamingConfig " +
|
var text = string.Format("UPDATE \"NamingConfig\" " +
|
||||||
"SET StandardMovieFormat = '{0}', " +
|
"SET \"StandardMovieFormat\" = '{0}', " +
|
||||||
"MovieFolderFormat = '{1}'",
|
"\"MovieFolderFormat\" = '{1}'",
|
||||||
standardMovieFormat,
|
standardMovieFormat,
|
||||||
movieFolderFormat);
|
movieFolderFormat);
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ private void SetSortTitles(IDbConnection conn, IDbTransaction tran)
|
|||||||
using (IDbCommand getSeriesCmd = conn.CreateCommand())
|
using (IDbCommand getSeriesCmd = conn.CreateCommand())
|
||||||
{
|
{
|
||||||
getSeriesCmd.Transaction = tran;
|
getSeriesCmd.Transaction = tran;
|
||||||
getSeriesCmd.CommandText = @"SELECT Id, Title FROM Movies";
|
getSeriesCmd.CommandText = @"SELECT ""Id"", ""Title"" FROM ""Movies""";
|
||||||
using (IDataReader seriesReader = getSeriesCmd.ExecuteReader())
|
using (IDataReader seriesReader = getSeriesCmd.ExecuteReader())
|
||||||
{
|
{
|
||||||
while (seriesReader.Read())
|
while (seriesReader.Read())
|
||||||
@ -31,7 +31,7 @@ private void SetSortTitles(IDbConnection conn, IDbTransaction tran)
|
|||||||
using (IDbCommand updateCmd = conn.CreateCommand())
|
using (IDbCommand updateCmd = conn.CreateCommand())
|
||||||
{
|
{
|
||||||
updateCmd.Transaction = tran;
|
updateCmd.Transaction = tran;
|
||||||
updateCmd.CommandText = "UPDATE Movies SET SortTitle = ? WHERE Id = ?";
|
updateCmd.CommandText = "UPDATE \"Movies\" SET \"SortTitle\" = ? WHERE \"Id\" = ?";
|
||||||
updateCmd.AddParameter(sortTitle);
|
updateCmd.AddParameter(sortTitle);
|
||||||
updateCmd.AddParameter(id);
|
updateCmd.AddParameter(id);
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ private void SetSortTitles(IDbConnection conn, IDbTransaction tran)
|
|||||||
using (IDbCommand getSeriesCmd = conn.CreateCommand())
|
using (IDbCommand getSeriesCmd = conn.CreateCommand())
|
||||||
{
|
{
|
||||||
getSeriesCmd.Transaction = tran;
|
getSeriesCmd.Transaction = tran;
|
||||||
getSeriesCmd.CommandText = @"SELECT Id, Title FROM Movies";
|
getSeriesCmd.CommandText = @"SELECT ""Id"", ""Title"" FROM ""Movies""";
|
||||||
using (IDataReader seriesReader = getSeriesCmd.ExecuteReader())
|
using (IDataReader seriesReader = getSeriesCmd.ExecuteReader())
|
||||||
{
|
{
|
||||||
while (seriesReader.Read())
|
while (seriesReader.Read())
|
||||||
@ -30,7 +30,7 @@ private void SetSortTitles(IDbConnection conn, IDbTransaction tran)
|
|||||||
using (IDbCommand updateCmd = conn.CreateCommand())
|
using (IDbCommand updateCmd = conn.CreateCommand())
|
||||||
{
|
{
|
||||||
updateCmd.Transaction = tran;
|
updateCmd.Transaction = tran;
|
||||||
updateCmd.CommandText = "UPDATE Movies SET SortTitle = ? WHERE Id = ?";
|
updateCmd.CommandText = "UPDATE \"Movies\" SET \"SortTitle\" = ? WHERE \"Id\" = ?";
|
||||||
updateCmd.AddParameter(sortTitle);
|
updateCmd.AddParameter(sortTitle);
|
||||||
updateCmd.AddParameter(id);
|
updateCmd.AddParameter(id);
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ private void SetSortTitles(IDbConnection conn, IDbTransaction tran)
|
|||||||
using (IDbCommand getSeriesCmd = conn.CreateCommand())
|
using (IDbCommand getSeriesCmd = conn.CreateCommand())
|
||||||
{
|
{
|
||||||
getSeriesCmd.Transaction = tran;
|
getSeriesCmd.Transaction = tran;
|
||||||
getSeriesCmd.CommandText = @"SELECT Id, RelativePath FROM MovieFiles";
|
getSeriesCmd.CommandText = @"SELECT ""Id"", ""RelativePath"" FROM ""MovieFiles""";
|
||||||
using (IDataReader seriesReader = getSeriesCmd.ExecuteReader())
|
using (IDataReader seriesReader = getSeriesCmd.ExecuteReader())
|
||||||
{
|
{
|
||||||
while (seriesReader.Read())
|
while (seriesReader.Read())
|
||||||
@ -39,7 +39,7 @@ private void SetSortTitles(IDbConnection conn, IDbTransaction tran)
|
|||||||
using (IDbCommand updateCmd = conn.CreateCommand())
|
using (IDbCommand updateCmd = conn.CreateCommand())
|
||||||
{
|
{
|
||||||
updateCmd.Transaction = tran;
|
updateCmd.Transaction = tran;
|
||||||
updateCmd.CommandText = "UPDATE MovieFiles SET Edition = ? WHERE Id = ?";
|
updateCmd.CommandText = "UPDATE \"MovieFiles\" SET \"Edition\" = ? WHERE \"Id\" = ?";
|
||||||
updateCmd.AddParameter(edition);
|
updateCmd.AddParameter(edition);
|
||||||
updateCmd.AddParameter(id);
|
updateCmd.AddParameter(id);
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ private void SetTitleSlug(IDbConnection conn, IDbTransaction tran)
|
|||||||
using (IDbCommand getSeriesCmd = conn.CreateCommand())
|
using (IDbCommand getSeriesCmd = conn.CreateCommand())
|
||||||
{
|
{
|
||||||
getSeriesCmd.Transaction = tran;
|
getSeriesCmd.Transaction = tran;
|
||||||
getSeriesCmd.CommandText = @"SELECT Id, Title, Year, TmdbId FROM Movies";
|
getSeriesCmd.CommandText = @"SELECT ""Id"", ""Title"", ""Year"", ""TmdbId"" FROM ""Movies""";
|
||||||
using (IDataReader seriesReader = getSeriesCmd.ExecuteReader())
|
using (IDataReader seriesReader = getSeriesCmd.ExecuteReader())
|
||||||
{
|
{
|
||||||
while (seriesReader.Read())
|
while (seriesReader.Read())
|
||||||
@ -32,7 +32,7 @@ private void SetTitleSlug(IDbConnection conn, IDbTransaction tran)
|
|||||||
using (IDbCommand updateCmd = conn.CreateCommand())
|
using (IDbCommand updateCmd = conn.CreateCommand())
|
||||||
{
|
{
|
||||||
updateCmd.Transaction = tran;
|
updateCmd.Transaction = tran;
|
||||||
updateCmd.CommandText = "UPDATE Movies SET TitleSlug = ? WHERE Id = ?";
|
updateCmd.CommandText = "UPDATE \"Movies\" SET \"TitleSlug\" = ? WHERE \"Id\" = ?";
|
||||||
updateCmd.AddParameter(titleSlug);
|
updateCmd.AddParameter(titleSlug);
|
||||||
updateCmd.AddParameter(id);
|
updateCmd.AddParameter(id);
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ private void SetTitleSlug(IDbConnection conn, IDbTransaction tran)
|
|||||||
using (IDbCommand getSeriesCmd = conn.CreateCommand())
|
using (IDbCommand getSeriesCmd = conn.CreateCommand())
|
||||||
{
|
{
|
||||||
getSeriesCmd.Transaction = tran;
|
getSeriesCmd.Transaction = tran;
|
||||||
getSeriesCmd.CommandText = @"SELECT Id, Value FROM Config WHERE Key = 'filedate'";
|
getSeriesCmd.CommandText = @"SELECT ""Id"", ""Value"" FROM ""Config"" WHERE ""Key"" = 'filedate'";
|
||||||
using (IDataReader seriesReader = getSeriesCmd.ExecuteReader())
|
using (IDataReader seriesReader = getSeriesCmd.ExecuteReader())
|
||||||
{
|
{
|
||||||
while (seriesReader.Read())
|
while (seriesReader.Read())
|
||||||
@ -30,7 +30,7 @@ private void SetTitleSlug(IDbConnection conn, IDbTransaction tran)
|
|||||||
using (IDbCommand updateCmd = conn.CreateCommand())
|
using (IDbCommand updateCmd = conn.CreateCommand())
|
||||||
{
|
{
|
||||||
updateCmd.Transaction = tran;
|
updateCmd.Transaction = tran;
|
||||||
updateCmd.CommandText = "UPDATE Config SET Value = 'Release' WHERE Id = ?";
|
updateCmd.CommandText = "UPDATE \"Config\" SET \"Value\" = 'Release' WHERE \"Id\" = ?";
|
||||||
updateCmd.AddParameter(id);
|
updateCmd.AddParameter(id);
|
||||||
|
|
||||||
updateCmd.ExecuteNonQuery();
|
updateCmd.ExecuteNonQuery();
|
||||||
|
@ -16,9 +16,9 @@ protected override void MainDbUpgrade()
|
|||||||
.WithColumn("Implementation").AsString()
|
.WithColumn("Implementation").AsString()
|
||||||
.WithColumn("ConfigContract").AsString().Nullable()
|
.WithColumn("ConfigContract").AsString().Nullable()
|
||||||
.WithColumn("Settings").AsString().Nullable()
|
.WithColumn("Settings").AsString().Nullable()
|
||||||
.WithColumn("EnableAuto").AsInt32()
|
.WithColumn("EnableAuto").AsBoolean()
|
||||||
.WithColumn("RootFolderPath").AsString()
|
.WithColumn("RootFolderPath").AsString()
|
||||||
.WithColumn("ShouldMonitor").AsInt32()
|
.WithColumn("ShouldMonitor").AsBoolean()
|
||||||
.WithColumn("ProfileId").AsInt32();
|
.WithColumn("ProfileId").AsInt32();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
using System.Data;
|
using System.Data;
|
||||||
using FluentMigrator;
|
using FluentMigrator;
|
||||||
using NzbDrone.Core.Datastore.Migration.Framework;
|
using NzbDrone.Core.Datastore.Migration.Framework;
|
||||||
|
|
||||||
@ -17,7 +17,7 @@ private void DeleteUniqueIndex(IDbConnection conn, IDbTransaction tran)
|
|||||||
using (IDbCommand getSeriesCmd = conn.CreateCommand())
|
using (IDbCommand getSeriesCmd = conn.CreateCommand())
|
||||||
{
|
{
|
||||||
getSeriesCmd.Transaction = tran;
|
getSeriesCmd.Transaction = tran;
|
||||||
getSeriesCmd.CommandText = @"DROP INDEX 'IX_Movies_ImdbId'";
|
getSeriesCmd.CommandText = @"DROP INDEX ""IX_Movies_ImdbId""";
|
||||||
|
|
||||||
getSeriesCmd.ExecuteNonQuery();
|
getSeriesCmd.ExecuteNonQuery();
|
||||||
}
|
}
|
||||||
|
@ -82,7 +82,7 @@ public void Commit()
|
|||||||
using (var updateProfileCmd = _connection.CreateCommand())
|
using (var updateProfileCmd = _connection.CreateCommand())
|
||||||
{
|
{
|
||||||
updateProfileCmd.Transaction = _transaction;
|
updateProfileCmd.Transaction = _transaction;
|
||||||
updateProfileCmd.CommandText = "UPDATE Profiles SET Name = ?, Cutoff = ?, Items = ?, Language = ? WHERE Id = ?";
|
updateProfileCmd.CommandText = "UPDATE \"Profiles\" SET \"Name\" = ?, \"Cutoff\" = ?, \"Items\" = ?, \"Language\" = ? WHERE \"Id\" = ?";
|
||||||
updateProfileCmd.AddParameter(profile.Name);
|
updateProfileCmd.AddParameter(profile.Name);
|
||||||
updateProfileCmd.AddParameter(profile.Cutoff);
|
updateProfileCmd.AddParameter(profile.Cutoff);
|
||||||
updateProfileCmd.AddParameter(profile.Items.ToJson());
|
updateProfileCmd.AddParameter(profile.Items.ToJson());
|
||||||
@ -187,7 +187,7 @@ public void UpdateQualityToQualityDefinition()
|
|||||||
using (var getDefinitions = _connection.CreateCommand())
|
using (var getDefinitions = _connection.CreateCommand())
|
||||||
{
|
{
|
||||||
getDefinitions.Transaction = _transaction;
|
getDefinitions.Transaction = _transaction;
|
||||||
getDefinitions.CommandText = @"SELECT Id, Quality FROM QualityDefinitions";
|
getDefinitions.CommandText = @"SELECT ""Id"", ""Quality"" FROM ""QualityDefinitions""";
|
||||||
|
|
||||||
using (var definitionsReader = getDefinitions.ExecuteReader())
|
using (var definitionsReader = getDefinitions.ExecuteReader())
|
||||||
{
|
{
|
||||||
@ -225,7 +225,7 @@ private List<Profile125> GetProfiles()
|
|||||||
using (var getProfilesCmd = _connection.CreateCommand())
|
using (var getProfilesCmd = _connection.CreateCommand())
|
||||||
{
|
{
|
||||||
getProfilesCmd.Transaction = _transaction;
|
getProfilesCmd.Transaction = _transaction;
|
||||||
getProfilesCmd.CommandText = @"SELECT Id, Name, Cutoff, Items, Language FROM Profiles";
|
getProfilesCmd.CommandText = @"SELECT ""Id"", ""Name"", ""Cutoff"", ""Items"", ""Language"" FROM ""Profiles""";
|
||||||
|
|
||||||
using (var profileReader = getProfilesCmd.ExecuteReader())
|
using (var profileReader = getProfilesCmd.ExecuteReader())
|
||||||
{
|
{
|
||||||
|
@ -8,7 +8,7 @@ public class rename_torrent_downloadstation : NzbDroneMigrationBase
|
|||||||
{
|
{
|
||||||
protected override void MainDbUpgrade()
|
protected override void MainDbUpgrade()
|
||||||
{
|
{
|
||||||
Execute.Sql("UPDATE DownloadClients SET Implementation = 'TorrentDownloadStation' WHERE Implementation = 'DownloadStation';");
|
Execute.Sql("UPDATE \"DownloadClients\" SET \"Implementation\" = 'TorrentDownloadStation' WHERE \"Implementation\" = 'DownloadStation';");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,12 +13,12 @@ protected override void MainDbUpgrade()
|
|||||||
{
|
{
|
||||||
if (!Schema.Schema("dbo").Table("NetImport").Column("MinimumAvailability").Exists())
|
if (!Schema.Schema("dbo").Table("NetImport").Column("MinimumAvailability").Exists())
|
||||||
{
|
{
|
||||||
Alter.Table("NetImport").AddColumn("MinimumAvailability").AsInt32().WithDefaultValue(MovieStatusType.Released);
|
Alter.Table("NetImport").AddColumn("MinimumAvailability").AsInt32().WithDefaultValue((int)MovieStatusType.Released);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Schema.Schema("dbo").Table("Movies").Column("MinimumAvailability").Exists())
|
if (!Schema.Schema("dbo").Table("Movies").Column("MinimumAvailability").Exists())
|
||||||
{
|
{
|
||||||
Alter.Table("Movies").AddColumn("MinimumAvailability").AsInt32().WithDefaultValue(MovieStatusType.Released);
|
Alter.Table("Movies").AddColumn("MinimumAvailability").AsInt32().WithDefaultValue((int)MovieStatusType.Released);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@ private void AddExisting(IDbConnection conn, IDbTransaction tran)
|
|||||||
using (IDbCommand getSeriesCmd = conn.CreateCommand())
|
using (IDbCommand getSeriesCmd = conn.CreateCommand())
|
||||||
{
|
{
|
||||||
getSeriesCmd.Transaction = tran;
|
getSeriesCmd.Transaction = tran;
|
||||||
getSeriesCmd.CommandText = @"SELECT Key, Value FROM Config WHERE Key = 'importexclusions'";
|
getSeriesCmd.CommandText = @"SELECT ""Key"", ""Value"" FROM ""Config"" WHERE ""Key"" = 'importexclusions'";
|
||||||
TextInfo textInfo = new CultureInfo("en-US", false).TextInfo;
|
TextInfo textInfo = new CultureInfo("en-US", false).TextInfo;
|
||||||
using (IDataReader seriesReader = getSeriesCmd.ExecuteReader())
|
using (IDataReader seriesReader = getSeriesCmd.ExecuteReader())
|
||||||
{
|
{
|
||||||
@ -48,7 +48,7 @@ private void AddExisting(IDbConnection conn, IDbTransaction tran)
|
|||||||
using (IDbCommand updateCmd = conn.CreateCommand())
|
using (IDbCommand updateCmd = conn.CreateCommand())
|
||||||
{
|
{
|
||||||
updateCmd.Transaction = tran;
|
updateCmd.Transaction = tran;
|
||||||
updateCmd.CommandText = "INSERT INTO ImportExclusions (tmdbid, MovieTitle) VALUES " + string.Join(", ", importExclusions);
|
updateCmd.CommandText = "INSERT INTO \"ImportExclusions\" (tmdbid, MovieTitle) VALUES " + string.Join(", ", importExclusions);
|
||||||
|
|
||||||
updateCmd.ExecuteNonQuery();
|
updateCmd.ExecuteNonQuery();
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ private void RenameUrlToBaseUrl(IDbConnection conn, IDbTransaction tran)
|
|||||||
using (var cmd = conn.CreateCommand())
|
using (var cmd = conn.CreateCommand())
|
||||||
{
|
{
|
||||||
cmd.Transaction = tran;
|
cmd.Transaction = tran;
|
||||||
cmd.CommandText = "SELECT Id, Settings FROM Indexers WHERE ConfigContract IN ('NewznabSettings', 'TorznabSettings', 'IPTorrentsSettings', 'OmgwtfnzbsSettings')";
|
cmd.CommandText = "SELECT \"Id\", \"Settings\" FROM \"Indexers\" WHERE \"ConfigContract\" IN ('NewznabSettings', 'TorznabSettings', 'IPTorrentsSettings', 'OmgwtfnzbsSettings')";
|
||||||
|
|
||||||
using (var reader = cmd.ExecuteReader())
|
using (var reader = cmd.ExecuteReader())
|
||||||
{
|
{
|
||||||
@ -42,7 +42,7 @@ private void RenameUrlToBaseUrl(IDbConnection conn, IDbTransaction tran)
|
|||||||
using (var updateCmd = conn.CreateCommand())
|
using (var updateCmd = conn.CreateCommand())
|
||||||
{
|
{
|
||||||
updateCmd.Transaction = tran;
|
updateCmd.Transaction = tran;
|
||||||
updateCmd.CommandText = "UPDATE Indexers SET Settings = ? WHERE Id = ?";
|
updateCmd.CommandText = "UPDATE \"Indexers\" SET \"Settings\" = ? WHERE \"Id\" = ?";
|
||||||
updateCmd.AddParameter(settings);
|
updateCmd.AddParameter(settings);
|
||||||
updateCmd.AddParameter(id);
|
updateCmd.AddParameter(id);
|
||||||
updateCmd.ExecuteNonQuery();
|
updateCmd.ExecuteNonQuery();
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
using System.Data;
|
using System.Data;
|
||||||
using FluentMigrator;
|
using FluentMigrator;
|
||||||
using NzbDrone.Core.Datastore.Migration.Framework;
|
using NzbDrone.Core.Datastore.Migration.Framework;
|
||||||
|
|
||||||
@ -9,16 +9,16 @@ public class fix_duplicate_alt_titles : NzbDroneMigrationBase
|
|||||||
{
|
{
|
||||||
protected override void MainDbUpgrade()
|
protected override void MainDbUpgrade()
|
||||||
{
|
{
|
||||||
Execute.WithConnection(RenameUrlToBaseUrl);
|
Execute.WithConnection(RemoveDuplicateAlternateTitles);
|
||||||
Alter.Table("AlternativeTitles").AlterColumn("CleanTitle").AsString().Unique();
|
Alter.Table("AlternativeTitles").AlterColumn("CleanTitle").AsString().Unique();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void RenameUrlToBaseUrl(IDbConnection conn, IDbTransaction tran)
|
private void RemoveDuplicateAlternateTitles(IDbConnection conn, IDbTransaction tran)
|
||||||
{
|
{
|
||||||
using (var cmd = conn.CreateCommand())
|
using (var cmd = conn.CreateCommand())
|
||||||
{
|
{
|
||||||
cmd.Transaction = tran;
|
cmd.Transaction = tran;
|
||||||
cmd.CommandText = "DELETE FROM AlternativeTitles WHERE rowid NOT IN ( SELECT MIN(rowid) FROM AlternativeTitles GROUP BY CleanTitle )";
|
cmd.CommandText = "DELETE FROM \"AlternativeTitles\" WHERE \"Id\" NOT IN (Select Min(\"Id\") From \"AlternativeTitles\" Group By \"CleanTitle\")";
|
||||||
|
|
||||||
cmd.ExecuteNonQuery();
|
cmd.ExecuteNonQuery();
|
||||||
}
|
}
|
||||||
|
@ -8,10 +8,10 @@ public class banner_to_fanart : NzbDroneMigrationBase
|
|||||||
{
|
{
|
||||||
protected override void MainDbUpgrade()
|
protected override void MainDbUpgrade()
|
||||||
{
|
{
|
||||||
Execute.Sql("UPDATE Movies SET Images = replace(Images, \'\"coverType\": \"banner\"\', \'\"coverType\": \"fanart\"\')");
|
Execute.Sql("UPDATE \"Movies\" SET \"Images\" = replace(\"Images\", \'\"coverType\": \"banner\"\', \'\"coverType\": \"fanart\"\')");
|
||||||
|
|
||||||
// Remove Link for images to specific MovieFiles, Images are now related to the Movie object only
|
// Remove Link for images to specific MovieFiles, Images are now related to the Movie object only
|
||||||
Execute.Sql("UPDATE MetadataFiles SET MovieFileId = null WHERE Type = 2");
|
Execute.Sql("UPDATE \"MetadataFiles\" SET \"MovieFileId\" = null WHERE \"Type\" = 2");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ public class remove_extra_naming_config : NzbDroneMigrationBase
|
|||||||
protected override void MainDbUpgrade()
|
protected override void MainDbUpgrade()
|
||||||
{
|
{
|
||||||
// Remove all but 1 NamingConfig
|
// Remove all but 1 NamingConfig
|
||||||
Execute.Sql("DELETE FROM NamingConfig WHERE ID NOT IN(SELECT ID FROM NamingConfig LIMIT 1)");
|
Execute.Sql("DELETE FROM \"NamingConfig\" WHERE \"Id\" NOT IN(SELECT \"Id\" FROM \"NamingConfig\" LIMIT 1)");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -82,7 +82,15 @@ public void Commit()
|
|||||||
using (var updateProfileCmd = _connection.CreateCommand())
|
using (var updateProfileCmd = _connection.CreateCommand())
|
||||||
{
|
{
|
||||||
updateProfileCmd.Transaction = _transaction;
|
updateProfileCmd.Transaction = _transaction;
|
||||||
updateProfileCmd.CommandText = "UPDATE CustomFormats SET Name = ?, FormatTags = ? WHERE Id = ?";
|
if (_connection.GetType().FullName == "Npgsql.NpgsqlConnection")
|
||||||
|
{
|
||||||
|
updateProfileCmd.CommandText = "UPDATE \"CustomFormats\" SET \"Name\" = $1, \"FormatTags\" = $2 WHERE \"Id\" = $3";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
updateProfileCmd.CommandText = "UPDATE \"CustomFormats\" SET \"Name\" = ?, \"FormatTags\" = ? WHERE \"Id\" = ?";
|
||||||
|
}
|
||||||
|
|
||||||
updateProfileCmd.AddParameter(profile.Name);
|
updateProfileCmd.AddParameter(profile.Name);
|
||||||
updateProfileCmd.AddParameter(profile.FormatTags.ToJson());
|
updateProfileCmd.AddParameter(profile.FormatTags.ToJson());
|
||||||
updateProfileCmd.AddParameter(profile.Id);
|
updateProfileCmd.AddParameter(profile.Id);
|
||||||
@ -119,7 +127,7 @@ private List<CustomFormat149> GetFormats()
|
|||||||
using (var getProfilesCmd = _connection.CreateCommand())
|
using (var getProfilesCmd = _connection.CreateCommand())
|
||||||
{
|
{
|
||||||
getProfilesCmd.Transaction = _transaction;
|
getProfilesCmd.Transaction = _transaction;
|
||||||
getProfilesCmd.CommandText = @"SELECT Id, Name, FormatTags FROM CustomFormats";
|
getProfilesCmd.CommandText = @"SELECT ""Id"", ""Name"", ""FormatTags"" FROM ""CustomFormats""";
|
||||||
|
|
||||||
using (var profileReader = getProfilesCmd.ExecuteReader())
|
using (var profileReader = getProfilesCmd.ExecuteReader())
|
||||||
{
|
{
|
||||||
|
@ -11,7 +11,7 @@ protected override void MainDbUpgrade()
|
|||||||
Alter.Table("NetImport")
|
Alter.Table("NetImport")
|
||||||
.AddColumn("Tags").AsString().Nullable();
|
.AddColumn("Tags").AsString().Nullable();
|
||||||
|
|
||||||
Execute.Sql("UPDATE NetImport SET Tags = '[]'");
|
Execute.Sql("UPDATE \"NetImport\" SET \"Tags\" = '[]'");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ protected override void MainDbUpgrade()
|
|||||||
Rename.Column("EnableSearch").OnTable("Indexers").To("EnableAutomaticSearch");
|
Rename.Column("EnableSearch").OnTable("Indexers").To("EnableAutomaticSearch");
|
||||||
Alter.Table("Indexers").AddColumn("EnableInteractiveSearch").AsBoolean().Nullable();
|
Alter.Table("Indexers").AddColumn("EnableInteractiveSearch").AsBoolean().Nullable();
|
||||||
|
|
||||||
Execute.Sql("UPDATE Indexers SET EnableInteractiveSearch = EnableAutomaticSearch");
|
Execute.Sql("UPDATE \"Indexers\" SET \"EnableInteractiveSearch\" = \"EnableAutomaticSearch\"");
|
||||||
|
|
||||||
Alter.Table("Indexers").AlterColumn("EnableInteractiveSearch").AsBoolean().NotNullable();
|
Alter.Table("Indexers").AlterColumn("EnableInteractiveSearch").AsBoolean().NotNullable();
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ private void UpdateLanguage(IDbConnection conn, IDbTransaction tran)
|
|||||||
using (IDbCommand getProfileCmd = conn.CreateCommand())
|
using (IDbCommand getProfileCmd = conn.CreateCommand())
|
||||||
{
|
{
|
||||||
getProfileCmd.Transaction = tran;
|
getProfileCmd.Transaction = tran;
|
||||||
getProfileCmd.CommandText = "SELECT Id, Language FROM Profiles";
|
getProfileCmd.CommandText = "SELECT \"Id\", \"Language\" FROM \"Profiles\"";
|
||||||
|
|
||||||
IDataReader profilesReader = getProfileCmd.ExecuteReader();
|
IDataReader profilesReader = getProfileCmd.ExecuteReader();
|
||||||
while (profilesReader.Read())
|
while (profilesReader.Read())
|
||||||
@ -59,6 +59,8 @@ private void UpdateLanguage(IDbConnection conn, IDbTransaction tran)
|
|||||||
|
|
||||||
profileLanguages[profileId] = movieLanguage;
|
profileLanguages[profileId] = movieLanguage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
profilesReader.Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
var movieLanguages = new Dictionary<int, int>();
|
var movieLanguages = new Dictionary<int, int>();
|
||||||
@ -66,7 +68,7 @@ private void UpdateLanguage(IDbConnection conn, IDbTransaction tran)
|
|||||||
using (IDbCommand getSeriesCmd = conn.CreateCommand())
|
using (IDbCommand getSeriesCmd = conn.CreateCommand())
|
||||||
{
|
{
|
||||||
getSeriesCmd.Transaction = tran;
|
getSeriesCmd.Transaction = tran;
|
||||||
getSeriesCmd.CommandText = @"SELECT Id, ProfileId FROM Movies";
|
getSeriesCmd.CommandText = @"SELECT ""Id"", ""ProfileId"" FROM ""Movies""";
|
||||||
using (IDataReader moviesReader = getSeriesCmd.ExecuteReader())
|
using (IDataReader moviesReader = getSeriesCmd.ExecuteReader())
|
||||||
{
|
{
|
||||||
while (moviesReader.Read())
|
while (moviesReader.Read())
|
||||||
@ -76,6 +78,8 @@ private void UpdateLanguage(IDbConnection conn, IDbTransaction tran)
|
|||||||
|
|
||||||
movieLanguages[movieId] = profileLanguages.GetValueOrDefault(movieProfileId, Language.English.Id);
|
movieLanguages[movieId] = profileLanguages.GetValueOrDefault(movieProfileId, Language.English.Id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
moviesReader.Close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,7 +89,7 @@ private void UpdateLanguage(IDbConnection conn, IDbTransaction tran)
|
|||||||
using (IDbCommand getSeriesCmd = conn.CreateCommand())
|
using (IDbCommand getSeriesCmd = conn.CreateCommand())
|
||||||
{
|
{
|
||||||
getSeriesCmd.Transaction = tran;
|
getSeriesCmd.Transaction = tran;
|
||||||
getSeriesCmd.CommandText = @"SELECT Id, MovieId, SceneName, MediaInfo FROM MovieFiles";
|
getSeriesCmd.CommandText = @"SELECT ""Id"", ""MovieId"", ""SceneName"", ""MediaInfo"" FROM ""MovieFiles""";
|
||||||
using (IDataReader movieFilesReader = getSeriesCmd.ExecuteReader())
|
using (IDataReader movieFilesReader = getSeriesCmd.ExecuteReader())
|
||||||
{
|
{
|
||||||
while (movieFilesReader.Read())
|
while (movieFilesReader.Read())
|
||||||
@ -125,6 +129,8 @@ private void UpdateLanguage(IDbConnection conn, IDbTransaction tran)
|
|||||||
|
|
||||||
movieFileLanguages[movieFileId] = languages;
|
movieFileLanguages[movieFileId] = languages;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
movieFilesReader.Close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,7 +139,7 @@ private void UpdateLanguage(IDbConnection conn, IDbTransaction tran)
|
|||||||
using (IDbCommand getSeriesCmd = conn.CreateCommand())
|
using (IDbCommand getSeriesCmd = conn.CreateCommand())
|
||||||
{
|
{
|
||||||
getSeriesCmd.Transaction = tran;
|
getSeriesCmd.Transaction = tran;
|
||||||
getSeriesCmd.CommandText = @"SELECT Id, SourceTitle, MovieId FROM History";
|
getSeriesCmd.CommandText = @"SELECT ""Id"", ""SourceTitle"", ""MovieId"" FROM ""History""";
|
||||||
using (IDataReader historyReader = getSeriesCmd.ExecuteReader())
|
using (IDataReader historyReader = getSeriesCmd.ExecuteReader())
|
||||||
{
|
{
|
||||||
while (historyReader.Read())
|
while (historyReader.Read())
|
||||||
@ -160,6 +166,8 @@ private void UpdateLanguage(IDbConnection conn, IDbTransaction tran)
|
|||||||
|
|
||||||
historyLanguages[historyId] = languages;
|
historyLanguages[historyId] = languages;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
historyReader.Close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -168,7 +176,7 @@ private void UpdateLanguage(IDbConnection conn, IDbTransaction tran)
|
|||||||
using (IDbCommand getSeriesCmd = conn.CreateCommand())
|
using (IDbCommand getSeriesCmd = conn.CreateCommand())
|
||||||
{
|
{
|
||||||
getSeriesCmd.Transaction = tran;
|
getSeriesCmd.Transaction = tran;
|
||||||
getSeriesCmd.CommandText = @"SELECT Id, SourceTitle, MovieId FROM Blacklist";
|
getSeriesCmd.CommandText = @"SELECT ""Id"", ""SourceTitle"", ""MovieId"" FROM ""Blacklist""";
|
||||||
using (IDataReader blacklistReader = getSeriesCmd.ExecuteReader())
|
using (IDataReader blacklistReader = getSeriesCmd.ExecuteReader())
|
||||||
{
|
{
|
||||||
while (blacklistReader.Read())
|
while (blacklistReader.Read())
|
||||||
@ -190,6 +198,8 @@ private void UpdateLanguage(IDbConnection conn, IDbTransaction tran)
|
|||||||
|
|
||||||
blacklistLanguages[blacklistId] = languages;
|
blacklistLanguages[blacklistId] = languages;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
blacklistReader.Close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -202,7 +212,15 @@ private void UpdateLanguage(IDbConnection conn, IDbTransaction tran)
|
|||||||
using (IDbCommand updateMovieFilesCmd = conn.CreateCommand())
|
using (IDbCommand updateMovieFilesCmd = conn.CreateCommand())
|
||||||
{
|
{
|
||||||
updateMovieFilesCmd.Transaction = tran;
|
updateMovieFilesCmd.Transaction = tran;
|
||||||
updateMovieFilesCmd.CommandText = $"UPDATE MovieFiles SET Languages = ? WHERE Id IN ({movieFileIds})";
|
if (conn.GetType().FullName == "Npgsql.NpgsqlConnection")
|
||||||
|
{
|
||||||
|
updateMovieFilesCmd.CommandText = $"UPDATE \"MovieFiles\" SET \"Languages\" = $1 WHERE \"Id\" IN ({movieFileIds})";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
updateMovieFilesCmd.CommandText = $"UPDATE \"MovieFiles\" SET \"Languages\" = ? WHERE \"Id\" IN ({movieFileIds})";
|
||||||
|
}
|
||||||
|
|
||||||
var param = updateMovieFilesCmd.CreateParameter();
|
var param = updateMovieFilesCmd.CreateParameter();
|
||||||
languageConverter.SetValue(param, languages);
|
languageConverter.SetValue(param, languages);
|
||||||
updateMovieFilesCmd.Parameters.Add(param);
|
updateMovieFilesCmd.Parameters.Add(param);
|
||||||
@ -220,7 +238,15 @@ private void UpdateLanguage(IDbConnection conn, IDbTransaction tran)
|
|||||||
using (IDbCommand updateHistoryCmd = conn.CreateCommand())
|
using (IDbCommand updateHistoryCmd = conn.CreateCommand())
|
||||||
{
|
{
|
||||||
updateHistoryCmd.Transaction = tran;
|
updateHistoryCmd.Transaction = tran;
|
||||||
updateHistoryCmd.CommandText = $"UPDATE History SET Languages = ? WHERE Id IN ({historyIds})";
|
if (conn.GetType().FullName == "Npgsql.NpgsqlConnection")
|
||||||
|
{
|
||||||
|
updateHistoryCmd.CommandText = $"UPDATE \"History\" SET \"Languages\" = $1 WHERE \"Id\" IN ({historyIds})";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
updateHistoryCmd.CommandText = $"UPDATE \"History\" SET \"Languages\" = ? WHERE \"Id\" IN ({historyIds})";
|
||||||
|
}
|
||||||
|
|
||||||
var param = updateHistoryCmd.CreateParameter();
|
var param = updateHistoryCmd.CreateParameter();
|
||||||
languageConverter.SetValue(param, languages);
|
languageConverter.SetValue(param, languages);
|
||||||
updateHistoryCmd.Parameters.Add(param);
|
updateHistoryCmd.Parameters.Add(param);
|
||||||
@ -238,7 +264,15 @@ private void UpdateLanguage(IDbConnection conn, IDbTransaction tran)
|
|||||||
using (IDbCommand updateBlacklistCmd = conn.CreateCommand())
|
using (IDbCommand updateBlacklistCmd = conn.CreateCommand())
|
||||||
{
|
{
|
||||||
updateBlacklistCmd.Transaction = tran;
|
updateBlacklistCmd.Transaction = tran;
|
||||||
updateBlacklistCmd.CommandText = $"UPDATE Blacklist SET Languages = ? WHERE Id IN ({blacklistIds})";
|
if (conn.GetType().FullName == "Npgsql.NpgsqlConnection")
|
||||||
|
{
|
||||||
|
updateBlacklistCmd.CommandText = $"UPDATE \"Blacklist\" SET \"Languages\" = $1 WHERE \"Id\" IN ({blacklistIds})";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
updateBlacklistCmd.CommandText = $"UPDATE \"Blacklist\" SET \"Languages\" = ? WHERE \"Id\" IN ({blacklistIds})";
|
||||||
|
}
|
||||||
|
|
||||||
var param = updateBlacklistCmd.CreateParameter();
|
var param = updateBlacklistCmd.CreateParameter();
|
||||||
languageConverter.SetValue(param, languages);
|
languageConverter.SetValue(param, languages);
|
||||||
updateBlacklistCmd.Parameters.Add(param);
|
updateBlacklistCmd.Parameters.Add(param);
|
||||||
|
@ -8,7 +8,7 @@ public class add_update_allowed_quality_profile : NzbDroneMigrationBase
|
|||||||
{
|
{
|
||||||
protected override void MainDbUpgrade()
|
protected override void MainDbUpgrade()
|
||||||
{
|
{
|
||||||
Alter.Table("Profiles").AddColumn("UpgradeAllowed").AsInt32().Nullable();
|
Alter.Table("Profiles").AddColumn("UpgradeAllowed").AsBoolean().Nullable();
|
||||||
|
|
||||||
// Set upgrade allowed for existing profiles (default will be false for new profiles)
|
// Set upgrade allowed for existing profiles (default will be false for new profiles)
|
||||||
Update.Table("Profiles").Set(new { UpgradeAllowed = true }).AllRows();
|
Update.Table("Profiles").Set(new { UpgradeAllowed = true }).AllRows();
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
|
using System.Linq;
|
||||||
|
using Dapper;
|
||||||
using FluentMigrator;
|
using FluentMigrator;
|
||||||
using NzbDrone.Core.Datastore.Migration.Framework;
|
using NzbDrone.Core.Datastore.Migration.Framework;
|
||||||
|
|
||||||
@ -22,37 +24,46 @@ protected override void MainDbUpgrade()
|
|||||||
|
|
||||||
private void InitPriorityForBackwardCompatibility(IDbConnection conn, IDbTransaction tran)
|
private void InitPriorityForBackwardCompatibility(IDbConnection conn, IDbTransaction tran)
|
||||||
{
|
{
|
||||||
using (var cmd = conn.CreateCommand())
|
var downloadClients = conn.Query<DownloadClients156>($"SELECT \"Id\", \"Implementation\" FROM \"DownloadClients\" WHERE \"Enable\"");
|
||||||
|
|
||||||
|
if (!downloadClients.Any())
|
||||||
{
|
{
|
||||||
cmd.Transaction = tran;
|
return;
|
||||||
cmd.CommandText = "SELECT Id, Implementation FROM DownloadClients WHERE Enable = 1";
|
}
|
||||||
|
|
||||||
using (var reader = cmd.ExecuteReader())
|
var nextUsenet = 1;
|
||||||
|
var nextTorrent = 1;
|
||||||
|
|
||||||
|
foreach (var downloadClient in downloadClients)
|
||||||
|
{
|
||||||
|
var isUsenet = _usenetImplementations.Contains(downloadClient.Implementation);
|
||||||
|
using (var updateCmd = conn.CreateCommand())
|
||||||
{
|
{
|
||||||
int nextUsenet = 1;
|
updateCmd.Transaction = tran;
|
||||||
int nextTorrent = 1;
|
if (conn.GetType().FullName == "Npgsql.NpgsqlConnection")
|
||||||
while (reader.Read())
|
|
||||||
{
|
{
|
||||||
var id = reader.GetInt32(0);
|
updateCmd.CommandText = "UPDATE \"DownloadClients\" SET \"Priority\" = $1 WHERE \"Id\" = $2";
|
||||||
var implName = reader.GetString(1);
|
|
||||||
|
|
||||||
var isUsenet = _usenetImplementations.Contains(implName);
|
|
||||||
|
|
||||||
using (var updateCmd = conn.CreateCommand())
|
|
||||||
{
|
|
||||||
updateCmd.Transaction = tran;
|
|
||||||
updateCmd.CommandText = "UPDATE DownloadClients SET Priority = ? WHERE Id = ?";
|
|
||||||
updateCmd.AddParameter(isUsenet ? nextUsenet++ : nextTorrent++);
|
|
||||||
updateCmd.AddParameter(id);
|
|
||||||
|
|
||||||
updateCmd.ExecuteNonQuery();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
updateCmd.CommandText = "UPDATE \"DownloadClients\" SET \"Priority\" = ? WHERE \"Id\" = ?";
|
||||||
|
}
|
||||||
|
|
||||||
|
updateCmd.AddParameter(isUsenet ? nextUsenet++ : nextTorrent++);
|
||||||
|
updateCmd.AddParameter(downloadClient.Id);
|
||||||
|
|
||||||
|
updateCmd.ExecuteNonQuery();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class DownloadClients156
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
public string Implementation { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
public class DelugeSettings156
|
public class DelugeSettings156
|
||||||
{
|
{
|
||||||
public string Host { get; set; }
|
public string Host { get; set; }
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using FluentMigrator;
|
using FluentMigrator;
|
||||||
@ -76,8 +76,16 @@ public void Commit()
|
|||||||
using (var updateProfileCmd = _connection.CreateCommand())
|
using (var updateProfileCmd = _connection.CreateCommand())
|
||||||
{
|
{
|
||||||
updateProfileCmd.Transaction = _transaction;
|
updateProfileCmd.Transaction = _transaction;
|
||||||
updateProfileCmd.CommandText =
|
|
||||||
"UPDATE Profiles SET Name = ?, Cutoff = ?, Items = ? WHERE Id = ?";
|
if (_connection.GetType().FullName == "Npgsql.NpgsqlConnection")
|
||||||
|
{
|
||||||
|
updateProfileCmd.CommandText = "UPDATE \"Profiles\" SET \"Name\" = $1, \"Cutoff\" = $2, \"Items\" = $3 WHERE \"Id\" = $4";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
updateProfileCmd.CommandText = "UPDATE \"Profiles\" SET \"Name\" = ?, \"Cutoff\" = ?, \"Items\" = ? WHERE \"Id\" = ?";
|
||||||
|
}
|
||||||
|
|
||||||
updateProfileCmd.AddParameter(profile.Name);
|
updateProfileCmd.AddParameter(profile.Name);
|
||||||
updateProfileCmd.AddParameter(profile.Cutoff);
|
updateProfileCmd.AddParameter(profile.Cutoff);
|
||||||
updateProfileCmd.AddParameter(profile.Items.ToJson());
|
updateProfileCmd.AddParameter(profile.Items.ToJson());
|
||||||
@ -219,7 +227,7 @@ private List<Profile159> GetProfiles()
|
|||||||
using (var getProfilesCmd = _connection.CreateCommand())
|
using (var getProfilesCmd = _connection.CreateCommand())
|
||||||
{
|
{
|
||||||
getProfilesCmd.Transaction = _transaction;
|
getProfilesCmd.Transaction = _transaction;
|
||||||
getProfilesCmd.CommandText = @"SELECT Id, Name, Cutoff, Items FROM Profiles";
|
getProfilesCmd.CommandText = @"SELECT ""Id"", ""Name"", ""Cutoff"", ""Items"" FROM ""Profiles""";
|
||||||
|
|
||||||
using (var profileReader = getProfilesCmd.ExecuteReader())
|
using (var profileReader = getProfilesCmd.ExecuteReader())
|
||||||
{
|
{
|
||||||
|
@ -8,8 +8,8 @@ public class health_issue_notification : NzbDroneMigrationBase
|
|||||||
{
|
{
|
||||||
protected override void MainDbUpgrade()
|
protected override void MainDbUpgrade()
|
||||||
{
|
{
|
||||||
Alter.Table("Notifications").AddColumn("OnHealthIssue").AsBoolean().WithDefaultValue(0);
|
Alter.Table("Notifications").AddColumn("OnHealthIssue").AsBoolean().WithDefaultValue(false);
|
||||||
Alter.Table("Notifications").AddColumn("IncludeHealthWarnings").AsBoolean().WithDefaultValue(0);
|
Alter.Table("Notifications").AddColumn("IncludeHealthWarnings").AsBoolean().WithDefaultValue(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,7 @@ private void FixPendingReleases(IDbConnection conn, IDbTransaction tran)
|
|||||||
{
|
{
|
||||||
SqlMapper.AddTypeHandler(new EmbeddedDocumentConverter<ParsedMovieInfo164>());
|
SqlMapper.AddTypeHandler(new EmbeddedDocumentConverter<ParsedMovieInfo164>());
|
||||||
SqlMapper.AddTypeHandler(new EmbeddedDocumentConverter<ParsedMovieInfo165>());
|
SqlMapper.AddTypeHandler(new EmbeddedDocumentConverter<ParsedMovieInfo165>());
|
||||||
var rows = conn.Query<ParsedMovieInfoData164>("SELECT Id, ParsedMovieInfo from PendingReleases");
|
var rows = conn.Query<ParsedMovieInfoData164>("SELECT \"Id\", \"ParsedMovieInfo\" from \"PendingReleases\"");
|
||||||
|
|
||||||
var newRows = new List<ParsedMovieInfoData165>();
|
var newRows = new List<ParsedMovieInfoData165>();
|
||||||
|
|
||||||
@ -76,26 +76,26 @@ private void FixPendingReleases(IDbConnection conn, IDbTransaction tran)
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
var sql = $"UPDATE PendingReleases SET ParsedMovieInfo = @ParsedMovieInfo WHERE Id = @Id";
|
var sql = $"UPDATE \"PendingReleases\" SET \"ParsedMovieInfo\" = @ParsedMovieInfo WHERE \"Id\" = @Id";
|
||||||
|
|
||||||
conn.Execute(sql, newRows, transaction: tran);
|
conn.Execute(sql, newRows, transaction: tran);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void RemoveCustomFormatFromQuality(IDbConnection conn, IDbTransaction tran, string table)
|
private void RemoveCustomFormatFromQuality(IDbConnection conn, IDbTransaction tran, string table)
|
||||||
{
|
{
|
||||||
var rows = conn.Query<QualityRow>($"SELECT Id, Quality from {table}");
|
var rows = conn.Query<QualityRow>($"SELECT \"Id\", \"Quality\" from \"{table}\"");
|
||||||
|
|
||||||
var sql = $"UPDATE {table} SET Quality = @Quality WHERE Id = @Id";
|
var sql = $"UPDATE \"{table}\" SET \"Quality\" = @Quality WHERE \"Id\" = @Id";
|
||||||
|
|
||||||
conn.Execute(sql, rows, transaction: tran);
|
conn.Execute(sql, rows, transaction: tran);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AddIndexerFlagsToBlacklist(IDbConnection conn, IDbTransaction tran)
|
private void AddIndexerFlagsToBlacklist(IDbConnection conn, IDbTransaction tran)
|
||||||
{
|
{
|
||||||
var blacklists = conn.Query<BlacklistData>("SELECT Blacklist.Id, Blacklist.TorrentInfoHash, History.Data " +
|
var blacklists = conn.Query<BlacklistData>("SELECT \"Blacklist\".\"Id\", \"Blacklist\".\"TorrentInfoHash\", \"History\".\"Data\" " +
|
||||||
"FROM Blacklist " +
|
"FROM \"Blacklist\" " +
|
||||||
"JOIN History ON Blacklist.MovieId = History.MovieId " +
|
"JOIN \"History\" ON \"Blacklist\".\"MovieId\" = \"History\".\"MovieId\" " +
|
||||||
"WHERE History.EventType = 1");
|
"WHERE \"History\".\"EventType\" = 1");
|
||||||
|
|
||||||
var toUpdate = new List<IndexerFlagsItem>();
|
var toUpdate = new List<IndexerFlagsItem>();
|
||||||
|
|
||||||
@ -117,16 +117,16 @@ private void AddIndexerFlagsToBlacklist(IDbConnection conn, IDbTransaction tran)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var updateSql = "UPDATE Blacklist SET IndexerFlags = @IndexerFlags WHERE Id = @Id";
|
var updateSql = "UPDATE \"Blacklist\" SET \"IndexerFlags\" = @IndexerFlags WHERE \"Id\" = @Id";
|
||||||
conn.Execute(updateSql, toUpdate, transaction: tran);
|
conn.Execute(updateSql, toUpdate, transaction: tran);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AddIndexerFlagsToMovieFiles(IDbConnection conn, IDbTransaction tran)
|
private void AddIndexerFlagsToMovieFiles(IDbConnection conn, IDbTransaction tran)
|
||||||
{
|
{
|
||||||
var movieFiles = conn.Query<MovieFileData>("SELECT MovieFiles.Id, MovieFiles.SceneName, History.SourceTitle, History.Data " +
|
var movieFiles = conn.Query<MovieFileData>("SELECT \"MovieFiles\".\"Id\", \"MovieFiles\".\"SceneName\", \"History\".\"SourceTitle\", \"History\".\"Data\" " +
|
||||||
"FROM MovieFiles " +
|
"FROM \"MovieFiles\" " +
|
||||||
"JOIN History ON MovieFiles.MovieId = History.MovieId " +
|
"JOIN \"History\" ON \"MovieFiles\".\"MovieId\" = \"History\".\"MovieId\" " +
|
||||||
"WHERE History.EventType = 1");
|
"WHERE \"History\".\"EventType\" = 1");
|
||||||
|
|
||||||
var toUpdate = new List<IndexerFlagsItem>();
|
var toUpdate = new List<IndexerFlagsItem>();
|
||||||
|
|
||||||
@ -148,7 +148,7 @@ private void AddIndexerFlagsToMovieFiles(IDbConnection conn, IDbTransaction tran
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var updateSql = "UPDATE MovieFiles SET IndexerFlags = @IndexerFlags WHERE Id = @Id";
|
var updateSql = "UPDATE \"MovieFiles\" SET \"IndexerFlags\" = @IndexerFlags WHERE \"Id\" = @Id";
|
||||||
conn.Execute(updateSql, toUpdate, transaction: tran);
|
conn.Execute(updateSql, toUpdate, transaction: tran);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ protected override void MainDbUpgrade()
|
|||||||
|
|
||||||
private void RenameTMDbListType(IDbConnection conn, IDbTransaction tran)
|
private void RenameTMDbListType(IDbConnection conn, IDbTransaction tran)
|
||||||
{
|
{
|
||||||
var rows = conn.Query<ProviderDefinition166>($"SELECT Id, Implementation, ConfigContract, Settings FROM NetImport WHERE Implementation = 'TMDbPopularImport'");
|
var rows = conn.Query<ProviderDefinition166>($"SELECT \"Id\", \"Implementation\", \"ConfigContract\", \"Settings\" FROM \"NetImport\" WHERE \"Implementation\" = 'TMDbPopularImport'");
|
||||||
|
|
||||||
var corrected = new List<ProviderDefinition166>();
|
var corrected = new List<ProviderDefinition166>();
|
||||||
|
|
||||||
@ -71,13 +71,13 @@ private void RenameTMDbListType(IDbConnection conn, IDbTransaction tran)
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
var updateSql = "UPDATE NetImport SET Settings = @Settings WHERE Id = @Id";
|
var updateSql = "UPDATE \"NetImport\" SET \"Settings\" = @Settings WHERE \"Id\" = @Id";
|
||||||
conn.Execute(updateSql, corrected, transaction: tran);
|
conn.Execute(updateSql, corrected, transaction: tran);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void RenameTraktListType(IDbConnection conn, IDbTransaction tran)
|
private void RenameTraktListType(IDbConnection conn, IDbTransaction tran)
|
||||||
{
|
{
|
||||||
var rows = conn.Query<ProviderDefinition166>($"SELECT Id, Implementation, ConfigContract, Settings FROM NetImport WHERE Implementation = 'TraktImport'");
|
var rows = conn.Query<ProviderDefinition166>($"SELECT \"Id\", \"Implementation\", \"ConfigContract\", \"Settings\" FROM \"NetImport\" WHERE \"Implementation\" = 'TraktImport'");
|
||||||
|
|
||||||
var corrected = new List<ProviderDefinition166>();
|
var corrected = new List<ProviderDefinition166>();
|
||||||
|
|
||||||
@ -112,13 +112,13 @@ private void RenameTraktListType(IDbConnection conn, IDbTransaction tran)
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
var updateSql = "UPDATE NetImport SET Settings = @Settings WHERE Id = @Id";
|
var updateSql = "UPDATE \"NetImport\" SET \"Settings\" = @Settings WHERE \"Id\" = @Id";
|
||||||
conn.Execute(updateSql, corrected, transaction: tran);
|
conn.Execute(updateSql, corrected, transaction: tran);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void FixConfig(IDbConnection conn, IDbTransaction tran)
|
private void FixConfig(IDbConnection conn, IDbTransaction tran)
|
||||||
{
|
{
|
||||||
var rows = conn.Query<ProviderDefinition166>($"SELECT Id, Implementation, ConfigContract, Settings FROM NetImport WHERE Implementation = 'TMDbImport'");
|
var rows = conn.Query<ProviderDefinition166>($"SELECT \"Id\", \"Implementation\", \"ConfigContract\", \"Settings\" FROM \"NetImport\" WHERE \"Implementation\" = 'TMDbImport'");
|
||||||
|
|
||||||
var corrected = new List<ProviderDefinition166>();
|
var corrected = new List<ProviderDefinition166>();
|
||||||
|
|
||||||
@ -167,7 +167,7 @@ private void FixConfig(IDbConnection conn, IDbTransaction tran)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var updateSql = "UPDATE NetImport SET Implementation = @Implementation, ConfigContract = @ConfigContract, Settings = @Settings WHERE Id = @Id";
|
var updateSql = "UPDATE \"NetImport\" SET \"Implementation\" = @Implementation, \"ConfigContract\" = @ConfigContract, \"Settings\" = @Settings WHERE \"Id\" = @Id";
|
||||||
conn.Execute(updateSql, corrected, transaction: tran);
|
conn.Execute(updateSql, corrected, transaction: tran);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ protected override void MainDbUpgrade()
|
|||||||
{
|
{
|
||||||
Delete.Column("PathState").FromTable("Movies");
|
Delete.Column("PathState").FromTable("Movies");
|
||||||
|
|
||||||
Execute.Sql("DELETE FROM Config WHERE [KEY] IN ('pathsdefaultstatic')");
|
Execute.Sql("DELETE FROM \"Config\" WHERE \"Key\" IN ('pathsdefaultstatic')");
|
||||||
|
|
||||||
Alter.Table("MovieFiles").AddColumn("OriginalFilePath").AsString().Nullable();
|
Alter.Table("MovieFiles").AddColumn("OriginalFilePath").AsString().Nullable();
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ protected override void MainDbUpgrade()
|
|||||||
|
|
||||||
private void UpdateCustomFormats(IDbConnection conn, IDbTransaction tran)
|
private void UpdateCustomFormats(IDbConnection conn, IDbTransaction tran)
|
||||||
{
|
{
|
||||||
var existing = conn.Query<FormatTag167>("SELECT Id, Name, FormatTags FROM CustomFormats");
|
var existing = conn.Query<FormatTag167>("SELECT \"Id\", \"Name\", \"FormatTags\" FROM \"CustomFormats\"");
|
||||||
|
|
||||||
var updated = new List<Specification168>();
|
var updated = new List<Specification168>();
|
||||||
|
|
||||||
@ -66,7 +66,7 @@ private void UpdateCustomFormats(IDbConnection conn, IDbTransaction tran)
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
var updateSql = "UPDATE CustomFormats SET Specifications = @Specifications WHERE Id = @Id";
|
var updateSql = "UPDATE \"CustomFormats\" SET \"Specifications\" = @Specifications WHERE \"Id\" = @Id";
|
||||||
conn.Execute(updateSql, updated, transaction: tran);
|
conn.Execute(updateSql, updated, transaction: tran);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ protected override void MainDbUpgrade()
|
|||||||
|
|
||||||
Delete.Column("FormatCutoff").FromTable("Profiles");
|
Delete.Column("FormatCutoff").FromTable("Profiles");
|
||||||
|
|
||||||
Alter.Table("CustomFormats").AddColumn("IncludeCustomFormatWhenRenaming").AsBoolean().WithDefaultValue(0);
|
Alter.Table("CustomFormats").AddColumn("IncludeCustomFormatWhenRenaming").AsBoolean().WithDefaultValue(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void MigrateOrderToScores(IDbConnection conn, IDbTransaction tran)
|
private void MigrateOrderToScores(IDbConnection conn, IDbTransaction tran)
|
||||||
@ -29,7 +29,7 @@ private void MigrateOrderToScores(IDbConnection conn, IDbTransaction tran)
|
|||||||
SqlMapper.AddTypeHandler(new EmbeddedDocumentConverter<List<ProfileFormatItem168>>());
|
SqlMapper.AddTypeHandler(new EmbeddedDocumentConverter<List<ProfileFormatItem168>>());
|
||||||
SqlMapper.AddTypeHandler(new EmbeddedDocumentConverter<List<ProfileFormatItem169>>());
|
SqlMapper.AddTypeHandler(new EmbeddedDocumentConverter<List<ProfileFormatItem169>>());
|
||||||
|
|
||||||
var rows = conn.Query<Profile168>("SELECT Id, FormatCutoff, FormatItems from Profiles", transaction: tran);
|
var rows = conn.Query<Profile168>("SELECT \"Id\", \"FormatCutoff\", \"FormatItems\" from \"Profiles\"", transaction: tran);
|
||||||
var newRows = new List<Profile169>();
|
var newRows = new List<Profile169>();
|
||||||
|
|
||||||
foreach (var row in rows)
|
foreach (var row in rows)
|
||||||
@ -125,7 +125,7 @@ private void MigrateOrderToScores(IDbConnection conn, IDbTransaction tran)
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
var sql = $"UPDATE Profiles SET MinFormatScore = @MinFormatScore, CutoffFormatScore = @CutoffFormatScore, FormatItems = @FormatItems WHERE Id = @Id";
|
var sql = $"UPDATE \"Profiles\" SET \"MinFormatScore\" = @MinFormatScore, \"CutoffFormatScore\" = @CutoffFormatScore, \"FormatItems\" = @FormatItems WHERE \"Id\" = @Id";
|
||||||
|
|
||||||
conn.Execute(sql, newRows, transaction: tran);
|
conn.Execute(sql, newRows, transaction: tran);
|
||||||
}
|
}
|
||||||
|
@ -33,12 +33,12 @@ protected override void MainDbUpgrade()
|
|||||||
{
|
{
|
||||||
Execute.WithConnection(FixTraktConfig);
|
Execute.WithConnection(FixTraktConfig);
|
||||||
Execute.WithConnection(RenameRadarrListType);
|
Execute.WithConnection(RenameRadarrListType);
|
||||||
Execute.Sql("DELETE FROM Config WHERE[KEY] IN ('TraktAuthToken', 'TraktRefreshToken', 'TraktTokenExpiry', 'NewTraktAuthToken', 'NewTraktRefreshToken', 'NewTraktTokenExpiry')");
|
Execute.Sql("DELETE FROM \"Config\" WHERE \"Key\" IN ('TraktAuthToken', 'TraktRefreshToken', 'TraktTokenExpiry', 'NewTraktAuthToken', 'NewTraktRefreshToken', 'NewTraktTokenExpiry')");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void RenameRadarrListType(IDbConnection conn, IDbTransaction tran)
|
private void RenameRadarrListType(IDbConnection conn, IDbTransaction tran)
|
||||||
{
|
{
|
||||||
var rows = conn.Query<ProviderDefinition169>($"SELECT Id, Implementation, ConfigContract, Settings FROM NetImport WHERE Implementation = 'RadarrLists'");
|
var rows = conn.Query<ProviderDefinition169>($"SELECT \"Id\", \"Implementation\", \"ConfigContract\", \"Settings\" FROM \"NetImport\" WHERE \"Implementation\" = 'RadarrLists'");
|
||||||
|
|
||||||
var corrected = new List<ProviderDefinition169>();
|
var corrected = new List<ProviderDefinition169>();
|
||||||
|
|
||||||
@ -52,13 +52,13 @@ private void RenameRadarrListType(IDbConnection conn, IDbTransaction tran)
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
var updateSql = "UPDATE NetImport SET Implementation = @Implementation, ConfigContract = @ConfigContract WHERE Id = @Id";
|
var updateSql = "UPDATE \"NetImport\" SET \"Implementation\" = @Implementation, \"ConfigContract\" = @ConfigContract WHERE \"Id\" = @Id";
|
||||||
conn.Execute(updateSql, corrected, transaction: tran);
|
conn.Execute(updateSql, corrected, transaction: tran);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void FixTraktConfig(IDbConnection conn, IDbTransaction tran)
|
private void FixTraktConfig(IDbConnection conn, IDbTransaction tran)
|
||||||
{
|
{
|
||||||
var rows = conn.Query<ProviderDefinition169>($"SELECT Id, Implementation, ConfigContract, Settings FROM NetImport WHERE Implementation = 'TraktImport'");
|
var rows = conn.Query<ProviderDefinition169>($"SELECT \"Id\", \"Implementation\", \"ConfigContract\", \"Settings\" FROM \"NetImport\" WHERE \"Implementation\" = 'TraktImport'");
|
||||||
|
|
||||||
var corrected = new List<ProviderDefinition169>();
|
var corrected = new List<ProviderDefinition169>();
|
||||||
|
|
||||||
@ -158,7 +158,7 @@ private void FixTraktConfig(IDbConnection conn, IDbTransaction tran)
|
|||||||
|
|
||||||
Console.WriteLine(corrected.ToJson());
|
Console.WriteLine(corrected.ToJson());
|
||||||
|
|
||||||
var updateSql = "UPDATE NetImport SET Implementation = @Implementation, ConfigContract = @ConfigContract, Settings = @Settings WHERE Id = @Id";
|
var updateSql = "UPDATE \"NetImport\" SET \"Implementation\" = @Implementation, \"ConfigContract\" = @ConfigContract, \"Settings\" = @Settings WHERE \"Id\" = @Id";
|
||||||
conn.Execute(updateSql, corrected, transaction: tran);
|
conn.Execute(updateSql, corrected, transaction: tran);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ protected override void MainDbUpgrade()
|
|||||||
|
|
||||||
private void UpdateQualityDefinitions(IDbConnection conn, IDbTransaction tran)
|
private void UpdateQualityDefinitions(IDbConnection conn, IDbTransaction tran)
|
||||||
{
|
{
|
||||||
var existing = conn.Query<QualityDefinition170>("SELECT Id, MaxSize FROM QualityDefinitions");
|
var existing = conn.Query<QualityDefinition170>("SELECT \"Id\", \"MaxSize\" FROM \"QualityDefinitions\"");
|
||||||
|
|
||||||
var updated = new List<QualityDefinition171>();
|
var updated = new List<QualityDefinition171>();
|
||||||
|
|
||||||
@ -39,7 +39,7 @@ private void UpdateQualityDefinitions(IDbConnection conn, IDbTransaction tran)
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
var updateSql = "UPDATE QualityDefinitions SET PreferredSize = @PreferredSize WHERE Id = @Id";
|
var updateSql = "UPDATE \"QualityDefinitions\" SET \"PreferredSize\" = @PreferredSize WHERE \"Id\" = @Id";
|
||||||
conn.Execute(updateSql, updated, transaction: tran);
|
conn.Execute(updateSql, updated, transaction: tran);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ protected override void MainDbUpgrade()
|
|||||||
Create.Index().OnTable("DownloadHistory").OnColumn("MovieId");
|
Create.Index().OnTable("DownloadHistory").OnColumn("MovieId");
|
||||||
Create.Index().OnTable("DownloadHistory").OnColumn("DownloadId");
|
Create.Index().OnTable("DownloadHistory").OnColumn("DownloadId");
|
||||||
|
|
||||||
Execute.WithConnection(InitialImportedDownloadHistory);
|
IfDatabase("sqlite").Execute.WithConnection(InitialImportedDownloadHistory);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static readonly Dictionary<int, int> EventTypeMap = new Dictionary<int, int>()
|
private static readonly Dictionary<int, int> EventTypeMap = new Dictionary<int, int>()
|
||||||
@ -44,7 +44,7 @@ private void InitialImportedDownloadHistory(IDbConnection conn, IDbTransaction t
|
|||||||
using (var cmd = conn.CreateCommand())
|
using (var cmd = conn.CreateCommand())
|
||||||
{
|
{
|
||||||
cmd.Transaction = tran;
|
cmd.Transaction = tran;
|
||||||
cmd.CommandText = "SELECT MovieId, DownloadId, EventType, SourceTitle, Date, Data FROM History WHERE DownloadId IS NOT NULL AND EventType IN (1, 3, 4, 9) GROUP BY EventType, DownloadId";
|
cmd.CommandText = "SELECT \"MovieId\", \"DownloadId\", \"EventType\", \"SourceTitle\", \"Date\", \"Data\" FROM \"History\" WHERE \"DownloadId\" IS NOT NULL AND \"EventType\" IN (1, 3, 4, 9) GROUP BY \"EventType\", \"DownloadId\"";
|
||||||
|
|
||||||
using (var reader = cmd.ExecuteReader())
|
using (var reader = cmd.ExecuteReader())
|
||||||
{
|
{
|
||||||
@ -75,7 +75,15 @@ private void InitialImportedDownloadHistory(IDbConnection conn, IDbTransaction t
|
|||||||
using (var updateCmd = conn.CreateCommand())
|
using (var updateCmd = conn.CreateCommand())
|
||||||
{
|
{
|
||||||
updateCmd.Transaction = tran;
|
updateCmd.Transaction = tran;
|
||||||
updateCmd.CommandText = @"INSERT INTO DownloadHistory (EventType, MovieId, DownloadId, SourceTitle, Date, Protocol, Data) VALUES (?, ?, ?, ?, ?, ?, ?)";
|
if (conn.GetType().FullName == "Npgsql.NpgsqlConnection")
|
||||||
|
{
|
||||||
|
updateCmd.CommandText = @"INSERT INTO ""DownloadHistory"" (""EventType"", ""MovieId"", ""DownloadId"", ""SourceTitle"", ""Date"", ""Protocol"", ""Data"") VALUES ($1, $2, $3, $4, $5, $6, $7)";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
updateCmd.CommandText = @"INSERT INTO ""DownloadHistory"" (""EventType"", ""MovieId"", ""DownloadId"", ""SourceTitle"", ""Date"", ""Protocol"", ""Data"") VALUES (?, ?, ?, ?, ?, ?, ?)";
|
||||||
|
}
|
||||||
|
|
||||||
updateCmd.AddParameter(downloadHistoryEventType);
|
updateCmd.AddParameter(downloadHistoryEventType);
|
||||||
updateCmd.AddParameter(movieId);
|
updateCmd.AddParameter(movieId);
|
||||||
updateCmd.AddParameter(downloadId);
|
updateCmd.AddParameter(downloadId);
|
||||||
|
@ -34,7 +34,7 @@ protected override void MainDbUpgrade()
|
|||||||
|
|
||||||
private void ChangeEmailAddressType(IDbConnection conn, IDbTransaction tran)
|
private void ChangeEmailAddressType(IDbConnection conn, IDbTransaction tran)
|
||||||
{
|
{
|
||||||
var rows = conn.Query<ProviderDefinition166>($"SELECT Id, Settings FROM Notifications WHERE Implementation = 'Email'");
|
var rows = conn.Query<ProviderDefinition166>($"SELECT \"Id\", \"Settings\" FROM \"Notifications\" WHERE \"Implementation\" = 'Email'");
|
||||||
|
|
||||||
var corrected = new List<ProviderDefinition166>();
|
var corrected = new List<ProviderDefinition166>();
|
||||||
|
|
||||||
@ -62,7 +62,7 @@ private void ChangeEmailAddressType(IDbConnection conn, IDbTransaction tran)
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
var updateSql = "UPDATE Notifications SET Settings = @Settings WHERE Id = @Id";
|
var updateSql = "UPDATE \"Notifications\" SET \"Settings\" = @Settings WHERE \"Id\" = @Id";
|
||||||
conn.Execute(updateSql, corrected, transaction: tran);
|
conn.Execute(updateSql, corrected, transaction: tran);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ public class remove_chown_and_folderchmod_config : NzbDroneMigrationBase
|
|||||||
{
|
{
|
||||||
protected override void MainDbUpgrade()
|
protected override void MainDbUpgrade()
|
||||||
{
|
{
|
||||||
Execute.Sql("DELETE FROM config WHERE Key IN ('folderchmod', 'chownuser', 'parsingleniency')");
|
Execute.Sql("DELETE FROM \"Config\" WHERE \"Key\" IN ('folderchmod', 'chownuser', 'parsingleniency')");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,18 +41,27 @@ protected override void MainDbUpgrade()
|
|||||||
Delete.Column("PhysicalReleaseNote").FromTable("Movies");
|
Delete.Column("PhysicalReleaseNote").FromTable("Movies");
|
||||||
Delete.Column("SecondaryYearSourceId").FromTable("Movies");
|
Delete.Column("SecondaryYearSourceId").FromTable("Movies");
|
||||||
|
|
||||||
Alter.Table("NamingConfig").AddColumn("RenameMovies").AsBoolean().WithDefaultValue(0);
|
Alter.Table("NamingConfig").AddColumn("RenameMovies").AsBoolean().WithDefaultValue(false);
|
||||||
Execute.Sql("UPDATE NamingConfig SET RenameMovies=RenameEpisodes");
|
Execute.Sql("UPDATE \"NamingConfig\" SET \"RenameMovies\"=\"RenameEpisodes\"");
|
||||||
Delete.Column("RenameEpisodes").FromTable("NamingConfig");
|
Delete.Column("RenameEpisodes").FromTable("NamingConfig");
|
||||||
|
|
||||||
//Manual SQL, Fluent Migrator doesn't support multi-column unique contraint on table creation, SQLite doesn't support adding it after creation
|
//Manual SQL, Fluent Migrator doesn't support multi-column unique contraint on table creation, SQLite doesn't support adding it after creation
|
||||||
Execute.Sql("CREATE TABLE MovieTranslations(" +
|
IfDatabase("sqlite").Execute.Sql("CREATE TABLE \"MovieTranslations\"(" +
|
||||||
"Id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, " +
|
"\"Id\" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, " +
|
||||||
"MovieId INTEGER NOT NULL, " +
|
"\"MovieId\" INTEGER NOT NULL, " +
|
||||||
"Title TEXT, " +
|
"\"Title\" TEXT, " +
|
||||||
"CleanTitle TEXT, " +
|
"\"CleanTitle\" TEXT, " +
|
||||||
"Overview TEXT, " +
|
"\"Overview\" TEXT, " +
|
||||||
"Language INTEGER NOT NULL, " +
|
"\"Language\" INTEGER NOT NULL, " +
|
||||||
|
"Unique(\"MovieId\", \"Language\"));");
|
||||||
|
|
||||||
|
IfDatabase("postgres").Execute.Sql("CREATE TABLE \"MovieTranslations\"(" +
|
||||||
|
"\"Id\" SERIAL PRIMARY KEY , " +
|
||||||
|
"\"MovieId\" INTEGER NOT NULL, " +
|
||||||
|
"\"Title\" TEXT, " +
|
||||||
|
"\"CleanTitle\" TEXT, " +
|
||||||
|
"\"Overview\" TEXT, " +
|
||||||
|
"\"Language\" INTEGER NOT NULL, " +
|
||||||
"Unique(\"MovieId\", \"Language\"));");
|
"Unique(\"MovieId\", \"Language\"));");
|
||||||
|
|
||||||
// Prevent failure if two movies have same alt titles
|
// Prevent failure if two movies have same alt titles
|
||||||
@ -73,7 +82,7 @@ protected override void MainDbUpgrade()
|
|||||||
|
|
||||||
private void FixLanguagesMoveFile(IDbConnection conn, IDbTransaction tran)
|
private void FixLanguagesMoveFile(IDbConnection conn, IDbTransaction tran)
|
||||||
{
|
{
|
||||||
var rows = conn.Query<LanguageEntity177>($"SELECT Id, Languages FROM MovieFiles");
|
var rows = conn.Query<LanguageEntity177>($"SELECT \"Id\", \"Languages\" FROM \"MovieFiles\"");
|
||||||
|
|
||||||
var corrected = new List<LanguageEntity177>();
|
var corrected = new List<LanguageEntity177>();
|
||||||
|
|
||||||
@ -90,13 +99,13 @@ private void FixLanguagesMoveFile(IDbConnection conn, IDbTransaction tran)
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
var updateSql = "UPDATE MovieFiles SET Languages = @Languages WHERE Id = @Id";
|
var updateSql = "UPDATE \"MovieFiles\" SET \"Languages\" = @Languages WHERE \"Id\" = @Id";
|
||||||
conn.Execute(updateSql, corrected, transaction: tran);
|
conn.Execute(updateSql, corrected, transaction: tran);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void FixLanguagesHistory(IDbConnection conn, IDbTransaction tran)
|
private void FixLanguagesHistory(IDbConnection conn, IDbTransaction tran)
|
||||||
{
|
{
|
||||||
var rows = conn.Query<LanguageEntity177>($"SELECT Id, Languages FROM History");
|
var rows = conn.Query<LanguageEntity177>($"SELECT \"Id\", \"Languages\" FROM \"History\"");
|
||||||
|
|
||||||
var corrected = new List<LanguageEntity177>();
|
var corrected = new List<LanguageEntity177>();
|
||||||
|
|
||||||
@ -113,7 +122,7 @@ private void FixLanguagesHistory(IDbConnection conn, IDbTransaction tran)
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
var updateSql = "UPDATE History SET Languages = @Languages WHERE Id = @Id";
|
var updateSql = "UPDATE \"History\" SET \"Languages\" = @Languages WHERE \"Id\" = @Id";
|
||||||
conn.Execute(updateSql, corrected, transaction: tran);
|
conn.Execute(updateSql, corrected, transaction: tran);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ protected override void MainDbUpgrade()
|
|||||||
|
|
||||||
private void FixRadarrLists(IDbConnection conn, IDbTransaction tran)
|
private void FixRadarrLists(IDbConnection conn, IDbTransaction tran)
|
||||||
{
|
{
|
||||||
var rows = conn.Query<NetImportDefinition178>($"SELECT * FROM NetImport WHERE ConfigContract = 'RadarrListSettings'");
|
var rows = conn.Query<NetImportDefinition178>($"SELECT * FROM \"NetImport\" WHERE \"ConfigContract\" = 'RadarrListSettings'");
|
||||||
|
|
||||||
var radarrUrls = new List<string>
|
var radarrUrls = new List<string>
|
||||||
{
|
{
|
||||||
@ -108,17 +108,17 @@ private void FixRadarrLists(IDbConnection conn, IDbTransaction tran)
|
|||||||
row.Settings = JsonSerializer.Serialize(newSettings, _serializerSettings);
|
row.Settings = JsonSerializer.Serialize(newSettings, _serializerSettings);
|
||||||
}
|
}
|
||||||
|
|
||||||
var updateSql = "UPDATE NetImport SET Implementation = @Implementation, " +
|
var updateSql = "UPDATE \"NetImport\" SET \"Implementation\" = @Implementation, " +
|
||||||
"ConfigContract = @ConfigContract, " +
|
"\"ConfigContract\" = @ConfigContract, " +
|
||||||
"Settings = @Settings " +
|
"\"Settings\" = @Settings " +
|
||||||
"WHERE Id = @Id";
|
"WHERE \"Id\" = @Id";
|
||||||
|
|
||||||
conn.Execute(updateSql, rows, transaction: tran);
|
conn.Execute(updateSql, rows, transaction: tran);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void FixStevenLuLists(IDbConnection conn, IDbTransaction tran)
|
private void FixStevenLuLists(IDbConnection conn, IDbTransaction tran)
|
||||||
{
|
{
|
||||||
var rows = conn.Query<NetImportDefinition178>($"SELECT * FROM NetImport WHERE ConfigContract = 'StevenLuSettings'");
|
var rows = conn.Query<NetImportDefinition178>($"SELECT * FROM \"NetImport\" WHERE \"ConfigContract\" = 'StevenLuSettings'");
|
||||||
|
|
||||||
var updated = new List<NetImportDefinition178>();
|
var updated = new List<NetImportDefinition178>();
|
||||||
|
|
||||||
@ -160,10 +160,10 @@ private void FixStevenLuLists(IDbConnection conn, IDbTransaction tran)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var updateSql = "UPDATE NetImport SET Implementation = @Implementation, " +
|
var updateSql = "UPDATE \"NetImport\" SET \"Implementation\" = @Implementation, " +
|
||||||
"ConfigContract = @ConfigContract, " +
|
"\"ConfigContract\" = @ConfigContract, " +
|
||||||
"Settings = @Settings " +
|
"\"Settings\" = @Settings " +
|
||||||
"WHERE Id = @Id";
|
"WHERE \"Id\" = @Id";
|
||||||
conn.Execute(updateSql, updated, transaction: tran);
|
conn.Execute(updateSql, updated, transaction: tran);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,8 +21,8 @@ protected override void MainDbUpgrade()
|
|||||||
private void FixMovies(IDbConnection conn, IDbTransaction tran)
|
private void FixMovies(IDbConnection conn, IDbTransaction tran)
|
||||||
{
|
{
|
||||||
var profiles = GetProfileIds(conn);
|
var profiles = GetProfileIds(conn);
|
||||||
var movieRows = conn.Query<ProfileEntity179>($"SELECT Id, ProfileId FROM Movies");
|
var movieRows = conn.Query<ProfileEntity179>($"SELECT \"Id\", \"ProfileId\" FROM \"Movies\"");
|
||||||
var listRows = conn.Query<ProfileEntity179>($"SELECT Id, ProfileId FROM NetImport");
|
var listRows = conn.Query<ProfileEntity179>($"SELECT \"Id\", \"ProfileId\" FROM \"NetImport\"");
|
||||||
|
|
||||||
// Only process if there are lists or movies existing in the DB
|
// Only process if there are lists or movies existing in the DB
|
||||||
if (movieRows.Any() || listRows.Any())
|
if (movieRows.Any() || listRows.Any())
|
||||||
@ -54,18 +54,18 @@ private void FixMovies(IDbConnection conn, IDbTransaction tran)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Correct any Movies that reference profiles that are null
|
//Correct any Movies that reference profiles that are null
|
||||||
var sql = $"UPDATE Movies SET ProfileId = {mostCommonProfileId} WHERE Id IN(SELECT Movies.Id FROM Movies LEFT OUTER JOIN Profiles ON Movies.ProfileId = Profiles.Id WHERE Profiles.Id IS NULL)";
|
var sql = $"UPDATE \"Movies\" SET \"ProfileId\" = {mostCommonProfileId} WHERE \"Id\" IN(SELECT \"Movies\".\"Id\" FROM \"Movies\" LEFT OUTER JOIN \"Profiles\" ON \"Movies\".\"ProfileId\" = \"Profiles\".\"Id\" WHERE \"Profiles\".\"Id\" IS NULL)";
|
||||||
conn.Execute(sql, transaction: tran);
|
conn.Execute(sql, transaction: tran);
|
||||||
|
|
||||||
//Correct any Lists that reference profiles that are null
|
//Correct any Lists that reference profiles that are null
|
||||||
sql = $"UPDATE NetImport SET ProfileId = {mostCommonProfileId} WHERE Id IN(SELECT NetImport.Id FROM NetImport LEFT OUTER JOIN Profiles ON NetImport.ProfileId = Profiles.Id WHERE Profiles.Id IS NULL)";
|
sql = $"UPDATE \"NetImport\" SET \"ProfileId\" = {mostCommonProfileId} WHERE \"Id\" IN(SELECT \"NetImport\".\"Id\" FROM \"NetImport\" LEFT OUTER JOIN \"Profiles\" ON \"NetImport\".\"ProfileId\" = \"Profiles\".\"Id\" WHERE \"Profiles\".\"Id\" IS NULL)";
|
||||||
conn.Execute(sql, transaction: tran);
|
conn.Execute(sql, transaction: tran);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<int> GetProfileIds(IDbConnection conn)
|
private List<int> GetProfileIds(IDbConnection conn)
|
||||||
{
|
{
|
||||||
return conn.Query<QualityProfile180>("SELECT Id From Profiles").Select(p => p.Id).ToList();
|
return conn.Query<QualityProfile180>("SELECT \"Id\" From \"Profiles\"").Select(p => p.Id).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void InsertDefaultQualityProfiles(IDbConnection conn, IDbTransaction tran)
|
private void InsertDefaultQualityProfiles(IDbConnection conn, IDbTransaction tran)
|
||||||
@ -80,7 +80,16 @@ private void InsertDefaultQualityProfiles(IDbConnection conn, IDbTransaction tra
|
|||||||
using (IDbCommand insertNewLanguageProfileCmd = conn.CreateCommand())
|
using (IDbCommand insertNewLanguageProfileCmd = conn.CreateCommand())
|
||||||
{
|
{
|
||||||
insertNewLanguageProfileCmd.Transaction = tran;
|
insertNewLanguageProfileCmd.Transaction = tran;
|
||||||
insertNewLanguageProfileCmd.CommandText = "INSERT INTO Profiles (Id, Name, Cutoff, Items, Language, FormatItems, MinFormatScore, CutoffFormatScore, UpgradeAllowed) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
|
||||||
|
if (conn.GetType().FullName == "Npgsql.NpgsqlConnection")
|
||||||
|
{
|
||||||
|
insertNewLanguageProfileCmd.CommandText = "INSERT INTO \"Profiles\" (\"Id\", \"Name\", \"Cutoff\", \"Items\", \"Language\", \"FormatItems\", \"MinFormatScore\", \"CutoffFormatScore\", \"UpgradeAllowed\") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
insertNewLanguageProfileCmd.CommandText = "INSERT INTO \"Profiles\" (\"Id\", \"Name\", \"Cutoff\", \"Items\", \"Language\", \"FormatItems\", \"MinFormatScore\", \"CutoffFormatScore\", \"UpgradeAllowed\") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
||||||
|
}
|
||||||
|
|
||||||
insertNewLanguageProfileCmd.AddParameter(profileId);
|
insertNewLanguageProfileCmd.AddParameter(profileId);
|
||||||
insertNewLanguageProfileCmd.AddParameter(profile.Name);
|
insertNewLanguageProfileCmd.AddParameter(profile.Name);
|
||||||
insertNewLanguageProfileCmd.AddParameter(profile.Cutoff);
|
insertNewLanguageProfileCmd.AddParameter(profile.Cutoff);
|
||||||
@ -111,7 +120,7 @@ private List<QualityProfile180> GetDefaultQualityProfiles(IDbConnection conn)
|
|||||||
var profiles = new List<QualityProfile180>();
|
var profiles = new List<QualityProfile180>();
|
||||||
|
|
||||||
//Grab custom formats if any exist and add them to the new profiles
|
//Grab custom formats if any exist and add them to the new profiles
|
||||||
var formats = conn.Query<CustomFormat180>($"SELECT Id FROM CustomFormats").ToList();
|
var formats = conn.Query<CustomFormat180>($"SELECT \"Id\" FROM \"CustomFormats\"").ToList();
|
||||||
|
|
||||||
profiles.Add(GetDefaultProfile("Any",
|
profiles.Add(GetDefaultProfile("Any",
|
||||||
formats,
|
formats,
|
||||||
@ -258,7 +267,7 @@ private QualityProfile180 GetDefaultProfile(string name, List<CustomFormat180> f
|
|||||||
Language = Language.English,
|
Language = Language.English,
|
||||||
MinFormatScore = 0,
|
MinFormatScore = 0,
|
||||||
CutoffFormatScore = 0,
|
CutoffFormatScore = 0,
|
||||||
UpgradeAllowed = 0,
|
UpgradeAllowed = false,
|
||||||
FormatItems = formatItems
|
FormatItems = formatItems
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -278,7 +287,7 @@ private class QualityProfile180
|
|||||||
public int Cutoff { get; set; }
|
public int Cutoff { get; set; }
|
||||||
public int MinFormatScore { get; set; }
|
public int MinFormatScore { get; set; }
|
||||||
public int CutoffFormatScore { get; set; }
|
public int CutoffFormatScore { get; set; }
|
||||||
public int UpgradeAllowed { get; set; }
|
public bool UpgradeAllowed { get; set; }
|
||||||
public Language Language { get; set; }
|
public Language Language { get; set; }
|
||||||
public List<ProfileFormatItem180> FormatItems { get; set; }
|
public List<ProfileFormatItem180> FormatItems { get; set; }
|
||||||
public List<QualityProfileItem111> Items { get; set; }
|
public List<QualityProfileItem111> Items { get; set; }
|
||||||
|
@ -11,7 +11,7 @@ protected override void MainDbUpgrade()
|
|||||||
Rename.Table("NetImport").To("ImportLists");
|
Rename.Table("NetImport").To("ImportLists");
|
||||||
Rename.Table("NetImportStatus").To("ImportListStatus");
|
Rename.Table("NetImportStatus").To("ImportListStatus");
|
||||||
|
|
||||||
Execute.Sql("UPDATE Config SET Key = 'importlistsyncinterval' WHERE Key = 'netimportsyncinterval'");
|
Execute.Sql("UPDATE \"Config\" SET \"Key\" = 'importlistsyncinterval' WHERE \"Key\" = 'netimportsyncinterval'");
|
||||||
|
|
||||||
Alter.Table("ImportLists").AddColumn("SearchOnAdd").AsBoolean().WithDefaultValue(false);
|
Alter.Table("ImportLists").AddColumn("SearchOnAdd").AsBoolean().WithDefaultValue(false);
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ public class download_propers_config : NzbDroneMigrationBase
|
|||||||
protected override void MainDbUpgrade()
|
protected override void MainDbUpgrade()
|
||||||
{
|
{
|
||||||
Execute.WithConnection(SetMetadataFileExtension);
|
Execute.WithConnection(SetMetadataFileExtension);
|
||||||
Execute.Sql("DELETE FROM Config WHERE Key = 'autodownloadpropers'");
|
Execute.Sql("DELETE FROM \"Config\" WHERE \"Key\" = 'autodownloadpropers'");
|
||||||
Delete.Column("PreferredTags").FromTable("Profiles");
|
Delete.Column("PreferredTags").FromTable("Profiles");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -19,7 +19,7 @@ private void SetMetadataFileExtension(IDbConnection conn, IDbTransaction tran)
|
|||||||
using (var cmd = conn.CreateCommand())
|
using (var cmd = conn.CreateCommand())
|
||||||
{
|
{
|
||||||
cmd.Transaction = tran;
|
cmd.Transaction = tran;
|
||||||
cmd.CommandText = "SELECT Value FROM Config WHERE Key = 'autodownloadpropers'";
|
cmd.CommandText = "SELECT \"Value\" FROM \"Config\" WHERE \"Key\" = 'autodownloadpropers'";
|
||||||
|
|
||||||
using (var reader = cmd.ExecuteReader())
|
using (var reader = cmd.ExecuteReader())
|
||||||
{
|
{
|
||||||
@ -31,7 +31,7 @@ private void SetMetadataFileExtension(IDbConnection conn, IDbTransaction tran)
|
|||||||
using (var updateCmd = conn.CreateCommand())
|
using (var updateCmd = conn.CreateCommand())
|
||||||
{
|
{
|
||||||
updateCmd.Transaction = tran;
|
updateCmd.Transaction = tran;
|
||||||
updateCmd.CommandText = "INSERT INTO Config (key, value) VALUES ('downloadpropersandrepacks', ?)";
|
updateCmd.CommandText = "INSERT INTO \"Config\" (\"key\", \"value\") VALUES ('downloadpropersandrepacks', ?)";
|
||||||
updateCmd.AddParameter(newValue);
|
updateCmd.AddParameter(newValue);
|
||||||
|
|
||||||
updateCmd.ExecuteNonQuery();
|
updateCmd.ExecuteNonQuery();
|
||||||
|
@ -20,7 +20,7 @@ protected override void MainDbUpgrade()
|
|||||||
|
|
||||||
private void FixMovies(IDbConnection conn, IDbTransaction tran)
|
private void FixMovies(IDbConnection conn, IDbTransaction tran)
|
||||||
{
|
{
|
||||||
var movieRows = conn.Query<MovieEntity185>($"SELECT Id, TmdbId, Added, LastInfoSync, MovieFileId FROM Movies");
|
var movieRows = conn.Query<MovieEntity185>($"SELECT \"Id\", \"TmdbId\", \"Added\", \"LastInfoSync\", \"MovieFileId\" FROM \"Movies\"");
|
||||||
|
|
||||||
// Only process if there are movies existing in the DB
|
// Only process if there are movies existing in the DB
|
||||||
if (movieRows.Any())
|
if (movieRows.Any())
|
||||||
@ -61,7 +61,7 @@ private void FixMovies(IDbConnection conn, IDbTransaction tran)
|
|||||||
|
|
||||||
if (purgeMovies.Count > 0)
|
if (purgeMovies.Count > 0)
|
||||||
{
|
{
|
||||||
var deleteSql = "DELETE FROM Movies WHERE Id = @Id";
|
var deleteSql = "DELETE FROM \"Movies\" WHERE \"Id\" = @Id";
|
||||||
conn.Execute(deleteSql, purgeMovies, transaction: tran);
|
conn.Execute(deleteSql, purgeMovies, transaction: tran);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ private void ConvertFileChmodToFolderChmod(IDbConnection conn, IDbTransaction tr
|
|||||||
using (IDbCommand getFileChmodCmd = conn.CreateCommand())
|
using (IDbCommand getFileChmodCmd = conn.CreateCommand())
|
||||||
{
|
{
|
||||||
getFileChmodCmd.Transaction = tran;
|
getFileChmodCmd.Transaction = tran;
|
||||||
getFileChmodCmd.CommandText = @"SELECT Value FROM Config WHERE Key = 'filechmod'";
|
getFileChmodCmd.CommandText = @"SELECT ""Value"" FROM ""Config"" WHERE ""Key"" = 'filechmod'";
|
||||||
|
|
||||||
var fileChmod = getFileChmodCmd.ExecuteScalar() as string;
|
var fileChmod = getFileChmodCmd.ExecuteScalar() as string;
|
||||||
if (fileChmod != null)
|
if (fileChmod != null)
|
||||||
@ -35,7 +35,7 @@ private void ConvertFileChmodToFolderChmod(IDbConnection conn, IDbTransaction tr
|
|||||||
using (IDbCommand insertCmd = conn.CreateCommand())
|
using (IDbCommand insertCmd = conn.CreateCommand())
|
||||||
{
|
{
|
||||||
insertCmd.Transaction = tran;
|
insertCmd.Transaction = tran;
|
||||||
insertCmd.CommandText = "INSERT INTO Config (Key, Value) VALUES ('chmodfolder', ?)";
|
insertCmd.CommandText = "INSERT INTO \"Config\" (\"Key\", \"Value\") VALUES ('chmodfolder', ?)";
|
||||||
insertCmd.AddParameter(folderChmod);
|
insertCmd.AddParameter(folderChmod);
|
||||||
|
|
||||||
insertCmd.ExecuteNonQuery();
|
insertCmd.ExecuteNonQuery();
|
||||||
@ -45,7 +45,7 @@ private void ConvertFileChmodToFolderChmod(IDbConnection conn, IDbTransaction tr
|
|||||||
using (IDbCommand deleteCmd = conn.CreateCommand())
|
using (IDbCommand deleteCmd = conn.CreateCommand())
|
||||||
{
|
{
|
||||||
deleteCmd.Transaction = tran;
|
deleteCmd.Transaction = tran;
|
||||||
deleteCmd.CommandText = "DELETE FROM Config WHERE Key = 'filechmod'";
|
deleteCmd.CommandText = "DELETE FROM \"Config\" WHERE \"Key\" = 'filechmod'";
|
||||||
|
|
||||||
deleteCmd.ExecuteNonQuery();
|
deleteCmd.ExecuteNonQuery();
|
||||||
}
|
}
|
||||||
|
@ -8,11 +8,12 @@ public class mediainfo_channels : NzbDroneMigrationBase
|
|||||||
{
|
{
|
||||||
protected override void MainDbUpgrade()
|
protected override void MainDbUpgrade()
|
||||||
{
|
{
|
||||||
Execute.Sql("UPDATE MovieFiles SET MediaInfo = Replace(MediaInfo, '\"audioChannels\"', '\"audioChannelsContainer\"');");
|
Execute.Sql("UPDATE \"MovieFiles\" SET \"MediaInfo\" = Replace(\"MediaInfo\", '\"audioChannels\"', '\"audioChannelsContainer\"');");
|
||||||
Execute.Sql("UPDATE MovieFiles SET MediaInfo = Replace(MediaInfo, '\"audioChannelPositionsText\"', '\"audioChannelPositionsTextContainer\"');");
|
Execute.Sql("UPDATE \"MovieFiles\" SET \"MediaInfo\" = Replace(\"MediaInfo\", '\"audioChannelPositionsText\"', '\"audioChannelPositionsTextContainer\"');");
|
||||||
|
|
||||||
//Change List Interval from Min to Hour
|
//Change List Interval from Min to Hour
|
||||||
Execute.Sql("UPDATE Config SET Value = max((Value / 60) + 1, 6) WHERE Key = 'importlistsyncinterval'");
|
IfDatabase("sqlite").Execute.Sql("UPDATE \"Config\" SET \"Value\" = max((\"Value\" / 60) + 1, 6) WHERE \"Key\" = 'importlistsyncinterval'");
|
||||||
|
IfDatabase("postgres").Execute.Sql("UPDATE \"Config\" SET \"Value\" = greatest((\"Value\"::int / 60) + 1, 6) WHERE \"Key\" = 'importlistsyncinterval'");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,8 +9,8 @@ public class update_awesome_hd_link : NzbDroneMigrationBase
|
|||||||
{
|
{
|
||||||
protected override void MainDbUpgrade()
|
protected override void MainDbUpgrade()
|
||||||
{
|
{
|
||||||
Execute.Sql("UPDATE Indexers SET Settings = Replace(Settings, 'https://awesome-hd.net', 'https://awesome-hd.club') WHERE Implementation = 'AwesomeHD';");
|
Execute.Sql("UPDATE \"Indexers\" SET \"Settings\" = Replace(\"Settings\", 'https://awesome-hd.net', 'https://awesome-hd.club') WHERE \"Implementation\" = 'AwesomeHD';");
|
||||||
Execute.Sql("UPDATE Indexers SET Settings = Replace(Settings, 'https://awesome-hd.me', 'https://awesome-hd.club') WHERE Implementation = 'AwesomeHD';");
|
Execute.Sql("UPDATE \"Indexers\" SET \"Settings\" = Replace(\"Settings\", 'https://awesome-hd.me', 'https://awesome-hd.club') WHERE \"Implementation\" = 'AwesomeHD';");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,8 +9,8 @@ public class add_on_delete_to_notifications : NzbDroneMigrationBase
|
|||||||
protected override void MainDbUpgrade()
|
protected override void MainDbUpgrade()
|
||||||
{
|
{
|
||||||
Rename.Column("OnDelete").OnTable("Notifications").To("OnMovieDelete");
|
Rename.Column("OnDelete").OnTable("Notifications").To("OnMovieDelete");
|
||||||
Alter.Table("Notifications").AddColumn("OnMovieFileDelete").AsBoolean().WithDefaultValue(0);
|
Alter.Table("Notifications").AddColumn("OnMovieFileDelete").AsBoolean().WithDefaultValue(false);
|
||||||
Alter.Table("Notifications").AddColumn("OnMovieFileDeleteForUpgrade").AsBoolean().WithDefaultValue(0);
|
Alter.Table("Notifications").AddColumn("OnMovieFileDeleteForUpgrade").AsBoolean().WithDefaultValue(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ protected override void MainDbUpgrade()
|
|||||||
Alter.Table("DelayProfiles").AddColumn("BypassIfHighestQuality").AsBoolean().WithDefaultValue(false);
|
Alter.Table("DelayProfiles").AddColumn("BypassIfHighestQuality").AsBoolean().WithDefaultValue(false);
|
||||||
|
|
||||||
// Set to true for existing Delay Profiles to keep behavior the same.
|
// Set to true for existing Delay Profiles to keep behavior the same.
|
||||||
Execute.Sql("UPDATE DelayProfiles SET BypassIfHighestQuality = 1;");
|
Update.Table("DelayProfiles").Set(new { BypassIfHighestQuality = true }).AllRows();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ public class update_notifiarr : NzbDroneMigrationBase
|
|||||||
{
|
{
|
||||||
protected override void MainDbUpgrade()
|
protected override void MainDbUpgrade()
|
||||||
{
|
{
|
||||||
Execute.Sql("UPDATE Notifications SET Implementation = Replace(Implementation, 'DiscordNotifier', 'Notifiarr'),ConfigContract = Replace(ConfigContract, 'DiscordNotifierSettings', 'NotifiarrSettings') WHERE Implementation = 'DiscordNotifier';");
|
Execute.Sql("UPDATE \"Notifications\" SET \"Implementation\" = Replace(\"Implementation\", 'DiscordNotifier', 'Notifiarr'),\"ConfigContract\" = Replace(\"ConfigContract\", 'DiscordNotifierSettings', 'NotifiarrSettings') WHERE \"Implementation\" = 'DiscordNotifier';");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@ public class legacy_mediainfo_hdr : NzbDroneMigrationBase
|
|||||||
{
|
{
|
||||||
protected override void MainDbUpgrade()
|
protected override void MainDbUpgrade()
|
||||||
{
|
{
|
||||||
Execute.Sql("UPDATE NamingConfig SET StandardMovieFormat = Replace(StandardMovieFormat, '{MediaInfo HDR}', '{MediaInfo VideoDynamicRange}');");
|
Execute.Sql("UPDATE \"NamingConfig\" SET \"StandardMovieFormat\" = Replace(\"StandardMovieFormat\", '{MediaInfo HDR}', '{MediaInfo VideoDynamicRange}');");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,7 @@ protected override void MainDbUpgrade()
|
|||||||
|
|
||||||
private void MigrateToFfprobe(IDbConnection conn, IDbTransaction tran)
|
private void MigrateToFfprobe(IDbConnection conn, IDbTransaction tran)
|
||||||
{
|
{
|
||||||
var existing = conn.Query<MediaInfoRaw>("SELECT Id, MediaInfo, SceneName FROM MovieFiles");
|
var existing = conn.Query<MediaInfoRaw>("SELECT \"Id\", \"MediaInfo\", \"SceneName\" FROM \"MovieFiles\"");
|
||||||
|
|
||||||
var updated = new List<MediaInfoRaw>();
|
var updated = new List<MediaInfoRaw>();
|
||||||
|
|
||||||
@ -78,7 +78,7 @@ private void MigrateToFfprobe(IDbConnection conn, IDbTransaction tran)
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
var updateSql = "UPDATE MovieFiles SET MediaInfo = @MediaInfo WHERE Id = @Id";
|
var updateSql = "UPDATE \"MovieFiles\" SET \"MediaInfo\" = @MediaInfo WHERE \"Id\" = @Id";
|
||||||
conn.Execute(updateSql, updated, transaction: tran);
|
conn.Execute(updateSql, updated, transaction: tran);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ private void MoveRemoveSettings(IDbConnection conn, IDbTransaction tran)
|
|||||||
var removeCompletedDownloads = false;
|
var removeCompletedDownloads = false;
|
||||||
var removeFailedDownloads = true;
|
var removeFailedDownloads = true;
|
||||||
|
|
||||||
using (var removeCompletedDownloadsCmd = conn.CreateCommand(tran, "SELECT Value FROM Config WHERE Key = 'removecompleteddownloads'"))
|
using (var removeCompletedDownloadsCmd = conn.CreateCommand(tran, "SELECT \"Value\" FROM \"Config\" WHERE \"Key\" = 'removecompleteddownloads'"))
|
||||||
{
|
{
|
||||||
if ((removeCompletedDownloadsCmd.ExecuteScalar() as string)?.ToLower() == "true")
|
if ((removeCompletedDownloadsCmd.ExecuteScalar() as string)?.ToLower() == "true")
|
||||||
{
|
{
|
||||||
@ -32,7 +32,7 @@ private void MoveRemoveSettings(IDbConnection conn, IDbTransaction tran)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
using (var removeFailedDownloadsCmd = conn.CreateCommand(tran, "SELECT Value FROM Config WHERE Key = 'removefaileddownloads'"))
|
using (var removeFailedDownloadsCmd = conn.CreateCommand(tran, "SELECT \"Value\" FROM \"Config\" WHERE \"Key\" = 'removefaileddownloads'"))
|
||||||
{
|
{
|
||||||
if ((removeFailedDownloadsCmd.ExecuteScalar() as string)?.ToLower() == "false")
|
if ((removeFailedDownloadsCmd.ExecuteScalar() as string)?.ToLower() == "false")
|
||||||
{
|
{
|
||||||
@ -40,14 +40,25 @@ private void MoveRemoveSettings(IDbConnection conn, IDbTransaction tran)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
using (var updateClientCmd = conn.CreateCommand(tran, $"UPDATE DownloadClients SET RemoveCompletedDownloads = (CASE WHEN Implementation IN (\"RTorrent\", \"Flood\") THEN 0 ELSE ? END), RemoveFailedDownloads = ?"))
|
string commandText;
|
||||||
|
|
||||||
|
if (conn.GetType().FullName == "Npgsql.NpgsqlConnection")
|
||||||
{
|
{
|
||||||
updateClientCmd.AddParameter(removeCompletedDownloads ? 1 : 0);
|
commandText = $"UPDATE \"DownloadClients\" SET \"RemoveCompletedDownloads\" = (CASE WHEN \"Implementation\" IN ('RTorrent', 'Flood') THEN 'false' ELSE $1 END), \"RemoveFailedDownloads\" = $2";
|
||||||
updateClientCmd.AddParameter(removeFailedDownloads ? 1 : 0);
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
commandText = $"UPDATE \"DownloadClients\" SET \"RemoveCompletedDownloads\" = (CASE WHEN \"Implementation\" IN ('RTorrent', 'Flood') THEN 'false' ELSE ? END), \"RemoveFailedDownloads\" = ?";
|
||||||
|
}
|
||||||
|
|
||||||
|
using (var updateClientCmd = conn.CreateCommand(tran, commandText))
|
||||||
|
{
|
||||||
|
updateClientCmd.AddParameter(removeCompletedDownloads);
|
||||||
|
updateClientCmd.AddParameter(removeFailedDownloads);
|
||||||
updateClientCmd.ExecuteNonQuery();
|
updateClientCmd.ExecuteNonQuery();
|
||||||
}
|
}
|
||||||
|
|
||||||
using (var removeConfigCmd = conn.CreateCommand(tran, $"DELETE FROM Config WHERE Key IN ('removecompleteddownloads', 'removefaileddownloads')"))
|
using (var removeConfigCmd = conn.CreateCommand(tran, $"DELETE FROM \"Config\" WHERE \"Key\" IN ('removecompleteddownloads', 'removefaileddownloads')"))
|
||||||
{
|
{
|
||||||
removeConfigCmd.ExecuteNonQuery();
|
removeConfigCmd.ExecuteNonQuery();
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ protected override void MainDbUpgrade()
|
|||||||
|
|
||||||
private void MigrateDiscordFromSlack(IDbConnection conn, IDbTransaction tran)
|
private void MigrateDiscordFromSlack(IDbConnection conn, IDbTransaction tran)
|
||||||
{
|
{
|
||||||
var notificationRows = conn.Query<NotificationEntity201>($"SELECT Id,ConfigContract,Implementation,Name,Settings FROM Notifications WHERE Implementation = 'Slack'");
|
var notificationRows = conn.Query<NotificationEntity201>($"SELECT \"Id\",\"ConfigContract\",\"Implementation\",\"Name\",\"Settings\" FROM \"Notifications\" WHERE \"Implementation\" = 'Slack'");
|
||||||
|
|
||||||
var discordSlackNotifications = notificationRows.Where(n => JsonSerializer.Deserialize<SlackNotificationSettings201>(n.Settings, _serializerSettings).WebHookUrl.Contains("discord"));
|
var discordSlackNotifications = notificationRows.Where(n => JsonSerializer.Deserialize<SlackNotificationSettings201>(n.Settings, _serializerSettings).WebHookUrl.Contains("discord"));
|
||||||
|
|
||||||
@ -63,11 +63,11 @@ private void MigrateDiscordFromSlack(IDbConnection conn, IDbTransaction tran)
|
|||||||
notification.Settings = JsonSerializer.Serialize(discordSettings, _serializerSettings);
|
notification.Settings = JsonSerializer.Serialize(discordSettings, _serializerSettings);
|
||||||
}
|
}
|
||||||
|
|
||||||
var updateSql = "UPDATE Notifications SET ConfigContract = @ConfigContract, " +
|
var updateSql = "UPDATE \"Notifications\" SET \"ConfigContract\" = @ConfigContract, " +
|
||||||
"Implementation = @Implementation, " +
|
"\"Implementation\" = @Implementation, " +
|
||||||
"Name = @Name, " +
|
"\"Name\" = @Name, " +
|
||||||
"Settings = @Settings " +
|
"\"Settings\" = @Settings " +
|
||||||
"WHERE Id = @Id";
|
"WHERE \"Id\" = @Id";
|
||||||
|
|
||||||
conn.Execute(updateSql, discordSlackNotifications, transaction: tran);
|
conn.Execute(updateSql, discordSlackNotifications, transaction: tran);
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@ public class add_on_update_to_notifications : NzbDroneMigrationBase
|
|||||||
{
|
{
|
||||||
protected override void MainDbUpgrade()
|
protected override void MainDbUpgrade()
|
||||||
{
|
{
|
||||||
Alter.Table("Notifications").AddColumn("OnApplicationUpdate").AsBoolean().WithDefaultValue(0);
|
Alter.Table("Notifications").AddColumn("OnApplicationUpdate").AsBoolean().WithDefaultValue(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,17 +11,17 @@ protected override void MainDbUpgrade()
|
|||||||
//Purge Commands before reworking tables
|
//Purge Commands before reworking tables
|
||||||
Delete.FromTable("Commands").AllRows();
|
Delete.FromTable("Commands").AllRows();
|
||||||
|
|
||||||
Alter.Column("Id").OnTable("Movies").AsInt32().PrimaryKey().Identity();
|
IfDatabase("sqlite").Alter.Column("Id").OnTable("Movies").AsInt32().PrimaryKey().Identity();
|
||||||
Alter.Column("Id").OnTable("MovieTranslations").AsInt32().PrimaryKey().Identity();
|
IfDatabase("sqlite").Alter.Column("Id").OnTable("MovieTranslations").AsInt32().PrimaryKey().Identity();
|
||||||
Alter.Column("Id").OnTable("Commands").AsInt32().PrimaryKey().Identity();
|
IfDatabase("sqlite").Alter.Column("Id").OnTable("Commands").AsInt32().PrimaryKey().Identity();
|
||||||
Alter.Column("Id").OnTable("Credits").AsInt32().PrimaryKey().Identity();
|
IfDatabase("sqlite").Alter.Column("Id").OnTable("Credits").AsInt32().PrimaryKey().Identity();
|
||||||
Alter.Column("Id").OnTable("Profiles").AsInt32().PrimaryKey().Identity();
|
IfDatabase("sqlite").Alter.Column("Id").OnTable("Profiles").AsInt32().PrimaryKey().Identity();
|
||||||
Alter.Column("Id").OnTable("PendingReleases").AsInt32().PrimaryKey().Identity();
|
IfDatabase("sqlite").Alter.Column("Id").OnTable("PendingReleases").AsInt32().PrimaryKey().Identity();
|
||||||
Alter.Column("Id").OnTable("NamingConfig").AsInt32().PrimaryKey().Identity();
|
IfDatabase("sqlite").Alter.Column("Id").OnTable("NamingConfig").AsInt32().PrimaryKey().Identity();
|
||||||
Alter.Column("Id").OnTable("History").AsInt32().PrimaryKey().Identity();
|
IfDatabase("sqlite").Alter.Column("Id").OnTable("History").AsInt32().PrimaryKey().Identity();
|
||||||
Alter.Column("Id").OnTable("Blocklist").AsInt32().PrimaryKey().Identity();
|
IfDatabase("sqlite").Alter.Column("Id").OnTable("Blocklist").AsInt32().PrimaryKey().Identity();
|
||||||
Alter.Column("Id").OnTable("MovieFiles").AsInt32().PrimaryKey().Identity();
|
IfDatabase("sqlite").Alter.Column("Id").OnTable("MovieFiles").AsInt32().PrimaryKey().Identity();
|
||||||
Alter.Column("Id").OnTable("CustomFormats").AsInt32().PrimaryKey().Identity();
|
IfDatabase("sqlite").Alter.Column("Id").OnTable("CustomFormats").AsInt32().PrimaryKey().Identity();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,8 +28,8 @@ public multiple_ratings_support()
|
|||||||
|
|
||||||
protected override void MainDbUpgrade()
|
protected override void MainDbUpgrade()
|
||||||
{
|
{
|
||||||
Execute.Sql("UPDATE CustomFilters SET Filters = Replace(Filters, 'ratings', 'tmdbRating') WHERE Type = 'discoverMovie';");
|
Execute.Sql("UPDATE \"CustomFilters\" SET \"Filters\" = Replace(\"Filters\", 'ratings', 'tmdbRating') WHERE \"Type\" = 'discoverMovie';");
|
||||||
Execute.Sql("UPDATE CustomFilters SET Filters = Replace(Filters, 'ratings', 'tmdbRating') WHERE Type = 'movieIndex';");
|
Execute.Sql("UPDATE \"CustomFilters\" SET \"Filters\" = Replace(\"Filters\", 'ratings', 'tmdbRating') WHERE \"Type\" = 'movieIndex';");
|
||||||
|
|
||||||
Execute.WithConnection((conn, tran) => FixRatings(conn, tran, "Movies"));
|
Execute.WithConnection((conn, tran) => FixRatings(conn, tran, "Movies"));
|
||||||
Execute.WithConnection((conn, tran) => FixRatings(conn, tran, "ImportListMovies"));
|
Execute.WithConnection((conn, tran) => FixRatings(conn, tran, "ImportListMovies"));
|
||||||
@ -37,7 +37,7 @@ protected override void MainDbUpgrade()
|
|||||||
|
|
||||||
private void FixRatings(IDbConnection conn, IDbTransaction tran, string table)
|
private void FixRatings(IDbConnection conn, IDbTransaction tran, string table)
|
||||||
{
|
{
|
||||||
var rows = conn.Query<Movie205>($"SELECT Id, Ratings FROM {table}");
|
var rows = conn.Query<Movie205>($"SELECT \"Id\", \"Ratings\" FROM \"{table}\"");
|
||||||
|
|
||||||
var corrected = new List<Movie206>();
|
var corrected = new List<Movie206>();
|
||||||
|
|
||||||
@ -68,7 +68,7 @@ private void FixRatings(IDbConnection conn, IDbTransaction tran, string table)
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
var updateSql = $"UPDATE {table} SET Ratings = @Ratings WHERE Id = @Id";
|
var updateSql = $"UPDATE \"{table}\" SET \"Ratings\" = @Ratings WHERE \"Id\" = @Id";
|
||||||
conn.Execute(updateSql, corrected, transaction: tran);
|
conn.Execute(updateSql, corrected, transaction: tran);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using FluentMigrator.Runner;
|
using FluentMigrator.Runner;
|
||||||
|
using FluentMigrator.Runner.Generators;
|
||||||
using FluentMigrator.Runner.Initialization;
|
using FluentMigrator.Runner.Initialization;
|
||||||
using FluentMigrator.Runner.Processors;
|
using FluentMigrator.Runner.Processors;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
@ -34,11 +35,16 @@ public void Migrate(string connectionString, MigrationContext migrationContext)
|
|||||||
|
|
||||||
_logger.Info("*** Migrating {0} ***", connectionString);
|
_logger.Info("*** Migrating {0} ***", connectionString);
|
||||||
|
|
||||||
var serviceProvider = new ServiceCollection()
|
ServiceProvider serviceProvider;
|
||||||
|
|
||||||
|
var db = connectionString.Contains(".db") ? "sqlite" : "postgres";
|
||||||
|
|
||||||
|
serviceProvider = new ServiceCollection()
|
||||||
.AddLogging(b => b.AddNLog())
|
.AddLogging(b => b.AddNLog())
|
||||||
.AddFluentMigratorCore()
|
.AddFluentMigratorCore()
|
||||||
.ConfigureRunner(
|
.ConfigureRunner(
|
||||||
builder => builder
|
builder => builder
|
||||||
|
.AddPostgres()
|
||||||
.AddNzbDroneSQLite()
|
.AddNzbDroneSQLite()
|
||||||
.WithGlobalConnectionString(connectionString)
|
.WithGlobalConnectionString(connectionString)
|
||||||
.WithMigrationsIn(Assembly.GetExecutingAssembly()))
|
.WithMigrationsIn(Assembly.GetExecutingAssembly()))
|
||||||
@ -48,6 +54,14 @@ public void Migrate(string connectionString, MigrationContext migrationContext)
|
|||||||
opt.PreviewOnly = false;
|
opt.PreviewOnly = false;
|
||||||
opt.Timeout = TimeSpan.FromSeconds(60);
|
opt.Timeout = TimeSpan.FromSeconds(60);
|
||||||
})
|
})
|
||||||
|
.Configure<SelectingProcessorAccessorOptions>(cfg =>
|
||||||
|
{
|
||||||
|
cfg.ProcessorId = db;
|
||||||
|
})
|
||||||
|
.Configure<SelectingGeneratorAccessorOptions>(cfg =>
|
||||||
|
{
|
||||||
|
cfg.GeneratorId = db;
|
||||||
|
})
|
||||||
.BuildServiceProvider();
|
.BuildServiceProvider();
|
||||||
|
|
||||||
using (var scope = serviceProvider.CreateScope())
|
using (var scope = serviceProvider.CreateScope())
|
||||||
|
@ -8,9 +8,17 @@ namespace NzbDrone.Core.Datastore
|
|||||||
public class SqlBuilder
|
public class SqlBuilder
|
||||||
{
|
{
|
||||||
private readonly Dictionary<string, Clauses> _data = new Dictionary<string, Clauses>();
|
private readonly Dictionary<string, Clauses> _data = new Dictionary<string, Clauses>();
|
||||||
|
private readonly DatabaseType _databaseType;
|
||||||
|
|
||||||
|
public SqlBuilder(DatabaseType databaseType)
|
||||||
|
{
|
||||||
|
_databaseType = databaseType;
|
||||||
|
}
|
||||||
|
|
||||||
public int Sequence { get; private set; }
|
public int Sequence { get; private set; }
|
||||||
|
|
||||||
|
public DatabaseType DatabaseType => _databaseType;
|
||||||
|
|
||||||
public Template AddTemplate(string sql, dynamic parameters = null) =>
|
public Template AddTemplate(string sql, dynamic parameters = null) =>
|
||||||
new Template(this, sql, parameters);
|
new Template(this, sql, parameters);
|
||||||
|
|
||||||
|
@ -49,17 +49,17 @@ public string TableNameMapping(Type x)
|
|||||||
|
|
||||||
public string SelectTemplate(Type x)
|
public string SelectTemplate(Type x)
|
||||||
{
|
{
|
||||||
return $"SELECT /**select**/ FROM {TableMap[x]} /**join**/ /**innerjoin**/ /**leftjoin**/ /**where**/ /**groupby**/ /**having**/ /**orderby**/";
|
return $"SELECT /**select**/ FROM \"{TableMap[x]}\" /**join**/ /**innerjoin**/ /**leftjoin**/ /**where**/ /**groupby**/ /**having**/ /**orderby**/";
|
||||||
}
|
}
|
||||||
|
|
||||||
public string DeleteTemplate(Type x)
|
public string DeleteTemplate(Type x)
|
||||||
{
|
{
|
||||||
return $"DELETE FROM {TableMap[x]} /**where**/";
|
return $"DELETE FROM \"{TableMap[x]}\" /**where**/";
|
||||||
}
|
}
|
||||||
|
|
||||||
public string PageCountTemplate(Type x)
|
public string PageCountTemplate(Type x)
|
||||||
{
|
{
|
||||||
return $"SELECT /**select**/ FROM {TableMap[x]} /**join**/ /**innerjoin**/ /**leftjoin**/ /**where**/";
|
return $"SELECT /**select**/ FROM \"{TableMap[x]}\" /**join**/ /**innerjoin**/ /**leftjoin**/ /**where**/";
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsValidSortKey(string sortKey)
|
public bool IsValidSortKey(string sortKey)
|
||||||
@ -90,6 +90,35 @@ public bool IsValidSortKey(string sortKey)
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string GetSortKey(string sortKey)
|
||||||
|
{
|
||||||
|
string table = null;
|
||||||
|
|
||||||
|
if (sortKey.Contains('.'))
|
||||||
|
{
|
||||||
|
var split = sortKey.Split('.');
|
||||||
|
if (split.Length != 2)
|
||||||
|
{
|
||||||
|
return sortKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
table = split[0];
|
||||||
|
sortKey = split[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (table != null && !TableMap.Values.Contains(table, StringComparer.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
return sortKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!_allowedOrderBy.Contains(sortKey))
|
||||||
|
{
|
||||||
|
return sortKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
return _allowedOrderBy.First(x => x.Equals(sortKey, StringComparison.OrdinalIgnoreCase));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class LazyLoadedProperty
|
public class LazyLoadedProperty
|
||||||
@ -154,7 +183,7 @@ public ColumnMapper<T> HasOne<TChild>(Expression<Func<T, LazyLoaded<TChild>>> po
|
|||||||
(db, parent) =>
|
(db, parent) =>
|
||||||
{
|
{
|
||||||
var id = childIdSelector(parent);
|
var id = childIdSelector(parent);
|
||||||
return db.Query<TChild>(new SqlBuilder().Where<TChild>(x => x.Id == id)).SingleOrDefault();
|
return db.Query<TChild>(new SqlBuilder(db.DatabaseType).Where<TChild>(x => x.Id == id)).SingleOrDefault();
|
||||||
},
|
},
|
||||||
parent => childIdSelector(parent) > 0);
|
parent => childIdSelector(parent) > 0);
|
||||||
}
|
}
|
||||||
|
@ -1,389 +1,9 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Data;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Linq.Expressions;
|
|
||||||
using System.Reflection;
|
|
||||||
using System.Text;
|
|
||||||
using Dapper;
|
using Dapper;
|
||||||
|
|
||||||
namespace NzbDrone.Core.Datastore
|
namespace NzbDrone.Core.Datastore
|
||||||
{
|
{
|
||||||
public class WhereBuilder : ExpressionVisitor
|
public abstract class WhereBuilder : ExpressionVisitor
|
||||||
{
|
{
|
||||||
protected StringBuilder _sb;
|
public DynamicParameters Parameters { get; protected set; }
|
||||||
|
|
||||||
private const DbType EnumerableMultiParameter = (DbType)(-1);
|
|
||||||
private readonly string _paramNamePrefix;
|
|
||||||
private readonly bool _requireConcreteValue = false;
|
|
||||||
private int _paramCount = 0;
|
|
||||||
private bool _gotConcreteValue = false;
|
|
||||||
|
|
||||||
public WhereBuilder(Expression filter, bool requireConcreteValue, int seq)
|
|
||||||
{
|
|
||||||
_paramNamePrefix = string.Format("Clause{0}", seq + 1);
|
|
||||||
_requireConcreteValue = requireConcreteValue;
|
|
||||||
_sb = new StringBuilder();
|
|
||||||
|
|
||||||
Parameters = new DynamicParameters();
|
|
||||||
|
|
||||||
if (filter != null)
|
|
||||||
{
|
|
||||||
Visit(filter);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public DynamicParameters Parameters { get; private set; }
|
|
||||||
|
|
||||||
private string AddParameter(object value, DbType? dbType = null)
|
|
||||||
{
|
|
||||||
_gotConcreteValue = true;
|
|
||||||
_paramCount++;
|
|
||||||
var name = _paramNamePrefix + "_P" + _paramCount;
|
|
||||||
Parameters.Add(name, value, dbType);
|
|
||||||
return '@' + name;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override Expression VisitBinary(BinaryExpression expression)
|
|
||||||
{
|
|
||||||
_sb.Append('(');
|
|
||||||
|
|
||||||
Visit(expression.Left);
|
|
||||||
|
|
||||||
_sb.AppendFormat(" {0} ", Decode(expression));
|
|
||||||
|
|
||||||
Visit(expression.Right);
|
|
||||||
|
|
||||||
_sb.Append(')');
|
|
||||||
|
|
||||||
return expression;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override Expression VisitMethodCall(MethodCallExpression expression)
|
|
||||||
{
|
|
||||||
var method = expression.Method.Name;
|
|
||||||
|
|
||||||
switch (expression.Method.Name)
|
|
||||||
{
|
|
||||||
case "Contains":
|
|
||||||
ParseContainsExpression(expression);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case "StartsWith":
|
|
||||||
ParseStartsWith(expression);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case "EndsWith":
|
|
||||||
ParseEndsWith(expression);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
var msg = string.Format("'{0}' expressions are not yet implemented in the where clause expression tree parser.", method);
|
|
||||||
throw new NotImplementedException(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
return expression;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override Expression VisitMemberAccess(MemberExpression expression)
|
|
||||||
{
|
|
||||||
var tableName = expression?.Expression?.Type != null ? TableMapping.Mapper.TableNameMapping(expression.Expression.Type) : null;
|
|
||||||
var gotValue = TryGetRightValue(expression, out var value);
|
|
||||||
|
|
||||||
// Only use the SQL condition if the expression didn't resolve to an actual value
|
|
||||||
if (tableName != null && !gotValue)
|
|
||||||
{
|
|
||||||
_sb.Append($"\"{tableName}\".\"{expression.Member.Name}\"");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (value != null)
|
|
||||||
{
|
|
||||||
// string is IEnumerable<Char> but we don't want to pick up that case
|
|
||||||
var type = value.GetType();
|
|
||||||
var typeInfo = type.GetTypeInfo();
|
|
||||||
var isEnumerable =
|
|
||||||
type != typeof(string) && (
|
|
||||||
typeInfo.ImplementedInterfaces.Any(ti => ti.IsGenericType && ti.GetGenericTypeDefinition() == typeof(IEnumerable<>)) ||
|
|
||||||
(typeInfo.IsGenericType && typeInfo.GetGenericTypeDefinition() == typeof(IEnumerable<>)));
|
|
||||||
|
|
||||||
var paramName = isEnumerable ? AddParameter(value, EnumerableMultiParameter) : AddParameter(value);
|
|
||||||
_sb.Append(paramName);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_gotConcreteValue = true;
|
|
||||||
_sb.Append("NULL");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return expression;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override Expression VisitConstant(ConstantExpression expression)
|
|
||||||
{
|
|
||||||
if (expression.Value != null)
|
|
||||||
{
|
|
||||||
var paramName = AddParameter(expression.Value);
|
|
||||||
_sb.Append(paramName);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_gotConcreteValue = true;
|
|
||||||
_sb.Append("NULL");
|
|
||||||
}
|
|
||||||
|
|
||||||
return expression;
|
|
||||||
}
|
|
||||||
|
|
||||||
private bool TryGetConstantValue(Expression expression, out object result)
|
|
||||||
{
|
|
||||||
result = null;
|
|
||||||
|
|
||||||
if (expression is ConstantExpression constExp)
|
|
||||||
{
|
|
||||||
result = constExp.Value;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private bool TryGetPropertyValue(MemberExpression expression, out object result)
|
|
||||||
{
|
|
||||||
result = null;
|
|
||||||
|
|
||||||
if (expression.Expression is MemberExpression nested)
|
|
||||||
{
|
|
||||||
// Value is passed in as a property on a parent entity
|
|
||||||
var container = (nested.Expression as ConstantExpression)?.Value;
|
|
||||||
|
|
||||||
if (container == null)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
var entity = GetFieldValue(container, nested.Member);
|
|
||||||
result = GetFieldValue(entity, expression.Member);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private bool TryGetVariableValue(MemberExpression expression, out object result)
|
|
||||||
{
|
|
||||||
result = null;
|
|
||||||
|
|
||||||
// Value is passed in as a variable
|
|
||||||
if (expression.Expression is ConstantExpression nested)
|
|
||||||
{
|
|
||||||
result = GetFieldValue(nested.Value, expression.Member);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private bool TryGetRightValue(Expression expression, out object value)
|
|
||||||
{
|
|
||||||
value = null;
|
|
||||||
|
|
||||||
if (TryGetConstantValue(expression, out value))
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
var memberExp = expression as MemberExpression;
|
|
||||||
|
|
||||||
if (TryGetPropertyValue(memberExp, out value))
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (TryGetVariableValue(memberExp, out value))
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private object GetFieldValue(object entity, MemberInfo member)
|
|
||||||
{
|
|
||||||
if (member.MemberType == MemberTypes.Field)
|
|
||||||
{
|
|
||||||
return (member as FieldInfo).GetValue(entity);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (member.MemberType == MemberTypes.Property)
|
|
||||||
{
|
|
||||||
return (member as PropertyInfo).GetValue(entity);
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new ArgumentException(string.Format("WhereBuilder could not get the value for {0}.{1}.", entity.GetType().Name, member.Name));
|
|
||||||
}
|
|
||||||
|
|
||||||
private bool IsNullVariable(Expression expression)
|
|
||||||
{
|
|
||||||
if (expression.NodeType == ExpressionType.Constant &&
|
|
||||||
TryGetConstantValue(expression, out var constResult) &&
|
|
||||||
constResult == null)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (expression.NodeType == ExpressionType.MemberAccess &&
|
|
||||||
expression is MemberExpression member &&
|
|
||||||
((TryGetPropertyValue(member, out var result) && result == null) ||
|
|
||||||
(TryGetVariableValue(member, out result) && result == null)))
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private string Decode(BinaryExpression expression)
|
|
||||||
{
|
|
||||||
if (IsNullVariable(expression.Right))
|
|
||||||
{
|
|
||||||
switch (expression.NodeType)
|
|
||||||
{
|
|
||||||
case ExpressionType.Equal: return "IS";
|
|
||||||
case ExpressionType.NotEqual: return "IS NOT";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (expression.NodeType)
|
|
||||||
{
|
|
||||||
case ExpressionType.AndAlso: return "AND";
|
|
||||||
case ExpressionType.And: return "AND";
|
|
||||||
case ExpressionType.Equal: return "=";
|
|
||||||
case ExpressionType.GreaterThan: return ">";
|
|
||||||
case ExpressionType.GreaterThanOrEqual: return ">=";
|
|
||||||
case ExpressionType.LessThan: return "<";
|
|
||||||
case ExpressionType.LessThanOrEqual: return "<=";
|
|
||||||
case ExpressionType.NotEqual: return "<>";
|
|
||||||
case ExpressionType.OrElse: return "OR";
|
|
||||||
case ExpressionType.Or: return "OR";
|
|
||||||
default: throw new NotSupportedException(string.Format("{0} statement is not supported", expression.NodeType.ToString()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ParseContainsExpression(MethodCallExpression expression)
|
|
||||||
{
|
|
||||||
var list = expression.Object;
|
|
||||||
|
|
||||||
if (list != null && (list.Type == typeof(string)))
|
|
||||||
{
|
|
||||||
ParseStringContains(expression);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ParseEnumerableContains(expression);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ParseEnumerableContains(MethodCallExpression body)
|
|
||||||
{
|
|
||||||
// Fish out the list and the item to compare
|
|
||||||
// It's in a different form for arrays and Lists
|
|
||||||
var list = body.Object;
|
|
||||||
Expression item;
|
|
||||||
|
|
||||||
if (list != null)
|
|
||||||
{
|
|
||||||
// Generic collection
|
|
||||||
item = body.Arguments[0];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Static method
|
|
||||||
// Must be Enumerable.Contains(source, item)
|
|
||||||
if (body.Method.DeclaringType != typeof(Enumerable) || body.Arguments.Count != 2)
|
|
||||||
{
|
|
||||||
throw new NotSupportedException("Unexpected form of Enumerable.Contains");
|
|
||||||
}
|
|
||||||
|
|
||||||
list = body.Arguments[0];
|
|
||||||
item = body.Arguments[1];
|
|
||||||
}
|
|
||||||
|
|
||||||
_sb.Append('(');
|
|
||||||
|
|
||||||
Visit(item);
|
|
||||||
|
|
||||||
_sb.Append(" IN ");
|
|
||||||
|
|
||||||
// hardcode the integer list if it exists to bypass parameter limit
|
|
||||||
if (item.Type == typeof(int) && TryGetRightValue(list, out var value))
|
|
||||||
{
|
|
||||||
var items = (IEnumerable<int>)value;
|
|
||||||
_sb.Append('(');
|
|
||||||
_sb.Append(string.Join(", ", items));
|
|
||||||
_sb.Append(')');
|
|
||||||
|
|
||||||
_gotConcreteValue = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Visit(list);
|
|
||||||
}
|
|
||||||
|
|
||||||
_sb.Append(')');
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ParseStringContains(MethodCallExpression body)
|
|
||||||
{
|
|
||||||
_sb.Append('(');
|
|
||||||
|
|
||||||
Visit(body.Object);
|
|
||||||
|
|
||||||
_sb.Append(" LIKE '%' || ");
|
|
||||||
|
|
||||||
Visit(body.Arguments[0]);
|
|
||||||
|
|
||||||
_sb.Append(" || '%')");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ParseStartsWith(MethodCallExpression body)
|
|
||||||
{
|
|
||||||
_sb.Append('(');
|
|
||||||
|
|
||||||
Visit(body.Object);
|
|
||||||
|
|
||||||
_sb.Append(" LIKE ");
|
|
||||||
|
|
||||||
Visit(body.Arguments[0]);
|
|
||||||
|
|
||||||
_sb.Append(" || '%')");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ParseEndsWith(MethodCallExpression body)
|
|
||||||
{
|
|
||||||
_sb.Append('(');
|
|
||||||
|
|
||||||
Visit(body.Object);
|
|
||||||
|
|
||||||
_sb.Append(" LIKE '%' || ");
|
|
||||||
|
|
||||||
Visit(body.Arguments[0]);
|
|
||||||
|
|
||||||
_sb.Append(')');
|
|
||||||
}
|
|
||||||
|
|
||||||
public override string ToString()
|
|
||||||
{
|
|
||||||
var sql = _sb.ToString();
|
|
||||||
|
|
||||||
if (_requireConcreteValue && !_gotConcreteValue)
|
|
||||||
{
|
|
||||||
var e = new InvalidOperationException("WhereBuilder requires a concrete condition");
|
|
||||||
e.Data.Add("sql", sql);
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
|
|
||||||
return sql;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
387
src/NzbDrone.Core/Datastore/WhereBuilderPostgres.cs
Normal file
387
src/NzbDrone.Core/Datastore/WhereBuilderPostgres.cs
Normal file
@ -0,0 +1,387 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Text;
|
||||||
|
using Dapper;
|
||||||
|
|
||||||
|
namespace NzbDrone.Core.Datastore
|
||||||
|
{
|
||||||
|
public class WhereBuilderPostgres : WhereBuilder
|
||||||
|
{
|
||||||
|
protected StringBuilder _sb;
|
||||||
|
|
||||||
|
private const DbType EnumerableMultiParameter = (DbType)(-1);
|
||||||
|
private readonly string _paramNamePrefix;
|
||||||
|
private readonly bool _requireConcreteValue = false;
|
||||||
|
private int _paramCount = 0;
|
||||||
|
private bool _gotConcreteValue = false;
|
||||||
|
|
||||||
|
public WhereBuilderPostgres(Expression filter, bool requireConcreteValue, int seq)
|
||||||
|
{
|
||||||
|
_paramNamePrefix = string.Format("Clause{0}", seq + 1);
|
||||||
|
_requireConcreteValue = requireConcreteValue;
|
||||||
|
_sb = new StringBuilder();
|
||||||
|
|
||||||
|
Parameters = new DynamicParameters();
|
||||||
|
|
||||||
|
if (filter != null)
|
||||||
|
{
|
||||||
|
Visit(filter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private string AddParameter(object value, DbType? dbType = null)
|
||||||
|
{
|
||||||
|
_gotConcreteValue = true;
|
||||||
|
_paramCount++;
|
||||||
|
var name = _paramNamePrefix + "_P" + _paramCount;
|
||||||
|
Parameters.Add(name, value, dbType);
|
||||||
|
return '@' + name;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override Expression VisitBinary(BinaryExpression expression)
|
||||||
|
{
|
||||||
|
_sb.Append('(');
|
||||||
|
|
||||||
|
Visit(expression.Left);
|
||||||
|
|
||||||
|
_sb.AppendFormat(" {0} ", Decode(expression));
|
||||||
|
|
||||||
|
Visit(expression.Right);
|
||||||
|
|
||||||
|
_sb.Append(')');
|
||||||
|
|
||||||
|
return expression;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override Expression VisitMethodCall(MethodCallExpression expression)
|
||||||
|
{
|
||||||
|
var method = expression.Method.Name;
|
||||||
|
|
||||||
|
switch (expression.Method.Name)
|
||||||
|
{
|
||||||
|
case "Contains":
|
||||||
|
ParseContainsExpression(expression);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "StartsWith":
|
||||||
|
ParseStartsWith(expression);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "EndsWith":
|
||||||
|
ParseEndsWith(expression);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
var msg = string.Format("'{0}' expressions are not yet implemented in the where clause expression tree parser.", method);
|
||||||
|
throw new NotImplementedException(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
return expression;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override Expression VisitMemberAccess(MemberExpression expression)
|
||||||
|
{
|
||||||
|
var tableName = expression?.Expression?.Type != null ? TableMapping.Mapper.TableNameMapping(expression.Expression.Type) : null;
|
||||||
|
var gotValue = TryGetRightValue(expression, out var value);
|
||||||
|
|
||||||
|
// Only use the SQL condition if the expression didn't resolve to an actual value
|
||||||
|
if (tableName != null && !gotValue)
|
||||||
|
{
|
||||||
|
_sb.Append($"\"{tableName}\".\"{expression.Member.Name.ToLower()}\"");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (value != null)
|
||||||
|
{
|
||||||
|
// string is IEnumerable<Char> but we don't want to pick up that case
|
||||||
|
var type = value.GetType();
|
||||||
|
var typeInfo = type.GetTypeInfo();
|
||||||
|
var isEnumerable =
|
||||||
|
type != typeof(string) && (
|
||||||
|
typeInfo.ImplementedInterfaces.Any(ti => ti.IsGenericType && ti.GetGenericTypeDefinition() == typeof(IEnumerable<>)) ||
|
||||||
|
(typeInfo.IsGenericType && typeInfo.GetGenericTypeDefinition() == typeof(IEnumerable<>)));
|
||||||
|
|
||||||
|
var paramName = isEnumerable ? AddParameter(value, EnumerableMultiParameter) : AddParameter(value);
|
||||||
|
_sb.Append(paramName);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_gotConcreteValue = true;
|
||||||
|
_sb.Append("NULL");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return expression;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override Expression VisitConstant(ConstantExpression expression)
|
||||||
|
{
|
||||||
|
if (expression.Value != null)
|
||||||
|
{
|
||||||
|
var paramName = AddParameter(expression.Value);
|
||||||
|
_sb.Append(paramName);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_gotConcreteValue = true;
|
||||||
|
_sb.Append("NULL");
|
||||||
|
}
|
||||||
|
|
||||||
|
return expression;
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool TryGetConstantValue(Expression expression, out object result)
|
||||||
|
{
|
||||||
|
result = null;
|
||||||
|
|
||||||
|
if (expression is ConstantExpression constExp)
|
||||||
|
{
|
||||||
|
result = constExp.Value;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool TryGetPropertyValue(MemberExpression expression, out object result)
|
||||||
|
{
|
||||||
|
result = null;
|
||||||
|
|
||||||
|
if (expression.Expression is MemberExpression nested)
|
||||||
|
{
|
||||||
|
// Value is passed in as a property on a parent entity
|
||||||
|
var container = (nested.Expression as ConstantExpression)?.Value;
|
||||||
|
|
||||||
|
if (container == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
var entity = GetFieldValue(container, nested.Member);
|
||||||
|
result = GetFieldValue(entity, expression.Member);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool TryGetVariableValue(MemberExpression expression, out object result)
|
||||||
|
{
|
||||||
|
result = null;
|
||||||
|
|
||||||
|
// Value is passed in as a variable
|
||||||
|
if (expression.Expression is ConstantExpression nested)
|
||||||
|
{
|
||||||
|
result = GetFieldValue(nested.Value, expression.Member);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool TryGetRightValue(Expression expression, out object value)
|
||||||
|
{
|
||||||
|
value = null;
|
||||||
|
|
||||||
|
if (TryGetConstantValue(expression, out value))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
var memberExp = expression as MemberExpression;
|
||||||
|
|
||||||
|
if (TryGetPropertyValue(memberExp, out value))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (TryGetVariableValue(memberExp, out value))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private object GetFieldValue(object entity, MemberInfo member)
|
||||||
|
{
|
||||||
|
if (member.MemberType == MemberTypes.Field)
|
||||||
|
{
|
||||||
|
return (member as FieldInfo).GetValue(entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (member.MemberType == MemberTypes.Property)
|
||||||
|
{
|
||||||
|
return (member as PropertyInfo).GetValue(entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new ArgumentException(string.Format("WhereBuilder could not get the value for {0}.{1}.", entity.GetType().Name, member.Name));
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool IsNullVariable(Expression expression)
|
||||||
|
{
|
||||||
|
if (expression.NodeType == ExpressionType.Constant &&
|
||||||
|
TryGetConstantValue(expression, out var constResult) &&
|
||||||
|
constResult == null)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (expression.NodeType == ExpressionType.MemberAccess &&
|
||||||
|
expression is MemberExpression member &&
|
||||||
|
((TryGetPropertyValue(member, out var result) && result == null) ||
|
||||||
|
(TryGetVariableValue(member, out result) && result == null)))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private string Decode(BinaryExpression expression)
|
||||||
|
{
|
||||||
|
if (IsNullVariable(expression.Right))
|
||||||
|
{
|
||||||
|
switch (expression.NodeType)
|
||||||
|
{
|
||||||
|
case ExpressionType.Equal: return "IS";
|
||||||
|
case ExpressionType.NotEqual: return "IS NOT";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (expression.NodeType)
|
||||||
|
{
|
||||||
|
case ExpressionType.AndAlso: return "AND";
|
||||||
|
case ExpressionType.And: return "AND";
|
||||||
|
case ExpressionType.Equal: return "=";
|
||||||
|
case ExpressionType.GreaterThan: return ">";
|
||||||
|
case ExpressionType.GreaterThanOrEqual: return ">=";
|
||||||
|
case ExpressionType.LessThan: return "<";
|
||||||
|
case ExpressionType.LessThanOrEqual: return "<=";
|
||||||
|
case ExpressionType.NotEqual: return "<>";
|
||||||
|
case ExpressionType.OrElse: return "OR";
|
||||||
|
case ExpressionType.Or: return "OR";
|
||||||
|
default: throw new NotSupportedException(string.Format("{0} statement is not supported", expression.NodeType.ToString()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ParseContainsExpression(MethodCallExpression expression)
|
||||||
|
{
|
||||||
|
var list = expression.Object;
|
||||||
|
|
||||||
|
if (list != null && (list.Type == typeof(string)))
|
||||||
|
{
|
||||||
|
ParseStringContains(expression);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ParseEnumerableContains(expression);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ParseEnumerableContains(MethodCallExpression body)
|
||||||
|
{
|
||||||
|
// Fish out the list and the item to compare
|
||||||
|
// It's in a different form for arrays and Lists
|
||||||
|
var list = body.Object;
|
||||||
|
Expression item;
|
||||||
|
|
||||||
|
if (list != null)
|
||||||
|
{
|
||||||
|
// Generic collection
|
||||||
|
item = body.Arguments[0];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Static method
|
||||||
|
// Must be Enumerable.Contains(source, item)
|
||||||
|
if (body.Method.DeclaringType != typeof(Enumerable) || body.Arguments.Count != 2)
|
||||||
|
{
|
||||||
|
throw new NotSupportedException("Unexpected form of Enumerable.Contains");
|
||||||
|
}
|
||||||
|
|
||||||
|
list = body.Arguments[0];
|
||||||
|
item = body.Arguments[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
_sb.Append('(');
|
||||||
|
|
||||||
|
Visit(item);
|
||||||
|
|
||||||
|
_sb.Append(" = ANY (");
|
||||||
|
|
||||||
|
// hardcode the integer list if it exists to bypass parameter limit
|
||||||
|
if (item.Type == typeof(int) && TryGetRightValue(list, out var value))
|
||||||
|
{
|
||||||
|
var items = (IEnumerable<int>)value;
|
||||||
|
_sb.Append("('{");
|
||||||
|
_sb.Append(string.Join(", ", items));
|
||||||
|
_sb.Append("}')");
|
||||||
|
|
||||||
|
_gotConcreteValue = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Visit(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
_sb.Append("))");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ParseStringContains(MethodCallExpression body)
|
||||||
|
{
|
||||||
|
_sb.Append('(');
|
||||||
|
|
||||||
|
Visit(body.Object);
|
||||||
|
|
||||||
|
_sb.Append(" ILIKE '%' || ");
|
||||||
|
|
||||||
|
Visit(body.Arguments[0]);
|
||||||
|
|
||||||
|
_sb.Append(" || '%')");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ParseStartsWith(MethodCallExpression body)
|
||||||
|
{
|
||||||
|
_sb.Append('(');
|
||||||
|
|
||||||
|
Visit(body.Object);
|
||||||
|
|
||||||
|
_sb.Append(" ILIKE ");
|
||||||
|
|
||||||
|
Visit(body.Arguments[0]);
|
||||||
|
|
||||||
|
_sb.Append(" || '%')");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ParseEndsWith(MethodCallExpression body)
|
||||||
|
{
|
||||||
|
_sb.Append('(');
|
||||||
|
|
||||||
|
Visit(body.Object);
|
||||||
|
|
||||||
|
_sb.Append(" ILIKE '%' || ");
|
||||||
|
|
||||||
|
Visit(body.Arguments[0]);
|
||||||
|
|
||||||
|
_sb.Append(')');
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
var sql = _sb.ToString();
|
||||||
|
|
||||||
|
if (_requireConcreteValue && !_gotConcreteValue)
|
||||||
|
{
|
||||||
|
var e = new InvalidOperationException("WhereBuilder requires a concrete condition");
|
||||||
|
e.Data.Add("sql", sql);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
|
||||||
|
return sql;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
387
src/NzbDrone.Core/Datastore/WhereBuilderSqlite.cs
Normal file
387
src/NzbDrone.Core/Datastore/WhereBuilderSqlite.cs
Normal file
@ -0,0 +1,387 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Text;
|
||||||
|
using Dapper;
|
||||||
|
|
||||||
|
namespace NzbDrone.Core.Datastore
|
||||||
|
{
|
||||||
|
public class WhereBuilderSqlite : WhereBuilder
|
||||||
|
{
|
||||||
|
protected StringBuilder _sb;
|
||||||
|
|
||||||
|
private const DbType EnumerableMultiParameter = (DbType)(-1);
|
||||||
|
private readonly string _paramNamePrefix;
|
||||||
|
private readonly bool _requireConcreteValue = false;
|
||||||
|
private int _paramCount = 0;
|
||||||
|
private bool _gotConcreteValue = false;
|
||||||
|
|
||||||
|
public WhereBuilderSqlite(Expression filter, bool requireConcreteValue, int seq)
|
||||||
|
{
|
||||||
|
_paramNamePrefix = string.Format("Clause{0}", seq + 1);
|
||||||
|
_requireConcreteValue = requireConcreteValue;
|
||||||
|
_sb = new StringBuilder();
|
||||||
|
|
||||||
|
Parameters = new DynamicParameters();
|
||||||
|
|
||||||
|
if (filter != null)
|
||||||
|
{
|
||||||
|
Visit(filter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private string AddParameter(object value, DbType? dbType = null)
|
||||||
|
{
|
||||||
|
_gotConcreteValue = true;
|
||||||
|
_paramCount++;
|
||||||
|
var name = _paramNamePrefix + "_P" + _paramCount;
|
||||||
|
Parameters.Add(name, value, dbType);
|
||||||
|
return '@' + name;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override Expression VisitBinary(BinaryExpression expression)
|
||||||
|
{
|
||||||
|
_sb.Append('(');
|
||||||
|
|
||||||
|
Visit(expression.Left);
|
||||||
|
|
||||||
|
_sb.AppendFormat(" {0} ", Decode(expression));
|
||||||
|
|
||||||
|
Visit(expression.Right);
|
||||||
|
|
||||||
|
_sb.Append(')');
|
||||||
|
|
||||||
|
return expression;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override Expression VisitMethodCall(MethodCallExpression expression)
|
||||||
|
{
|
||||||
|
var method = expression.Method.Name;
|
||||||
|
|
||||||
|
switch (expression.Method.Name)
|
||||||
|
{
|
||||||
|
case "Contains":
|
||||||
|
ParseContainsExpression(expression);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "StartsWith":
|
||||||
|
ParseStartsWith(expression);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "EndsWith":
|
||||||
|
ParseEndsWith(expression);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
var msg = string.Format("'{0}' expressions are not yet implemented in the where clause expression tree parser.", method);
|
||||||
|
throw new NotImplementedException(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
return expression;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override Expression VisitMemberAccess(MemberExpression expression)
|
||||||
|
{
|
||||||
|
var tableName = expression?.Expression?.Type != null ? TableMapping.Mapper.TableNameMapping(expression.Expression.Type) : null;
|
||||||
|
var gotValue = TryGetRightValue(expression, out var value);
|
||||||
|
|
||||||
|
// Only use the SQL condition if the expression didn't resolve to an actual value
|
||||||
|
if (tableName != null && !gotValue)
|
||||||
|
{
|
||||||
|
_sb.Append($"\"{tableName}\".\"{expression.Member.Name}\"");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (value != null)
|
||||||
|
{
|
||||||
|
// string is IEnumerable<Char> but we don't want to pick up that case
|
||||||
|
var type = value.GetType();
|
||||||
|
var typeInfo = type.GetTypeInfo();
|
||||||
|
var isEnumerable =
|
||||||
|
type != typeof(string) && (
|
||||||
|
typeInfo.ImplementedInterfaces.Any(ti => ti.IsGenericType && ti.GetGenericTypeDefinition() == typeof(IEnumerable<>)) ||
|
||||||
|
(typeInfo.IsGenericType && typeInfo.GetGenericTypeDefinition() == typeof(IEnumerable<>)));
|
||||||
|
|
||||||
|
var paramName = isEnumerable ? AddParameter(value, EnumerableMultiParameter) : AddParameter(value);
|
||||||
|
_sb.Append(paramName);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_gotConcreteValue = true;
|
||||||
|
_sb.Append("NULL");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return expression;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override Expression VisitConstant(ConstantExpression expression)
|
||||||
|
{
|
||||||
|
if (expression.Value != null)
|
||||||
|
{
|
||||||
|
var paramName = AddParameter(expression.Value);
|
||||||
|
_sb.Append(paramName);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_gotConcreteValue = true;
|
||||||
|
_sb.Append("NULL");
|
||||||
|
}
|
||||||
|
|
||||||
|
return expression;
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool TryGetConstantValue(Expression expression, out object result)
|
||||||
|
{
|
||||||
|
result = null;
|
||||||
|
|
||||||
|
if (expression is ConstantExpression constExp)
|
||||||
|
{
|
||||||
|
result = constExp.Value;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool TryGetPropertyValue(MemberExpression expression, out object result)
|
||||||
|
{
|
||||||
|
result = null;
|
||||||
|
|
||||||
|
if (expression.Expression is MemberExpression nested)
|
||||||
|
{
|
||||||
|
// Value is passed in as a property on a parent entity
|
||||||
|
var container = (nested.Expression as ConstantExpression)?.Value;
|
||||||
|
|
||||||
|
if (container == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
var entity = GetFieldValue(container, nested.Member);
|
||||||
|
result = GetFieldValue(entity, expression.Member);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool TryGetVariableValue(MemberExpression expression, out object result)
|
||||||
|
{
|
||||||
|
result = null;
|
||||||
|
|
||||||
|
// Value is passed in as a variable
|
||||||
|
if (expression.Expression is ConstantExpression nested)
|
||||||
|
{
|
||||||
|
result = GetFieldValue(nested.Value, expression.Member);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool TryGetRightValue(Expression expression, out object value)
|
||||||
|
{
|
||||||
|
value = null;
|
||||||
|
|
||||||
|
if (TryGetConstantValue(expression, out value))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
var memberExp = expression as MemberExpression;
|
||||||
|
|
||||||
|
if (TryGetPropertyValue(memberExp, out value))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (TryGetVariableValue(memberExp, out value))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private object GetFieldValue(object entity, MemberInfo member)
|
||||||
|
{
|
||||||
|
if (member.MemberType == MemberTypes.Field)
|
||||||
|
{
|
||||||
|
return (member as FieldInfo).GetValue(entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (member.MemberType == MemberTypes.Property)
|
||||||
|
{
|
||||||
|
return (member as PropertyInfo).GetValue(entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new ArgumentException(string.Format("WhereBuilder could not get the value for {0}.{1}.", entity.GetType().Name, member.Name));
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool IsNullVariable(Expression expression)
|
||||||
|
{
|
||||||
|
if (expression.NodeType == ExpressionType.Constant &&
|
||||||
|
TryGetConstantValue(expression, out var constResult) &&
|
||||||
|
constResult == null)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (expression.NodeType == ExpressionType.MemberAccess &&
|
||||||
|
expression is MemberExpression member &&
|
||||||
|
((TryGetPropertyValue(member, out var result) && result == null) ||
|
||||||
|
(TryGetVariableValue(member, out result) && result == null)))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private string Decode(BinaryExpression expression)
|
||||||
|
{
|
||||||
|
if (IsNullVariable(expression.Right))
|
||||||
|
{
|
||||||
|
switch (expression.NodeType)
|
||||||
|
{
|
||||||
|
case ExpressionType.Equal: return "IS";
|
||||||
|
case ExpressionType.NotEqual: return "IS NOT";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (expression.NodeType)
|
||||||
|
{
|
||||||
|
case ExpressionType.AndAlso: return "AND";
|
||||||
|
case ExpressionType.And: return "AND";
|
||||||
|
case ExpressionType.Equal: return "=";
|
||||||
|
case ExpressionType.GreaterThan: return ">";
|
||||||
|
case ExpressionType.GreaterThanOrEqual: return ">=";
|
||||||
|
case ExpressionType.LessThan: return "<";
|
||||||
|
case ExpressionType.LessThanOrEqual: return "<=";
|
||||||
|
case ExpressionType.NotEqual: return "<>";
|
||||||
|
case ExpressionType.OrElse: return "OR";
|
||||||
|
case ExpressionType.Or: return "OR";
|
||||||
|
default: throw new NotSupportedException(string.Format("{0} statement is not supported", expression.NodeType.ToString()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ParseContainsExpression(MethodCallExpression expression)
|
||||||
|
{
|
||||||
|
var list = expression.Object;
|
||||||
|
|
||||||
|
if (list != null && (list.Type == typeof(string)))
|
||||||
|
{
|
||||||
|
ParseStringContains(expression);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ParseEnumerableContains(expression);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ParseEnumerableContains(MethodCallExpression body)
|
||||||
|
{
|
||||||
|
// Fish out the list and the item to compare
|
||||||
|
// It's in a different form for arrays and Lists
|
||||||
|
var list = body.Object;
|
||||||
|
Expression item;
|
||||||
|
|
||||||
|
if (list != null)
|
||||||
|
{
|
||||||
|
// Generic collection
|
||||||
|
item = body.Arguments[0];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Static method
|
||||||
|
// Must be Enumerable.Contains(source, item)
|
||||||
|
if (body.Method.DeclaringType != typeof(Enumerable) || body.Arguments.Count != 2)
|
||||||
|
{
|
||||||
|
throw new NotSupportedException("Unexpected form of Enumerable.Contains");
|
||||||
|
}
|
||||||
|
|
||||||
|
list = body.Arguments[0];
|
||||||
|
item = body.Arguments[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
_sb.Append('(');
|
||||||
|
|
||||||
|
Visit(item);
|
||||||
|
|
||||||
|
_sb.Append(" IN ");
|
||||||
|
|
||||||
|
// hardcode the integer list if it exists to bypass parameter limit
|
||||||
|
if (item.Type == typeof(int) && TryGetRightValue(list, out var value))
|
||||||
|
{
|
||||||
|
var items = (IEnumerable<int>)value;
|
||||||
|
_sb.Append('(');
|
||||||
|
_sb.Append(string.Join(", ", items));
|
||||||
|
_sb.Append(')');
|
||||||
|
|
||||||
|
_gotConcreteValue = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Visit(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
_sb.Append(')');
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ParseStringContains(MethodCallExpression body)
|
||||||
|
{
|
||||||
|
_sb.Append('(');
|
||||||
|
|
||||||
|
Visit(body.Object);
|
||||||
|
|
||||||
|
_sb.Append(" LIKE '%' || ");
|
||||||
|
|
||||||
|
Visit(body.Arguments[0]);
|
||||||
|
|
||||||
|
_sb.Append(" || '%')");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ParseStartsWith(MethodCallExpression body)
|
||||||
|
{
|
||||||
|
_sb.Append('(');
|
||||||
|
|
||||||
|
Visit(body.Object);
|
||||||
|
|
||||||
|
_sb.Append(" LIKE ");
|
||||||
|
|
||||||
|
Visit(body.Arguments[0]);
|
||||||
|
|
||||||
|
_sb.Append(" || '%')");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ParseEndsWith(MethodCallExpression body)
|
||||||
|
{
|
||||||
|
_sb.Append('(');
|
||||||
|
|
||||||
|
Visit(body.Object);
|
||||||
|
|
||||||
|
_sb.Append(" LIKE '%' || ");
|
||||||
|
|
||||||
|
Visit(body.Arguments[0]);
|
||||||
|
|
||||||
|
_sb.Append(')');
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
var sql = _sb.ToString();
|
||||||
|
|
||||||
|
if (_requireConcreteValue && !_gotConcreteValue)
|
||||||
|
{
|
||||||
|
var e = new InvalidOperationException("WhereBuilder requires a concrete condition");
|
||||||
|
e.Data.Add("sql", sql);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
|
||||||
|
return sql;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -49,16 +49,16 @@ public List<MovieHistory> FindByDownloadId(string downloadId)
|
|||||||
|
|
||||||
public List<MovieHistory> FindDownloadHistory(int movieId, QualityModel quality)
|
public List<MovieHistory> FindDownloadHistory(int movieId, QualityModel quality)
|
||||||
{
|
{
|
||||||
var allowed = new[] { MovieHistoryEventType.Grabbed, MovieHistoryEventType.DownloadFailed, MovieHistoryEventType.DownloadFolderImported };
|
var allowed = new[] { (int)MovieHistoryEventType.Grabbed, (int)MovieHistoryEventType.DownloadFailed, (int)MovieHistoryEventType.DownloadFolderImported };
|
||||||
|
|
||||||
return Query(h => h.MovieId == movieId &&
|
return Query(h => h.MovieId == movieId &&
|
||||||
h.Quality == quality &&
|
h.Quality == quality &&
|
||||||
allowed.Contains(h.EventType));
|
allowed.Contains((int)h.EventType));
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<MovieHistory> GetByMovieId(int movieId, MovieHistoryEventType? eventType)
|
public List<MovieHistory> GetByMovieId(int movieId, MovieHistoryEventType? eventType)
|
||||||
{
|
{
|
||||||
var builder = new SqlBuilder()
|
var builder = new SqlBuilder(_database.DatabaseType)
|
||||||
.Join<MovieHistory, Movie>((h, m) => h.MovieId == m.Id)
|
.Join<MovieHistory, Movie>((h, m) => h.MovieId == m.Id)
|
||||||
.Join<Movie, Profile>((m, p) => m.ProfileId == p.Id)
|
.Join<Movie, Profile>((m, p) => m.ProfileId == p.Id)
|
||||||
.Where<MovieHistory>(h => h.MovieId == movieId);
|
.Where<MovieHistory>(h => h.MovieId == movieId);
|
||||||
@ -76,7 +76,7 @@ public void DeleteForMovies(List<int> movieIds)
|
|||||||
Delete(c => movieIds.Contains(c.MovieId));
|
Delete(c => movieIds.Contains(c.MovieId));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override SqlBuilder PagedBuilder() => new SqlBuilder()
|
protected override SqlBuilder PagedBuilder() => new SqlBuilder(_database.DatabaseType)
|
||||||
.Join<MovieHistory, Movie>((h, m) => h.MovieId == m.Id)
|
.Join<MovieHistory, Movie>((h, m) => h.MovieId == m.Id)
|
||||||
.Join<Movie, Profile>((m, p) => m.ProfileId == p.Id);
|
.Join<Movie, Profile>((m, p) => m.ProfileId == p.Id);
|
||||||
|
|
||||||
@ -97,7 +97,7 @@ public MovieHistory MostRecentForMovie(int movieId)
|
|||||||
|
|
||||||
public List<MovieHistory> Since(DateTime date, MovieHistoryEventType? eventType)
|
public List<MovieHistory> Since(DateTime date, MovieHistoryEventType? eventType)
|
||||||
{
|
{
|
||||||
var builder = new SqlBuilder()
|
var builder = new SqlBuilder(_database.DatabaseType)
|
||||||
.Join<MovieHistory, Movie>((h, m) => h.MovieId == m.Id)
|
.Join<MovieHistory, Movie>((h, m) => h.MovieId == m.Id)
|
||||||
.Join<Movie, Profile>((m, p) => m.ProfileId == p.Id)
|
.Join<Movie, Profile>((m, p) => m.ProfileId == p.Id)
|
||||||
.Where<MovieHistory>(x => x.Date >= date);
|
.Where<MovieHistory>(x => x.Date >= date);
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
using Dapper;
|
using Dapper;
|
||||||
using NzbDrone.Core.Datastore;
|
using NzbDrone.Core.Datastore;
|
||||||
|
|
||||||
namespace NzbDrone.Core.Housekeeping.Housekeepers
|
namespace NzbDrone.Core.Housekeeping.Housekeepers
|
||||||
@ -16,16 +16,32 @@ public void Clean()
|
|||||||
{
|
{
|
||||||
using (var mapper = _database.OpenConnection())
|
using (var mapper = _database.OpenConnection())
|
||||||
{
|
{
|
||||||
mapper.Execute(@"DELETE FROM MetadataFiles
|
if (_database.DatabaseType == DatabaseType.PostgreSQL)
|
||||||
WHERE Id IN (
|
{
|
||||||
SELECT Id FROM MetadataFiles
|
mapper.Execute(@"DELETE FROM ""MetadataFiles""
|
||||||
WHERE RelativePath
|
WHERE ""Id"" = ANY (
|
||||||
LIKE '_:\%'
|
SELECT ""Id"" FROM ""MetadataFiles""
|
||||||
OR RelativePath
|
WHERE ""RelativePath""
|
||||||
LIKE '\%'
|
LIKE '_:\\%'
|
||||||
OR RelativePath
|
OR ""RelativePath""
|
||||||
|
LIKE '\\%'
|
||||||
|
OR ""RelativePath""
|
||||||
LIKE '/%'
|
LIKE '/%'
|
||||||
)");
|
)");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mapper.Execute(@"DELETE FROM ""MetadataFiles""
|
||||||
|
WHERE ""Id"" IN (
|
||||||
|
SELECT ""Id"" FROM ""MetadataFiles""
|
||||||
|
WHERE ""RelativePath""
|
||||||
|
LIKE '_:\%'
|
||||||
|
OR ""RelativePath""
|
||||||
|
LIKE '\%'
|
||||||
|
OR ""RelativePath""
|
||||||
|
LIKE '/%'
|
||||||
|
)");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,9 +16,9 @@ public void Clean()
|
|||||||
{
|
{
|
||||||
using (var mapper = _database.OpenConnection())
|
using (var mapper = _database.OpenConnection())
|
||||||
{
|
{
|
||||||
mapper.Execute(@"DELETE FROM NamingConfig
|
mapper.Execute(@"DELETE FROM ""NamingConfig""
|
||||||
WHERE ID NOT IN (
|
WHERE ""Id"" NOT IN (
|
||||||
SELECT ID FROM NamingConfig
|
SELECT ""Id"" FROM ""NamingConfig""
|
||||||
LIMIT 1)");
|
LIMIT 1)");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,9 +16,9 @@ public void Clean()
|
|||||||
{
|
{
|
||||||
using (var mapper = _database.OpenConnection())
|
using (var mapper = _database.OpenConnection())
|
||||||
{
|
{
|
||||||
mapper.Execute(@"DELETE FROM Users
|
mapper.Execute(@"DELETE FROM ""Users""
|
||||||
WHERE ID NOT IN (
|
WHERE ""Id"" NOT IN (
|
||||||
SELECT ID FROM Users
|
SELECT ""Id"" FROM ""Users""
|
||||||
LIMIT 1)");
|
LIMIT 1)");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,14 +18,28 @@ public void Clean()
|
|||||||
{
|
{
|
||||||
var mapper = _database.OpenConnection();
|
var mapper = _database.OpenConnection();
|
||||||
|
|
||||||
mapper.Execute(@"DELETE FROM PendingReleases
|
if (_database.DatabaseType == DatabaseType.PostgreSQL)
|
||||||
WHERE Added < @TwoWeeksAgo
|
{
|
||||||
AND REASON IN @Reasons",
|
mapper.Execute(@"DELETE FROM ""PendingReleases""
|
||||||
|
WHERE ""Added"" < @TwoWeeksAgo
|
||||||
|
AND ""Reason"" = ANY (@Reasons)",
|
||||||
new
|
new
|
||||||
{
|
{
|
||||||
TwoWeeksAgo = DateTime.UtcNow.AddDays(-14),
|
TwoWeeksAgo = DateTime.UtcNow.AddDays(-14),
|
||||||
Reasons = new[] { (int)PendingReleaseReason.DownloadClientUnavailable, (int)PendingReleaseReason.Fallback }
|
Reasons = new[] { (int)PendingReleaseReason.DownloadClientUnavailable, (int)PendingReleaseReason.Fallback }
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mapper.Execute(@"DELETE FROM ""PendingReleases""
|
||||||
|
WHERE ""Added"" < @TwoWeeksAgo
|
||||||
|
AND ""REASON"" IN @Reasons",
|
||||||
|
new
|
||||||
|
{
|
||||||
|
TwoWeeksAgo = DateTime.UtcNow.AddDays(-14),
|
||||||
|
Reasons = new[] { (int)PendingReleaseReason.DownloadClientUnavailable, (int)PendingReleaseReason.Fallback }
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user