mirror of
https://github.com/Sonarr/Sonarr
synced 2025-02-22 06:01:24 +00:00
better migration error handling.
This commit is contained in:
parent
9390a00f80
commit
47d9b4d5bb
4 changed files with 29 additions and 8 deletions
|
@ -24,6 +24,7 @@ namespace NzbDrone.Console
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
Logger.FatalException("EPIC FAIL!", e);
|
||||||
System.Console.ReadLine();
|
System.Console.ReadLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,8 +29,12 @@ namespace NzbDrone.Core.Datastore
|
||||||
|
|
||||||
public static void RegisterDatabase(IContainer container)
|
public static void RegisterDatabase(IContainer container)
|
||||||
{
|
{
|
||||||
|
container.Resolve<IDbFactory>().Create();
|
||||||
|
|
||||||
container.Register(c => c.Resolve<IDbFactory>().Create());
|
container.Register(c => c.Resolve<IDbFactory>().Create());
|
||||||
|
|
||||||
|
container.Resolve<IDbFactory>().Create(MigrationType.Log);
|
||||||
|
|
||||||
container.Register<ILogRepository>(c =>
|
container.Register<ILogRepository>(c =>
|
||||||
{
|
{
|
||||||
var db = c.Resolve<IDbFactory>().Create(MigrationType.Log);
|
var db = c.Resolve<IDbFactory>().Create(MigrationType.Log);
|
||||||
|
|
|
@ -11,8 +11,8 @@ namespace NzbDrone.Core.Datastore.Migration
|
||||||
{
|
{
|
||||||
using (var transaction = MigrationHelper.BeginTransaction())
|
using (var transaction = MigrationHelper.BeginTransaction())
|
||||||
{
|
{
|
||||||
RemoveDuplicateSeries("TvdbId");
|
RemoveDuplicateSeries<int>("TvdbId");
|
||||||
RemoveDuplicateSeries("TitleSlug");
|
RemoveDuplicateSeries<string>("TitleSlug");
|
||||||
|
|
||||||
var duplicatedEpisodes = MigrationHelper.GetDuplicates<int>("Episodes", "TvDbEpisodeId");
|
var duplicatedEpisodes = MigrationHelper.GetDuplicates<int>("Episodes", "TvDbEpisodeId");
|
||||||
|
|
||||||
|
@ -28,9 +28,9 @@ namespace NzbDrone.Core.Datastore.Migration
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void RemoveDuplicateSeries(string field)
|
private void RemoveDuplicateSeries<T>(string field)
|
||||||
{
|
{
|
||||||
var duplicatedSeries = MigrationHelper.GetDuplicates<int>("Series", field);
|
var duplicatedSeries = MigrationHelper.GetDuplicates<T>("Series", field);
|
||||||
|
|
||||||
foreach (var duplicate in duplicatedSeries)
|
foreach (var duplicate in duplicatedSeries)
|
||||||
{
|
{
|
||||||
|
|
|
@ -4,6 +4,7 @@ using System.Data.SQLite;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using NLog;
|
using NLog;
|
||||||
|
using NzbDrone.Common.Exceptions;
|
||||||
|
|
||||||
namespace NzbDrone.Core.Datastore.Migration.Framework
|
namespace NzbDrone.Core.Datastore.Migration.Framework
|
||||||
{
|
{
|
||||||
|
@ -54,7 +55,14 @@ namespace NzbDrone.Core.Datastore.Migration.Framework
|
||||||
|
|
||||||
command.Connection = _connection;
|
command.Connection = _connection;
|
||||||
|
|
||||||
return (string)command.ExecuteScalar();
|
var sql = (string)command.ExecuteScalar();
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(sql))
|
||||||
|
{
|
||||||
|
throw new TableNotFoundException(tableName);
|
||||||
|
}
|
||||||
|
|
||||||
|
return sql;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Dictionary<String, SQLiteColumn> GetColumns(string tableName)
|
public Dictionary<String, SQLiteColumn> GetColumns(string tableName)
|
||||||
|
@ -163,7 +171,7 @@ namespace NzbDrone.Core.Datastore.Migration.Framework
|
||||||
{
|
{
|
||||||
while (reader.Read())
|
while (reader.Read())
|
||||||
{
|
{
|
||||||
result.Add(new KeyValuePair<int, T>(reader.GetInt16(0), (T)Convert.ChangeType(reader[1], typeof(T))));
|
result.Add(new KeyValuePair<int, T>(reader.GetInt32(0), (T)Convert.ChangeType(reader[1], typeof(T))));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -207,10 +215,18 @@ namespace NzbDrone.Core.Datastore.Migration.Framework
|
||||||
Connection = _connection
|
Connection = _connection
|
||||||
};
|
};
|
||||||
|
|
||||||
return (int)sqLiteCommand.ExecuteScalar();
|
return (int)sqLiteCommand.ExecuteScalar();
|
||||||
|
}
|
||||||
|
|
||||||
|
private class TableNotFoundException : NzbDroneException
|
||||||
|
{
|
||||||
|
public TableNotFoundException(string tableName)
|
||||||
|
: base("Table [{0}] not found", tableName)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue