mirror of
https://github.com/Sonarr/Sonarr.git
synced 2024-12-14 11:23:42 +02:00
Renamed IndexerStatus.IndexerId to ProviderId.
This commit is contained in:
parent
7b0e40d5d0
commit
14144bd4d9
@ -44,7 +44,7 @@ public void should_ignore_pending_items_from_unavailable_indexer()
|
||||
{
|
||||
Mocker.GetMock<IIndexerStatusService>()
|
||||
.Setup(v => v.GetBlockedIndexers())
|
||||
.Returns(new List<IndexerStatus> { new IndexerStatus { IndexerId = 1, DisabledTill = DateTime.UtcNow.AddHours(2) } });
|
||||
.Returns(new List<IndexerStatus> { new IndexerStatus { ProviderId = 1, DisabledTill = DateTime.UtcNow.AddHours(2) } });
|
||||
|
||||
GivenPendingRelease();
|
||||
|
||||
|
@ -40,7 +40,7 @@ private Mock<IIndexer> GivenIndexer(int i, double backoffHours, double failureHo
|
||||
{
|
||||
_blockedIndexers.Add(new IndexerStatus
|
||||
{
|
||||
IndexerId = id,
|
||||
ProviderId = id,
|
||||
InitialFailure = DateTime.UtcNow.AddHours(-failureHours),
|
||||
MostRecentFailure = DateTime.UtcNow.AddHours(-0.1),
|
||||
EscalationLevel = 5,
|
||||
|
@ -28,7 +28,7 @@ private void GivenIndexer()
|
||||
public void should_delete_orphaned_indexerstatus()
|
||||
{
|
||||
var status = Builder<IndexerStatus>.CreateNew()
|
||||
.With(h => h.IndexerId = _indexer.Id)
|
||||
.With(h => h.ProviderId = _indexer.Id)
|
||||
.BuildNew();
|
||||
Db.Insert(status);
|
||||
|
||||
@ -42,13 +42,13 @@ public void should_not_delete_unorphaned_indexerstatus()
|
||||
GivenIndexer();
|
||||
|
||||
var status = Builder<IndexerStatus>.CreateNew()
|
||||
.With(h => h.IndexerId = _indexer.Id)
|
||||
.With(h => h.ProviderId = _indexer.Id)
|
||||
.BuildNew();
|
||||
Db.Insert(status);
|
||||
|
||||
Subject.Clean();
|
||||
AllStoredModels.Should().HaveCount(1);
|
||||
AllStoredModels.Should().Contain(h => h.IndexerId == _indexer.Id);
|
||||
AllStoredModels.Should().Contain(h => h.ProviderId == _indexer.Id);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
using FluentMigrator;
|
||||
using NzbDrone.Core.Datastore.Migration.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Datastore.Migration
|
||||
{
|
||||
[Migration(114)]
|
||||
public class rename_indexer_status_id : NzbDroneMigrationBase
|
||||
{
|
||||
protected override void MainDbUpgrade()
|
||||
{
|
||||
Rename.Column("IndexerId").OnTable("IndexerStatus").To("ProviderId");
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using FluentMigrator;
|
||||
@ -7,6 +8,7 @@
|
||||
using FluentMigrator.Runner;
|
||||
using FluentMigrator.Runner.Generators.SQLite;
|
||||
using FluentMigrator.Runner.Processors.SQLite;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace NzbDrone.Core.Datastore.Migration.Framework
|
||||
{
|
||||
@ -62,6 +64,46 @@ public override void Process(DeleteColumnExpression expression)
|
||||
ProcessAlterTable(tableDefinition);
|
||||
}
|
||||
|
||||
public override void Process(RenameColumnExpression expression)
|
||||
{
|
||||
var tableDefinition = GetTableSchema(expression.TableName);
|
||||
|
||||
var oldColumnDefinitions = tableDefinition.Columns.ToList();
|
||||
var columnDefinitions = tableDefinition.Columns.ToList();
|
||||
var columnIndex = columnDefinitions.FindIndex(c => c.Name == expression.OldName);
|
||||
|
||||
if (columnIndex == -1)
|
||||
{
|
||||
throw new ApplicationException(string.Format("Column {0} does not exist on table {1}.", expression.OldName, expression.TableName));
|
||||
}
|
||||
|
||||
if (columnDefinitions.Any(c => c.Name == expression.NewName))
|
||||
{
|
||||
throw new ApplicationException(string.Format("Column {0} already exists on table {1}.", expression.NewName, expression.TableName));
|
||||
}
|
||||
|
||||
oldColumnDefinitions[columnIndex] = (ColumnDefinition)columnDefinitions[columnIndex].Clone();
|
||||
columnDefinitions[columnIndex].Name = expression.NewName;
|
||||
|
||||
foreach (var index in tableDefinition.Indexes)
|
||||
{
|
||||
if (index.Name.StartsWith("IX_"))
|
||||
{
|
||||
index.Name = Regex.Replace(index.Name, "(?<=_)" + Regex.Escape(expression.OldName) + "(?=_|$)", Regex.Escape(expression.NewName));
|
||||
}
|
||||
|
||||
foreach (var column in index.Columns)
|
||||
{
|
||||
if (column.Name == expression.OldName)
|
||||
{
|
||||
column.Name = expression.NewName;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ProcessAlterTable(tableDefinition, oldColumnDefinitions);
|
||||
}
|
||||
|
||||
protected virtual TableDefinition GetTableSchema(string tableName)
|
||||
{
|
||||
var schemaDumper = new SqliteSchemaDumper(this, Announcer);
|
||||
@ -70,7 +112,7 @@ protected virtual TableDefinition GetTableSchema(string tableName)
|
||||
return schema.Single(v => v.Name == tableName);
|
||||
}
|
||||
|
||||
protected virtual void ProcessAlterTable(TableDefinition tableDefinition)
|
||||
protected virtual void ProcessAlterTable(TableDefinition tableDefinition, List<ColumnDefinition> oldColumnDefinitions = null)
|
||||
{
|
||||
var tableName = tableDefinition.Name;
|
||||
var tempTableName = tableName + "_temp";
|
||||
@ -83,11 +125,12 @@ protected virtual void ProcessAlterTable(TableDefinition tableDefinition)
|
||||
|
||||
// What is the cleanest way to do this? Add function to Generator?
|
||||
var quoter = new SQLiteQuoter();
|
||||
var columnsToTransfer = string.Join(", ", tableDefinition.Columns.Select(c => quoter.QuoteColumnName(c.Name)));
|
||||
var columnsToInsert = string.Join(", ", tableDefinition.Columns.Select(c => quoter.QuoteColumnName(c.Name)));
|
||||
var columnsToFetch = string.Join(", ", (oldColumnDefinitions ?? tableDefinition.Columns).Select(c => quoter.QuoteColumnName(c.Name)));
|
||||
|
||||
Process(new CreateTableExpression() { TableName = tempTableName, Columns = tableDefinition.Columns.ToList() });
|
||||
|
||||
Process(string.Format("INSERT INTO {0} SELECT {1} FROM {2}", quoter.QuoteTableName(tempTableName), columnsToTransfer, quoter.QuoteTableName(tableName)));
|
||||
Process(string.Format("INSERT INTO {0} ({1}) SELECT {2} FROM {3}", quoter.QuoteTableName(tempTableName), columnsToInsert, columnsToFetch, quoter.QuoteTableName(tableName)));
|
||||
|
||||
Process(new DeleteTableExpression() { TableName = tableName });
|
||||
|
||||
|
@ -101,7 +101,7 @@ public List<ReleaseInfo> GetPending()
|
||||
|
||||
private List<ReleaseInfo> FilterBlockedIndexers(List<ReleaseInfo> releases)
|
||||
{
|
||||
var blockedIndexers = new HashSet<int>(_indexerStatusService.GetBlockedIndexers().Select(v => v.IndexerId));
|
||||
var blockedIndexers = new HashSet<int>(_indexerStatusService.GetBlockedIndexers().Select(v => v.ProviderId));
|
||||
|
||||
return releases.Where(release => !blockedIndexers.Contains(release.IndexerId)).ToList();
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ public override HealthCheck Check()
|
||||
var enabledIndexers = _indexerFactory.GetAvailableProviders();
|
||||
var backOffIndexers = enabledIndexers.Join(_indexerStatusService.GetBlockedIndexers(),
|
||||
i => i.Definition.Id,
|
||||
s => s.IndexerId,
|
||||
s => s.ProviderId,
|
||||
(i, s) => new { Indexer = i, Status = s })
|
||||
.Where(v => (v.Status.MostRecentFailure - v.Status.InitialFailure) > TimeSpan.FromHours(1))
|
||||
.ToList();
|
||||
|
@ -19,7 +19,7 @@ public void Clean()
|
||||
WHERE Id IN (
|
||||
SELECT IndexerStatus.Id FROM IndexerStatus
|
||||
LEFT OUTER JOIN Indexers
|
||||
ON IndexerStatus.IndexerId = Indexers.Id
|
||||
ON IndexerStatus.ProviderId = Indexers.Id
|
||||
WHERE Indexers.Id IS NULL)");
|
||||
}
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ public List<IIndexer> SearchEnabled(bool filterBlockedIndexers = true)
|
||||
|
||||
private IEnumerable<IIndexer> FilterBlockedIndexers(IEnumerable<IIndexer> indexers)
|
||||
{
|
||||
var blockedIndexers = _indexerStatusService.GetBlockedIndexers().ToDictionary(v => v.IndexerId, v => v);
|
||||
var blockedIndexers = _indexerStatusService.GetBlockedIndexers().ToDictionary(v => v.ProviderId, v => v);
|
||||
|
||||
foreach (var indexer in indexers)
|
||||
{
|
||||
|
@ -6,7 +6,7 @@ namespace NzbDrone.Core.Indexers
|
||||
{
|
||||
public class IndexerStatus : ModelBase
|
||||
{
|
||||
public int IndexerId { get; set; }
|
||||
public int ProviderId { get; set; }
|
||||
|
||||
public DateTime? InitialFailure { get; set; }
|
||||
public DateTime? MostRecentFailure { get; set; }
|
||||
|
@ -20,7 +20,7 @@ public IndexerStatusRepository(IMainDatabase database, IEventAggregator eventAgg
|
||||
|
||||
public IndexerStatus FindByIndexerId(int indexerId)
|
||||
{
|
||||
return Query.Where(c => c.IndexerId == indexerId).SingleOrDefault();
|
||||
return Query.Where(c => c.ProviderId == indexerId).SingleOrDefault();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ public ReleaseInfo GetLastRssSyncReleaseInfo(int indexerId)
|
||||
|
||||
private IndexerStatus GetIndexerStatus(int indexerId)
|
||||
{
|
||||
return _indexerStatusRepository.FindByIndexerId(indexerId) ?? new IndexerStatus { IndexerId = indexerId };
|
||||
return _indexerStatusRepository.FindByIndexerId(indexerId) ?? new IndexerStatus { ProviderId = indexerId };
|
||||
}
|
||||
|
||||
private TimeSpan CalculateBackOffPeriod(IndexerStatus status)
|
||||
|
@ -251,6 +251,7 @@
|
||||
<Compile Include="Datastore\Migration\070_delay_profile.cs" />
|
||||
<Compile Include="Datastore\Migration\102_add_language_to_episodeFiles_history_and_blacklist.cs" />
|
||||
<Compile Include="Datastore\Migration\113_consolidate_indexer_baseurl.cs" />
|
||||
<Compile Include="Datastore\Migration\114_rename_indexer_status_id.cs" />
|
||||
<Compile Include="Datastore\Migration\112_added_regex_to_scenemapping.cs" />
|
||||
<Compile Include="Datastore\Migration\110_fix_extra_files_config.cs" />
|
||||
<Compile Include="Datastore\Migration\109_import_extra_files.cs" />
|
||||
|
Loading…
Reference in New Issue
Block a user