diff --git a/NzbDrone.Console/ConsoleApp.cs b/NzbDrone.Console/ConsoleApp.cs index 8b633510d..68de86f25 100644 --- a/NzbDrone.Console/ConsoleApp.cs +++ b/NzbDrone.Console/ConsoleApp.cs @@ -24,6 +24,7 @@ namespace NzbDrone.Console } catch (Exception e) { + Logger.FatalException("EPIC FAIL!", e); System.Console.ReadLine(); } diff --git a/NzbDrone.Core/Datastore/DbFactory.cs b/NzbDrone.Core/Datastore/DbFactory.cs index fb8d43a37..48fe63bbf 100644 --- a/NzbDrone.Core/Datastore/DbFactory.cs +++ b/NzbDrone.Core/Datastore/DbFactory.cs @@ -29,8 +29,12 @@ namespace NzbDrone.Core.Datastore public static void RegisterDatabase(IContainer container) { + container.Resolve().Create(); + container.Register(c => c.Resolve().Create()); + container.Resolve().Create(MigrationType.Log); + container.Register(c => { var db = c.Resolve().Create(MigrationType.Log); diff --git a/NzbDrone.Core/Datastore/Migration/018_remove_duplicates.cs b/NzbDrone.Core/Datastore/Migration/018_remove_duplicates.cs index 379f79a43..7fb11e5e7 100644 --- a/NzbDrone.Core/Datastore/Migration/018_remove_duplicates.cs +++ b/NzbDrone.Core/Datastore/Migration/018_remove_duplicates.cs @@ -11,8 +11,8 @@ namespace NzbDrone.Core.Datastore.Migration { using (var transaction = MigrationHelper.BeginTransaction()) { - RemoveDuplicateSeries("TvdbId"); - RemoveDuplicateSeries("TitleSlug"); + RemoveDuplicateSeries("TvdbId"); + RemoveDuplicateSeries("TitleSlug"); var duplicatedEpisodes = MigrationHelper.GetDuplicates("Episodes", "TvDbEpisodeId"); @@ -28,9 +28,9 @@ namespace NzbDrone.Core.Datastore.Migration } } - private void RemoveDuplicateSeries(string field) + private void RemoveDuplicateSeries(string field) { - var duplicatedSeries = MigrationHelper.GetDuplicates("Series", field); + var duplicatedSeries = MigrationHelper.GetDuplicates("Series", field); foreach (var duplicate in duplicatedSeries) { diff --git a/NzbDrone.Core/Datastore/Migration/Framework/SQLiteMigrationHelper.cs b/NzbDrone.Core/Datastore/Migration/Framework/SQLiteMigrationHelper.cs index 843b97466..42f8f8e7b 100644 --- a/NzbDrone.Core/Datastore/Migration/Framework/SQLiteMigrationHelper.cs +++ b/NzbDrone.Core/Datastore/Migration/Framework/SQLiteMigrationHelper.cs @@ -4,6 +4,7 @@ using System.Data.SQLite; using System.Linq; using System.Text.RegularExpressions; using NLog; +using NzbDrone.Common.Exceptions; namespace NzbDrone.Core.Datastore.Migration.Framework { @@ -54,7 +55,14 @@ namespace NzbDrone.Core.Datastore.Migration.Framework command.Connection = _connection; - return (string)command.ExecuteScalar(); + var sql = (string)command.ExecuteScalar(); + + if (string.IsNullOrWhiteSpace(sql)) + { + throw new TableNotFoundException(tableName); + } + + return sql; } public Dictionary GetColumns(string tableName) @@ -163,7 +171,7 @@ namespace NzbDrone.Core.Datastore.Migration.Framework { while (reader.Read()) { - result.Add(new KeyValuePair(reader.GetInt16(0), (T)Convert.ChangeType(reader[1], typeof(T)))); + result.Add(new KeyValuePair(reader.GetInt32(0), (T)Convert.ChangeType(reader[1], typeof(T)))); } } @@ -207,10 +215,18 @@ namespace NzbDrone.Core.Datastore.Migration.Framework Connection = _connection }; - return (int)sqLiteCommand.ExecuteScalar(); + return (int)sqLiteCommand.ExecuteScalar(); + } + + private class TableNotFoundException : NzbDroneException + { + public TableNotFoundException(string tableName) + : base("Table [{0}] not found", tableName) + { + + } } - } } \ No newline at end of file