1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-12 11:15:43 +02:00

Merge branch 'markus101'

Conflicts:
	NzbDrone.Core/Datastore/Migrations/Migration.cs
This commit is contained in:
kay.one 2011-06-17 17:19:43 -07:00
commit f11b4af305
4 changed files with 127 additions and 114 deletions

View File

@ -29,7 +29,7 @@ public void Init_indexer_test()
{ {
var mocker = new AutoMoqer(); var mocker = new AutoMoqer();
mocker.SetConstant(MockLib.GetEmptyRepository()); mocker.SetConstant(MockLib.GetEmptyDatabase());
//Act //Act
var indexerProvider = mocker.Resolve<IndexerProvider>(); var indexerProvider = mocker.Resolve<IndexerProvider>();
@ -51,7 +51,7 @@ public void Init_indexer_with_disabled_job()
{ {
var mocker = new AutoMoqer(); var mocker = new AutoMoqer();
mocker.SetConstant(MockLib.GetEmptyRepository()); mocker.SetConstant(MockLib.GetEmptyDatabase());
//Act //Act
var indexerProvider = mocker.Resolve<IndexerProvider>(); var indexerProvider = mocker.Resolve<IndexerProvider>();

View File

@ -37,122 +37,134 @@ public class Migration20110616 : Migration
{ {
public override void Up() public override void Up()
{ {
Database.AddTable("Series", "SQLite", new[] Database.AddTable("Series", new[]
{ {
new Column("SeriesId", DbType.Int32, ColumnProperty.PrimaryKey), new Column("SeriesId", DbType.Int32, ColumnProperty.PrimaryKey),
new Column("Title", DbType.String, ColumnProperty.NotNull, String.Empty), new Column("Title", DbType.String, ColumnProperty.NotNull, String.Empty),
new Column("CleanTitle", DbType.String, ColumnProperty.NotNull, String.Empty), new Column("CleanTitle", DbType.String, ColumnProperty.NotNull, String.Empty),
new Column("Status", DbType.String, ColumnProperty.Null), new Column("Status", DbType.String, ColumnProperty.Null),
new Column("Overview", DbType.String, ColumnProperty.NotNull, String.Empty), new Column("Overview", DbType.String, ColumnProperty.NotNull, String.Empty),
new Column("AirsDayOfWeek", DbType.Int16, ColumnProperty.Null), new Column("AirsDayOfWeek", DbType.Int16, ColumnProperty.Null),
new Column("AirTimes", DbType.String, ColumnProperty.NotNull, String.Empty), new Column("AirTimes", DbType.String, ColumnProperty.NotNull, String.Empty),
new Column("Language", DbType.String, ColumnProperty.NotNull, String.Empty), new Column("Language", DbType.String, ColumnProperty.NotNull, String.Empty),
new Column("Path", DbType.String, ColumnProperty.NotNull), new Column("Path", DbType.String, ColumnProperty.NotNull),
new Column("Monitored", DbType.Boolean, ColumnProperty.NotNull), new Column("Monitored", DbType.Boolean, ColumnProperty.NotNull),
new Column("QualityProfileId", DbType.Int16, ColumnProperty.NotNull), new Column("QualityProfileId", DbType.Int16, ColumnProperty.NotNull),
new Column("SeasonFolder", DbType.Boolean, ColumnProperty.NotNull), new Column("SeasonFolder", DbType.Boolean, ColumnProperty.NotNull),
new Column("LastInfoSync", DbType.DateTime, ColumnProperty.Null), new Column("LastInfoSync", DbType.DateTime, ColumnProperty.Null),
new Column("LastDiskSync", DbType.DateTime, ColumnProperty.Null) new Column("LastDiskSync", DbType.DateTime, ColumnProperty.Null)
}); });
Database.AddTable("Episodes", "SQLite", new[] Database.AddTable("Episodes", new[]
{ {
new Column("EpisodeId", DbType.Int32, ColumnProperty.PrimaryKeyWithIdentity), new Column("EpisodeId", DbType.Int32, ColumnProperty.PrimaryKeyWithIdentity),
new Column("TvDbEpisodeId", DbType.Int32, ColumnProperty.Null), new Column("TvDbEpisodeId", DbType.Int32, ColumnProperty.Null),
new Column("SeriesId", DbType.Int32, ColumnProperty.NotNull), new Column("SeriesId", DbType.Int32, ColumnProperty.NotNull),
new Column("SeasonNumber", DbType.Int16, ColumnProperty.NotNull), new Column("SeasonNumber", DbType.Int16, ColumnProperty.NotNull),
new Column("EpisodeNumber", DbType.Int16, ColumnProperty.NotNull), new Column("EpisodeNumber", DbType.Int16, ColumnProperty.NotNull),
new Column("Title", DbType.String, ColumnProperty.NotNull, String.Empty), new Column("Title", DbType.String, ColumnProperty.NotNull, String.Empty),
new Column("Overview", DbType.String, ColumnProperty.NotNull, String.Empty), new Column("Overview", DbType.String, ColumnProperty.NotNull, String.Empty),
new Column("Ignored", DbType.Boolean, ColumnProperty.NotNull, false), new Column("Ignored", DbType.Boolean, ColumnProperty.NotNull, false),
new Column("EpisodeFileId", DbType.Int32, ColumnProperty.Null), new Column("EpisodeFileId", DbType.Int32, ColumnProperty.Null),
new Column("AirDate", DbType.DateTime, ColumnProperty.Null), new Column("AirDate", DbType.DateTime, ColumnProperty.Null),
new Column("GrabDate", DbType.DateTime, ColumnProperty.Null) new Column("GrabDate", DbType.DateTime, ColumnProperty.Null)
}); });
Database.AddTable("EpisodeFiles", "SQLite", new[] Database.AddTable("EpisodeFiles", new[]
{ {
new Column("EpisodeFileId", DbType.Int32, new Column("EpisodeFileId", DbType.Int32,
ColumnProperty.PrimaryKeyWithIdentity), ColumnProperty.PrimaryKeyWithIdentity),
new Column("SeriesId", DbType.Int32, ColumnProperty.NotNull), new Column("SeriesId", DbType.Int32, ColumnProperty.NotNull),
new Column("Path", DbType.String, ColumnProperty.NotNull), new Column("Path", DbType.String, ColumnProperty.NotNull),
new Column("Quality", DbType.Int16, ColumnProperty.NotNull), new Column("Quality", DbType.Int16, ColumnProperty.NotNull),
new Column("Proper", DbType.Int16, ColumnProperty.NotNull), new Column("Proper", DbType.Int16, ColumnProperty.NotNull),
new Column("Size", DbType.Int64, ColumnProperty.NotNull), new Column("Size", DbType.Int64, ColumnProperty.NotNull),
new Column("DateAdded", DbType.DateTime, ColumnProperty.NotNull), new Column("DateAdded", DbType.DateTime, ColumnProperty.NotNull),
new Column("SeasonNumber", DbType.Int16, ColumnProperty.NotNull) new Column("SeasonNumber", DbType.Int16, ColumnProperty.NotNull)
}); });
Database.AddTable("Config", "SQLite", new[] Database.AddTable("Config", new[]
{ {
new Column("Key", DbType.String, ColumnProperty.PrimaryKey), new Column("Key", DbType.String, ColumnProperty.PrimaryKey),
new Column("Value", DbType.String, ColumnProperty.NotNull) new Column("Value", DbType.String, ColumnProperty.NotNull)
}); });
Database.AddTable("History", "SQLite", new[] Database.AddTable("SceneMappings", new[]
{ {
new Column("HistoryId", DbType.Int64, ColumnProperty.PrimaryKey), new Column("CleanTitle", DbType.String, ColumnProperty.PrimaryKey),
new Column("EpisodeId", DbType.Int32, ColumnProperty.NotNull), new Column("SeriesId", DbType.Int32, ColumnProperty.NotNull),
new Column("SeriesId", DbType.Int32, ColumnProperty.NotNull), new Column("SceneName", DbType.String, ColumnProperty.NotNull)
new Column("NzbTitle", DbType.String, ColumnProperty.NotNull), });
new Column("Date", DbType.DateTime, ColumnProperty.NotNull),
new Column("Quality", DbType.Int16, ColumnProperty.NotNull),
new Column("IsProper", DbType.Boolean, ColumnProperty.NotNull),
new Column("Indexer", DbType.String, ColumnProperty.NotNull)
});
Database.AddTable("RootDirs", "SQLite", new[] Database.AddTable("History", new[]
{ {
new Column("Id", DbType.Int32, ColumnProperty.PrimaryKey), new Column("HistoryId", DbType.Int64, ColumnProperty.PrimaryKey),
new Column("Path", DbType.String, ColumnProperty.NotNull) new Column("EpisodeId", DbType.Int32, ColumnProperty.NotNull),
}); new Column("SeriesId", DbType.Int32, ColumnProperty.NotNull),
new Column("NzbTitle", DbType.String, ColumnProperty.NotNull),
new Column("Date", DbType.DateTime, ColumnProperty.NotNull),
new Column("Quality", DbType.Int16, ColumnProperty.NotNull),
new Column("IsProper", DbType.Boolean, ColumnProperty.NotNull),
new Column("Indexer", DbType.String, ColumnProperty.NotNull)
});
Database.AddTable("ExternalNotificationSettings", "SQLite", new[] Database.AddTable("RootDirs", new[]
{ {
new Column("Id", DbType.Int32, ColumnProperty.PrimaryKey), new Column("Id", DbType.Int32, ColumnProperty.PrimaryKey),
new Column("Enabled", DbType.Boolean, ColumnProperty.NotNull) new Column("Path", DbType.String, ColumnProperty.NotNull)
, });
new Column("NotifierName", DbType.String,
ColumnProperty.NotNull),
new Column("Name", DbType.String, ColumnProperty.NotNull)
});
Database.AddTable("JobSettings", "SQLite", new[] Database.AddTable("ExternalNotificationSettings", new[]
{ {
new Column("Id", DbType.Int32, ColumnProperty.PrimaryKey), new Column("Id", DbType.Int32, ColumnProperty.PrimaryKey),
new Column("Enable", DbType.Boolean, ColumnProperty.NotNull), new Column("Enabled", DbType.Boolean, ColumnProperty.NotNull),
new Column("TypeName", DbType.String, ColumnProperty.NotNull), new Column("NotifierName", DbType.String, ColumnProperty.NotNull),
new Column("Name", DbType.String, ColumnProperty.NotNull), new Column("Name", DbType.String, ColumnProperty.NotNull)
new Column("Interval", DbType.Int32, ColumnProperty.NotNull), });
new Column("LastExecution", DbType.DateTime, ColumnProperty.NotNull),
new Column("Success", DbType.Boolean, ColumnProperty.NotNull)
});
Database.AddTable("QualityProfiles", "SQLite", new[] Database.AddTable("JobSettings", new[]
{ {
new Column("QualityProfileId", DbType.Int32, ColumnProperty.PrimaryKey), new Column("Id", DbType.Int32, ColumnProperty.PrimaryKey),
new Column("Name", DbType.String, ColumnProperty.NotNull), new Column("Enable", DbType.Boolean, ColumnProperty.NotNull),
new Column("Cutoff", DbType.Int32, ColumnProperty.NotNull), new Column("TypeName", DbType.String, ColumnProperty.NotNull),
new Column("SonicAllowed", DbType.String, ColumnProperty.NotNull), new Column("Name", DbType.String, ColumnProperty.NotNull),
}); new Column("Interval", DbType.Int32, ColumnProperty.NotNull),
new Column("LastExecution", DbType.DateTime, ColumnProperty.NotNull),
new Column("Success", DbType.Boolean, ColumnProperty.NotNull)
});
Database.AddTable("Logs", "SQLite", new[] Database.AddTable("QualityProfiles", new[]
{ {
new Column("LogId", DbType.Int64, ColumnProperty.PrimaryKey), new Column("QualityProfileId", DbType.Int32, ColumnProperty.PrimaryKey),
new Column("Message", DbType.String, ColumnProperty.NotNull), new Column("Name", DbType.String, ColumnProperty.NotNull),
new Column("Time", DbType.DateTime, ColumnProperty.NotNull), new Column("Cutoff", DbType.Int32, ColumnProperty.NotNull),
new Column("Logger", DbType.String, ColumnProperty.NotNull), new Column("SonicAllowed", DbType.String, ColumnProperty.NotNull),
new Column("Method", DbType.String, ColumnProperty.NotNull), });
new Column("Exception", DbType.String, ColumnProperty.Null),
new Column("ExceptionType", DbType.String, ColumnProperty.Null), Database.AddTable("Logs", new[]
new Column("Level", DbType.String, ColumnProperty.NotNull) {
}); new Column("LogId", DbType.Int64, ColumnProperty.PrimaryKey),
new Column("Message", DbType.String, ColumnProperty.NotNull),
new Column("Time", DbType.DateTime, ColumnProperty.NotNull),
new Column("Logger", DbType.String, ColumnProperty.NotNull),
new Column("Method", DbType.String, ColumnProperty.NotNull),
new Column("Exception", DbType.String, ColumnProperty.Null),
new Column("ExceptionType", DbType.String, ColumnProperty.Null),
new Column("Level", DbType.String, ColumnProperty.NotNull)
});
Database.AddTable("IndexerSettings", new[]
{
new Column("Id", DbType.Int32, ColumnProperty.PrimaryKey),
new Column("Enable", DbType.Boolean, ColumnProperty.NotNull),
new Column("IndexProviderType", DbType.String, ColumnProperty.NotNull),
new Column("Name", DbType.String, ColumnProperty.NotNull),
});
} }
public override void Down() public override void Down()
{ {
throw new NotImplementedException(); throw new NotImplementedException();

View File

@ -5,21 +5,21 @@
using NLog; using NLog;
using NzbDrone.Core.Providers.Indexer; using NzbDrone.Core.Providers.Indexer;
using NzbDrone.Core.Repository; using NzbDrone.Core.Repository;
using SubSonic.Repository; using PetaPoco;
namespace NzbDrone.Core.Providers namespace NzbDrone.Core.Providers
{ {
public class IndexerProvider public class IndexerProvider
{ {
private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
private readonly IRepository _repository; private readonly IDatabase _database;
private IList<IndexerBase> _indexers = new List<IndexerBase>(); private IList<IndexerBase> _indexers = new List<IndexerBase>();
[Inject] [Inject]
public IndexerProvider(IRepository repository) public IndexerProvider(IDatabase database)
{ {
_repository = repository; _database = database;
} }
public IndexerProvider() public IndexerProvider()
@ -35,7 +35,7 @@ public virtual IList<IndexerBase> GetEnabledIndexers()
public virtual List<IndexerSetting> GetAllISettings() public virtual List<IndexerSetting> GetAllISettings()
{ {
return _repository.All<IndexerSetting>().ToList(); return _database.Fetch<IndexerSetting>();
} }
public virtual void SaveSettings(IndexerSetting settings) public virtual void SaveSettings(IndexerSetting settings)
@ -43,18 +43,18 @@ public virtual void SaveSettings(IndexerSetting settings)
if (settings.Id == 0) if (settings.Id == 0)
{ {
Logger.Debug("Adding Indexer settings for {0}", settings.Name); Logger.Debug("Adding Indexer settings for {0}", settings.Name);
_repository.Add(settings); _database.Insert(settings);
} }
else else
{ {
Logger.Debug("Updating Indexer settings for {0}", settings.Name); Logger.Debug("Updating Indexer settings for {0}", settings.Name);
_repository.Update(settings); _database.Update(settings);
} }
} }
public virtual IndexerSetting GetSettings(Type type) public virtual IndexerSetting GetSettings(Type type)
{ {
return _repository.Single<IndexerSetting>(s => s.IndexProviderType == type.ToString()); return _database.Single<IndexerSetting>("WHERE IndexProviderType = @0", type.ToString());
} }
public virtual void InitializeIndexers(IList<IndexerBase> indexers) public virtual void InitializeIndexers(IList<IndexerBase> indexers)

View File

@ -1,11 +1,12 @@
using System; using System;
using SubSonic.SqlGeneration.Schema; using PetaPoco;
namespace NzbDrone.Core.Repository namespace NzbDrone.Core.Repository
{ {
[TableName("IndexerSettings")]
[PrimaryKey("Id", autoIncrement = true)]
public class IndexerSetting public class IndexerSetting
{ {
[SubSonicPrimaryKey(true)]
public int Id { get; set; } public int Id { get; set; }
public Boolean Enable { get; set; } public Boolean Enable { get; set; }