@ -1,4 +1,6 @@
using System.Reflection ;
using System.Collections.Concurrent ;
using System.Collections.Generic ;
using System.Reflection ;
using FluentMigrator.Runner ;
using FluentMigrator.Runner.Initialization ;
using FluentMigrator.Runner.Processors.Sqlite ;
@ -14,6 +16,8 @@ namespace NzbDrone.Core.Datastore.Migration.Framework
{
private readonly IAnnouncer _announcer ;
private static readonly HashSet < string > MigrationCache = new HashSet < string > ( ) ;
public MigrationController ( IAnnouncer announcer )
{
_announcer = announcer ;
@ -21,19 +25,26 @@ namespace NzbDrone.Core.Datastore.Migration.Framework
public void MigrateToLatest ( string connectionString , MigrationType migrationType )
{
var assembly = Assembly . GetExecutingAssembly ( ) ;
var migrationContext = new RunnerContext ( _announcer )
lock ( MigrationCache )
{
Namespace = "NzbDrone.Core.Datastore.Migration" ,
ApplicationContext = migrationType
} ;
var options = new MigrationOptions { PreviewOnly = false , Timeout = 60 } ;
var factory = new SqliteProcessorFactory ( ) ;
var processor = factory . Create ( connectionString , _announcer , options ) ;
var runner = new MigrationRunner ( assembly , migrationContext , processor ) ;
runner . MigrateUp ( true ) ;
if ( MigrationCache . Contains ( connectionString . ToLower ( ) ) ) return ;
var assembly = Assembly . GetExecutingAssembly ( ) ;
var migrationContext = new RunnerContext ( _announcer )
{
Namespace = "NzbDrone.Core.Datastore.Migration" ,
ApplicationContext = migrationType
} ;
var options = new MigrationOptions { PreviewOnly = false , Timeout = 60 } ;
var factory = new SqliteProcessorFactory ( ) ;
var processor = factory . Create ( connectionString , _announcer , options ) ;
var runner = new MigrationRunner ( assembly , migrationContext , processor ) ;
runner . MigrateUp ( true ) ;
MigrationCache . Add ( connectionString . ToLower ( ) ) ;
}
}
}
}