2014-12-02 19:21:43 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Diagnostics;
|
2014-11-24 20:00:19 +00:00
|
|
|
|
using System.Reflection;
|
2013-03-25 06:13:53 +00:00
|
|
|
|
using FluentMigrator.Runner;
|
|
|
|
|
using FluentMigrator.Runner.Initialization;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Datastore.Migration.Framework
|
|
|
|
|
{
|
|
|
|
|
public interface IMigrationController
|
|
|
|
|
{
|
2014-12-02 19:21:43 +00:00
|
|
|
|
void MigrateToLatest(string connectionString, MigrationType migrationType, Action<NzbDroneMigrationBase> beforeMigration);
|
2013-03-25 06:13:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class MigrationController : IMigrationController
|
|
|
|
|
{
|
|
|
|
|
private readonly IAnnouncer _announcer;
|
|
|
|
|
|
2014-08-25 21:29:37 +00:00
|
|
|
|
public MigrationController(IAnnouncer announcer)
|
2013-03-25 06:13:53 +00:00
|
|
|
|
{
|
|
|
|
|
_announcer = announcer;
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-02 19:21:43 +00:00
|
|
|
|
public void MigrateToLatest(string connectionString, MigrationType migrationType, Action<NzbDroneMigrationBase> beforeMigration)
|
2013-03-25 06:13:53 +00:00
|
|
|
|
{
|
2014-11-24 20:00:19 +00:00
|
|
|
|
var sw = Stopwatch.StartNew();
|
|
|
|
|
|
2013-11-30 21:08:53 +00:00
|
|
|
|
_announcer.Heading("Migrating " + connectionString);
|
|
|
|
|
|
|
|
|
|
var assembly = Assembly.GetExecutingAssembly();
|
|
|
|
|
|
|
|
|
|
var migrationContext = new RunnerContext(_announcer)
|
|
|
|
|
{
|
|
|
|
|
Namespace = "NzbDrone.Core.Datastore.Migration",
|
2014-12-02 19:21:43 +00:00
|
|
|
|
ApplicationContext = new MigrationContext(migrationType, beforeMigration)
|
2013-11-30 21:08:53 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var options = new MigrationOptions { PreviewOnly = false, Timeout = 60 };
|
2014-08-25 21:29:37 +00:00
|
|
|
|
var factory = new NzbDroneSqliteProcessorFactory();
|
2013-11-30 21:08:53 +00:00
|
|
|
|
var processor = factory.Create(connectionString, _announcer, options);
|
|
|
|
|
var runner = new MigrationRunner(assembly, migrationContext, processor);
|
|
|
|
|
runner.MigrateUp(true);
|
2014-11-24 20:00:19 +00:00
|
|
|
|
|
|
|
|
|
sw.Stop();
|
|
|
|
|
|
2014-12-02 19:21:43 +00:00
|
|
|
|
_announcer.ElapsedTime(sw.Elapsed);
|
2013-03-25 06:13:53 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|