mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-14 02:37:08 -07:00
cleaned up test db path for tests.
This commit is contained in:
parent
02c175950b
commit
dde91569ac
15 changed files with 123 additions and 133 deletions
|
@ -2,19 +2,25 @@
|
|||
using System.Data.SQLite;
|
||||
using Marr.Data;
|
||||
using Marr.Data.Reflection;
|
||||
using NzbDrone.Common.Composition;
|
||||
using NzbDrone.Common.EnvironmentInfo;
|
||||
using NzbDrone.Common.Messaging;
|
||||
using NzbDrone.Core.Datastore.Migration.Framework;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Core.Instrumentation;
|
||||
|
||||
|
||||
namespace NzbDrone.Core.Datastore
|
||||
{
|
||||
public interface IDbFactory
|
||||
{
|
||||
IDatabase Create(string dbPath, MigrationType migrationType = MigrationType.Main);
|
||||
IDatabase Create(MigrationType migrationType = MigrationType.Main);
|
||||
}
|
||||
|
||||
public class DbFactory : IDbFactory
|
||||
{
|
||||
private readonly IMigrationController _migrationController;
|
||||
private readonly IAppDirectoryInfo _appDirectoryInfo;
|
||||
|
||||
static DbFactory()
|
||||
{
|
||||
|
@ -22,13 +28,46 @@ namespace NzbDrone.Core.Datastore
|
|||
TableMapping.Map();
|
||||
}
|
||||
|
||||
public DbFactory(IMigrationController migrationController)
|
||||
public static void RegisterDatabase(IContainer container)
|
||||
{
|
||||
_migrationController = migrationController;
|
||||
container.Register(c => c.Resolve<IDbFactory>().Create());
|
||||
|
||||
container.Register<ILogRepository>(c =>
|
||||
{
|
||||
var db = c.Resolve<IDbFactory>().Create(MigrationType.Log);
|
||||
return new LogRepository(db, c.Resolve<IMessageAggregator>());
|
||||
});
|
||||
}
|
||||
|
||||
public IDatabase Create(string dbPath, MigrationType migrationType = MigrationType.Main)
|
||||
public DbFactory(IMigrationController migrationController, IAppDirectoryInfo appDirectoryInfo)
|
||||
{
|
||||
_migrationController = migrationController;
|
||||
_appDirectoryInfo = appDirectoryInfo;
|
||||
}
|
||||
|
||||
public IDatabase Create(MigrationType migrationType = MigrationType.Main)
|
||||
{
|
||||
string dbPath;
|
||||
|
||||
switch (migrationType)
|
||||
{
|
||||
case MigrationType.Main:
|
||||
{
|
||||
dbPath = _appDirectoryInfo.GetNzbDroneDatabase();
|
||||
break;
|
||||
}
|
||||
case MigrationType.Log:
|
||||
{
|
||||
dbPath = _appDirectoryInfo.GetLogDatabase();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
throw new ArgumentException("Invalid MigrationType");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var connectionString = GetConnectionString(dbPath);
|
||||
|
||||
_migrationController.MigrateToLatest(connectionString, migrationType);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue