refactored Migrations
This commit is contained in:
parent
a6fe8b276b
commit
a1653022ad
|
@ -56,7 +56,7 @@ namespace NzbDrone.Core
|
||||||
|
|
||||||
LogConfiguration.Setup();
|
LogConfiguration.Setup();
|
||||||
|
|
||||||
Migrations.Run();
|
Migrations.Run(Connection.MainConnectionString);
|
||||||
ForceMigration(_kernel.Get<IRepository>());
|
ForceMigration(_kernel.Get<IRepository>());
|
||||||
|
|
||||||
SetupDefaultQualityProfiles(_kernel.Get<IRepository>()); //Setup the default QualityProfiles on start-up
|
SetupDefaultQualityProfiles(_kernel.Get<IRepository>()); //Setup the default QualityProfiles on start-up
|
||||||
|
@ -97,9 +97,9 @@ namespace NzbDrone.Core
|
||||||
_kernel.Bind<WebTimer>().ToSelf().InSingletonScope();
|
_kernel.Bind<WebTimer>().ToSelf().InSingletonScope();
|
||||||
_kernel.Bind<AutoConfigureProvider>().ToSelf().InSingletonScope();
|
_kernel.Bind<AutoConfigureProvider>().ToSelf().InSingletonScope();
|
||||||
|
|
||||||
_kernel.Bind<IRepository>().ToConstant(Connection.MainDataRepository).InSingletonScope();
|
_kernel.Bind<IRepository>().ToConstant(Connection.CreateSimpleRepository(Connection.MainConnectionString)).InSingletonScope();
|
||||||
_kernel.Bind<IRepository>().ToConstant(Connection.LogDataRepository).WhenInjectedInto<SubsonicTarget>().InSingletonScope();
|
_kernel.Bind<IRepository>().ToConstant(Connection.CreateSimpleRepository(Connection.LogConnectionString)).WhenInjectedInto<SubsonicTarget>().InSingletonScope();
|
||||||
_kernel.Bind<IRepository>().ToConstant(Connection.LogDataRepository).WhenInjectedInto<LogProvider>().InSingletonScope();
|
_kernel.Bind<IRepository>().ToConstant(Connection.CreateSimpleRepository(Connection.LogConnectionString)).WhenInjectedInto<LogProvider>().InSingletonScope();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,11 +18,16 @@ namespace NzbDrone.Core.Datastore
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static string GetConnectionString(string path)
|
||||||
|
{
|
||||||
|
return String.Format("Data Source={0};Version=3;", path);
|
||||||
|
}
|
||||||
|
|
||||||
public static String MainConnectionString
|
public static String MainConnectionString
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return String.Format("Data Source={0};Version=3;", Path.Combine(AppDataPath.FullName, "nzbdrone.db"));
|
return GetConnectionString(Path.Combine(AppDataPath.FullName, "nzbdrone.db"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,70 +35,19 @@ namespace NzbDrone.Core.Datastore
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return String.Format("Data Source={0};Version=3;", Path.Combine(AppDataPath.FullName, "log.db"));
|
return GetConnectionString(Path.Combine(AppDataPath.FullName, "log.db"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static IDataProvider GetDataProvider(string connectionString)
|
||||||
private static IDataProvider _mainDataProvider;
|
|
||||||
public static IDataProvider MainDataProvider
|
|
||||||
{
|
{
|
||||||
get
|
return ProviderFactory.GetProvider(connectionString, "System.Data.SQLite");
|
||||||
{
|
|
||||||
if (_mainDataProvider == null)
|
|
||||||
{
|
|
||||||
_mainDataProvider = ProviderFactory.GetProvider(Connection.MainConnectionString, "System.Data.SQLite");
|
|
||||||
}
|
|
||||||
return _mainDataProvider;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
public static IRepository CreateSimpleRepository(string connectionString)
|
||||||
|
|
||||||
private static IDataProvider _logDataProvider;
|
|
||||||
public static IDataProvider LogDataProvider
|
|
||||||
{
|
{
|
||||||
get
|
return new SimpleRepository(GetDataProvider(connectionString), SimpleRepositoryOptions.RunMigrations);
|
||||||
{
|
|
||||||
if (_logDataProvider == null)
|
|
||||||
{
|
|
||||||
_logDataProvider = ProviderFactory.GetProvider(Connection.LogConnectionString, "System.Data.SQLite");
|
|
||||||
}
|
}
|
||||||
return _logDataProvider;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private static SimpleRepository _mainDataRepository;
|
|
||||||
public static SimpleRepository MainDataRepository
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
if (_mainDataRepository == null)
|
|
||||||
{
|
|
||||||
_mainDataRepository = new SimpleRepository(MainDataProvider, SimpleRepositoryOptions.RunMigrations);
|
|
||||||
}
|
|
||||||
|
|
||||||
return _mainDataRepository;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private static SimpleRepository _logDataRepository;
|
|
||||||
public static SimpleRepository LogDataRepository
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
if (_logDataRepository == null)
|
|
||||||
{
|
|
||||||
_logDataRepository = new SimpleRepository(LogDataProvider, SimpleRepositoryOptions.RunMigrations);
|
|
||||||
}
|
|
||||||
return _logDataRepository;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,16 +16,16 @@ namespace NzbDrone.Core.Datastore
|
||||||
{
|
{
|
||||||
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
||||||
|
|
||||||
public static void Run()
|
public static void Run(string connetionString)
|
||||||
{
|
{
|
||||||
Logger.Info("Preparing to migrate databse");
|
Logger.Info("Preparing run database migration");
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var mig = new Migrator.Migrator("Sqlite", Connection.MainConnectionString,
|
var migrator = new Migrator.Migrator("Sqlite", connetionString,
|
||||||
Assembly.GetAssembly(typeof(Migrations)), true, new MigrationLogger());
|
Assembly.GetAssembly(typeof(Migrations)), true, new MigrationLogger());
|
||||||
|
|
||||||
mig.MigrateToLastVersion();
|
migrator.MigrateToLastVersion();
|
||||||
|
|
||||||
Logger.Info("Database migration completed");
|
Logger.Info("Database migration completed");
|
||||||
}
|
}
|
||||||
|
@ -110,11 +110,8 @@ namespace NzbDrone.Core.Datastore
|
||||||
public class Migration20110603 : Migration
|
public class Migration20110603 : Migration
|
||||||
{
|
{
|
||||||
public override void Up()
|
public override void Up()
|
||||||
{
|
|
||||||
if(Database.TableExists("Seasons"))
|
|
||||||
{
|
{
|
||||||
Database.RemoveTable("Seasons");
|
Database.RemoveTable("Seasons");
|
||||||
}
|
|
||||||
|
|
||||||
Migrations.RemoveDeletedColumns(Database);
|
Migrations.RemoveDeletedColumns(Database);
|
||||||
Migrations.AddNewColumns(Database);
|
Migrations.AddNewColumns(Database);
|
||||||
|
|
|
@ -26,7 +26,7 @@ namespace NzbDrone.Core.Datastore
|
||||||
|
|
||||||
public virtual ITable GetSchemaFromType(Type type)
|
public virtual ITable GetSchemaFromType(Type type)
|
||||||
{
|
{
|
||||||
return type.ToSchemaTable(Connection.MainDataProvider);
|
return type.ToSchemaTable(Connection.GetDataProvider(Connection.MainConnectionString));
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual Column[] GetColumnsFromDatabase(ITransformationProvider database, string tableName)
|
public virtual Column[] GetColumnsFromDatabase(ITransformationProvider database, string tableName)
|
||||||
|
|
Loading…
Reference in New Issue