public static void Run(string connectionString) { var firstMigration = typeof(Lucid.Database.Migrations.Y2016.M01.V01); var assembly = new SingleAssembly(firstMigration.Assembly); var migrationGenerator = new SqlServer2008Generator(); var announcer = new NullAnnouncer(); var options = new ProcessorOptions(); var dbFactory = new SqlServerDbFactory(); var runnerContext = new RunnerContext(announcer) { Database = "SqlServer2008", Connection = connectionString, Targets = new string[] { firstMigration.Assembly.FullName }, NestedNamespaces = true, Namespace = "Lucid.Database.Migrations", }; using (var connection = new SqlConnection(connectionString)) using (var processor = new SqlServerProcessor(connection, migrationGenerator, announcer, options, dbFactory)) { var runner = new MigrationRunner(assembly, runnerContext, processor); runner.MigrateUp(); } }
public void MigrateToLatest(string connectionString, MigrationType migrationType) { lock (MigrationCache) { if (MigrationCache.Contains(connectionString.ToLower())) return; _announcer.Heading("Migrating " + connectionString); var assembly = Assembly.GetExecutingAssembly(); var migrationContext = new RunnerContext(_announcer) { Namespace = "NzbDrone.Core.Datastore.Migration", ApplicationContext = new MigrationContext { MigrationType = migrationType, SQLiteAlter = _sqLiteAlter, MigrationHelper = _migrationHelper, } }; 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()); } }
public static void RunMigrations(string connectionString, string migration) { // var announcer = new NullAnnouncer(); var announcer = new TextWriterAnnouncer(s => System.Diagnostics.Debug.WriteLine(s)); var assembly = Assembly.GetExecutingAssembly(); var migrationContext = new RunnerContext(announcer) { Namespace = "Azimuth.Migrations", WorkingDirectory = "Migrations" }; var options = new MigrationOptions { PreviewOnly = false, Timeout = 60 }; var factory = new FluentMigrator.Runner.Processors.SqlServer.SqlServer2012ProcessorFactory(); var processor = factory.Create(connectionString, announcer, options); var runner = new MigrationRunner(assembly, migrationContext, processor); switch (migration) { case "Run migrations": runner.MigrateUp(true); break; case "Drop all tables": runner.RollbackToVersion(201408091845); runner.Rollback(1); break; } }
public void Migrate(string connectionString, MigrationContext migrationContext) { var sw = Stopwatch.StartNew(); _announcer.Heading("Migrating " + connectionString); var assembly = Assembly.GetExecutingAssembly(); var runnerContext = new RunnerContext(_announcer) { Namespace = "NzbDrone.Core.Datastore.Migration", ApplicationContext = migrationContext }; var options = new MigrationOptions { PreviewOnly = false, Timeout = 60 }; var factory = new NzbDroneSqliteProcessorFactory(); var processor = factory.Create(connectionString, _announcer, options); var runner = new MigrationRunner(assembly, runnerContext, processor); if (migrationContext.DesiredVersion.HasValue) { runner.MigrateUp(migrationContext.DesiredVersion.Value, true); } else { runner.MigrateUp(true); } sw.Stop(); _announcer.ElapsedTime(sw.Elapsed); }
public void CanUseCustomVersionInfo() { ExecuteWithSupportedProcessors(processor => { var runner = new MigrationRunner(Assembly.GetExecutingAssembly(), new RunnerContext(new TextWriterAnnouncer(System.Console.Out)) { Namespace = "FluentMigrator.Tests.Integration.Migrations.Interleaved.Pass3" }, processor); IVersionTableMetaData tableMetaData = new TestVersionTableMetaData(); //ensure table doesn't exist if (processor.TableExists(tableMetaData.SchemaName, tableMetaData.TableName)) runner.Down(new VersionMigration(tableMetaData)); //ensure schema doesn't exist if (processor.SchemaExists(tableMetaData.SchemaName)) runner.Down(new VersionSchemaMigration(tableMetaData)); runner.Up(new VersionSchemaMigration(tableMetaData)); processor.SchemaExists(tableMetaData.SchemaName).ShouldBeTrue(); runner.Up(new VersionMigration(tableMetaData)); processor.TableExists(tableMetaData.SchemaName, tableMetaData.TableName).ShouldBeTrue(); runner.Down(new VersionMigration(tableMetaData)); processor.TableExists(tableMetaData.SchemaName, tableMetaData.TableName).ShouldBeFalse(); runner.Down(new VersionSchemaMigration(tableMetaData)); processor.SchemaExists(tableMetaData.SchemaName).ShouldBeFalse(); }, true, typeof(SqliteProcessor)); }
public MigrationState GetMigrationState() { var state = new MigrationState(); try { using (var connection = new SqlConnection(_connectionString)) { var context = new RunnerContext(_announcer); var generator = GetMigrationGenerator(_syntax); var processor = new SqlServerProcessor(connection, generator, _announcer, _options); var runner = new FluentMigrator.Runner.MigrationRunner(_assembly, context, processor); state.Total = runner.MigrationLoader.Migrations.Keys.Count; foreach (var mig in runner.MigrationLoader.Migrations.Keys) { if (runner.VersionLoader.VersionInfo.HasAppliedMigration(mig)) { state.Completed++; } else { state.Pending++; } } } } catch (Exception ex) { state.Exception = ex; } return(state); }
public void UpgradeDatabase() { var assembly = System.Reflection.Assembly.GetExecutingAssembly(); var announcer = new TextWriterAnnouncer(s => Log.Debug(s)); var context = new RunnerContext(announcer) { Namespace = "Causal.Server.Migrations" }; var providerName = ConfigurationManager.ConnectionStrings["CausalContext"].ProviderName; MigrationProcessorFactory factory; if (providerName.Equals("Npgsql", StringComparison.InvariantCultureIgnoreCase)) { factory = new FluentMigrator.Runner.Processors.Postgres.PostgresProcessorFactory(); } else if (providerName.Equals("System.Data.SqlClient", StringComparison.InvariantCultureIgnoreCase)) { factory = new FluentMigrator.Runner.Processors.SqlServer.SqlServer2008ProcessorFactory(); } else { throw new Exception("Unknown provider for connection string CausalContext"); } var options = new ProcessorOptions { PreviewOnly = false }; var processor = factory.Create(ConfigurationManager.ConnectionStrings["CausalContext"].ConnectionString, announcer, options); var migrator = new MigrationRunner(assembly, context, processor); migrator.MigrateUp(true); }
public static void Run(IContainer settingsContainer) { var connectionString = settingsContainer.GetInstance<string>("DefaultConnection"); Announcer announcer = new TextWriterAnnouncer(s => System.Diagnostics.Debug.WriteLine(s)); announcer.ShowSql = true; Assembly assembly = typeof(CreateTableEstacionamento).Assembly; IRunnerContext migrationContext = new RunnerContext(announcer); var options = new ProcessorOptions { PreviewOnly = false, // set to true to see the SQL Timeout = 60 }; try { var factory = settingsContainer.GetInstance<MigrationProcessorFactory>(); //new FluentMigrator.Runner.Processors.SQLite.SQLiteProcessorFactory(); var processor = factory.Create(connectionString, announcer, options); var runner = new MigrationRunner(assembly, migrationContext, processor); runner.MigrateUp(true); } catch (Exception ex) { throw new InvalidOperationException("connectionString: " + connectionString, ex); } }
protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines) { base.ApplicationStartup(container, pipelines); var announcer = new NullAnnouncer(); var assembly = Assembly.GetExecutingAssembly(); var migrationContext = new RunnerContext(announcer) { Namespace = "Server.Migrations" }; var options = new MigrationOptions(); var factory = new FluentMigrator.Runner.Processors.SqlServer.SqlServer2008ProcessorFactory(); var processor = factory.Create( ConfigurationManager.ConnectionStrings["Simple.Data.Properties.Settings.DefaultConnectionString"].ConnectionString, announcer, options); var runner = new MigrationRunner(assembly, migrationContext, processor); runner.MigrateUp(true); pipelines.EnableBasicAuthentication(new BasicAuthenticationConfiguration(new UserValidator(), "CPNRealm")); JsonSettings.RetainCasing = true; StaticConfiguration.DisableErrorTraces = false; }
public void Migrate(Action<IMigrationRunner> runnerAction) { var options = new MigrationOptions { PreviewOnly = false, Timeout = 0 }; var factory = new FluentMigrator.Runner.Processors.MigrationProcessorFactoryProvider().GetFactory(_dbType); var announcer = new TextWriterAnnouncer(s => System.Diagnostics.Debug.WriteLine(s)); var migrationContext = new RunnerContext(announcer); var processor = factory.Create(_connectionString, announcer, options); var runner = new MigrationRunner(_migrationAssembly, migrationContext, processor); runnerAction(runner); }
public MigrationVersionRunner(IMigrationConventions conventions, IMigrationProcessor processor, IMigrationLoader loader, Assembly assembly, string @namespace) { _migrationConventions = conventions; _migrationProcessor = processor; _migrationAssembly = assembly; _migrationLoader = loader; _namespace = @namespace; _migrationRunner = new MigrationRunner(conventions, processor); _versionMigration = new VersionMigration(); }
private void MigrateTo(long targetVersion) { var options = new MigrationOptions { PreviewOnly = false, Timeout = 60 }; var announcer = new NullAnnouncer(); var processor = new SqlServer2012ProcessorFactory().Create(connectionString, announcer, options); var migrationContext = new RunnerContext(announcer) { Namespace = "DDDEastAnglia.DatabaseMigrations.Migrations" }; var runner = new MigrationRunner(GetType().Assembly, migrationContext, processor); runner.MigrateUp(targetVersion, true); }
private MigrationRunner GetMigrationRunner(long version, string profile = "") { if(string.IsNullOrEmpty(ConnectionString)) throw new EmptyConnectionStringException("ConnectionString property not initialized"); var options = new MigrationOptions() {PreviewOnly = false, Timeout = 60}; var factory = new FluentMigrator.Runner.Processors.SqlServer.SqlServer2008ProcessorFactory(); var processor = factory.Create(ConnectionString, Announcer, options); var assembly = Assembly.GetExecutingAssembly(); var runner = new MigrationRunner(assembly, GetMigrationContext(version, profile), processor); return runner; }
public void Migrate(Action<IMigrationRunner> runnerAction) { var options = new MigrationOptions { PreviewOnly = false, Timeout = 0 }; var factory = new FluentMigrator.Runner.Processors.SqlServer.SqlServer2008ProcessorFactory(); var assembly = Assembly.GetExecutingAssembly(); var announcer = new TextWriterAnnouncer(s => System.Diagnostics.Debug.WriteLine(s)); var migrationContext = new RunnerContext(announcer); var processor = factory.Create(this._connectionString, announcer, options); var runner = new MigrationRunner(assembly, migrationContext, processor); runnerAction(runner); }
public void Migrate() { var processor = GetProcessor(); var context = new RunnerContext(new NullAnnouncer()); var migrationRunner = new MigrationRunner( typeof (SqlSchemaMigrator).Assembly, context, processor); migrationRunner.MigrateUp(); }
public void Run() { using (var connection = new SqlConnection(_connectionString)) { var context = new RunnerContext(_announcer); var generator = GetMigrationGenerator(_syntax); var processor = new SqlServerProcessor(connection, generator, _announcer, _options); var runner = new FluentMigrator.Runner.MigrationRunner(_assembly, context, processor); runner.MigrateUp(); } }
public static void Update(IAnnouncer announcer, MigrationProcessorType type, string connectionString, Assembly migrationAssembly) { var context = new RunnerContext(announcer); var options = new ProcessorOptions(); var factory = GetProcessorFactory(type); var processor = factory.Create(connectionString, announcer, options); var runner = new MigrationRunner(migrationAssembly, context, processor); runner.MigrateUp(); }
public MigrationVersionRunner(IMigrationConventions conventions, IMigrationProcessor processor, IMigrationLoader loader, Assembly assembly, string @namespace, IAnnouncer announcer) { _migrationConventions = conventions; _migrationProcessor = processor; _migrationAssembly = assembly; _migrationLoader = loader; _namespace = @namespace; _announcer = announcer; _migrationRunner = new MigrationRunner(conventions, processor, announcer, new StopWatch()); _versionTableMetaData = loader.GetVersionTableMetaData(assembly); _versionMigration = new VersionMigration(_versionTableMetaData); }
public void CanApplyForeignKeyConventionWithSchema() { ExecuteWithSupportedProcessors( processor => { var runner = new MigrationRunner(Assembly.GetExecutingAssembly(), _runnerContext, processor); runner.Up(new TestForeignKeyNamingConventionWithSchema()); processor.ConstraintExists("TestSchema", "Users", "FK_Users_GroupId_Groups_GroupId").ShouldBeTrue(); runner.Down(new TestForeignKeyNamingConvention()); }, false, typeof(SqliteProcessor)); }
public static void MigrateToLatest() { var connectionString = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString; var migrationAssembly= Assembly.GetExecutingAssembly(); var announcer = new TextWriterAnnouncer(s => System.Diagnostics.Debug.WriteLine(s)); var migrationContext = new RunnerContext(announcer); var factory = new FluentMigrator.Runner.Processors.SqlServer.SqlServer2008ProcessorFactory(); var options = new MigrationOptions { PreviewOnly = false, Timeout = 0 }; var processor = factory.Create(connectionString, announcer, options); var runner = new MigrationRunner(migrationAssembly, migrationContext, processor); runner.MigrateUp(); }
public Migrator(string connectionString, params Assembly[] assemblies) { var announcer = new TextWriterAnnouncer(Console.Write); IAssemblyCollection assemblyCollection = new AssemblyCollection(assemblies); var migrationContext = new RunnerContext(announcer); var options = new MigrationOptions { PreviewOnly = false, Timeout = 60 }; PostgresProcessorFactory factory = new PostgresProcessorFactory(); IMigrationProcessor processor = factory.Create(connectionString, announcer, options); runner = new MigrationRunner(assemblyCollection, migrationContext, processor); }
public void MigrateToLatest() { var announcer = new TextWriterAnnouncer(s => Debug.WriteLine(s)); var assembly = Assembly.GetExecutingAssembly(); var migrationContext = new RunnerContext(announcer); var options = new MigrationOptions { PreviewOnly = false, Timeout = 60 }; var factory = new FluentMigrator.Runner.Processors.SqlServer.SqlServer2012ProcessorFactory(); using (var processor = factory.Create(connectionString, announcer, options)) { var runner = new MigrationRunner(assembly, migrationContext, processor); runner.MigrateUp(true); } }
public void CanApplyIndexConvention() { ExecuteWithSupportedProcessors( processor => { var conventions = new MigrationConventions(); var runner = new MigrationRunner(conventions, processor, new TextWriterAnnouncer(System.Console.Out), new StopWatch()); runner.Up(new TestIndexNamingConvention()); processor.TableExists("Users").ShouldBeTrue(); runner.Down(new TestIndexNamingConvention()); processor.TableExists("Users").ShouldBeFalse(); }); }
public void CanRunMigration() { ExecuteWithSupportedProcessors(processor => { var conventions = new MigrationConventions(); var runner = new MigrationRunner(conventions, processor, new TextWriterAnnouncer(System.Console.Out), new StopWatch()); runner.Up(new TestCreateAndDropTableMigration()); processor.TableExists("TestTable").ShouldBeTrue(); runner.Down(new TestCreateAndDropTableMigration()); processor.TableExists("TestTable").ShouldBeFalse(); }); }
public void CanRunMigration() { ExecuteWithSupportedProcessors(processor => { var conventions = new MigrationConventions(); var runner = new MigrationRunner(conventions, processor); runner.Up(new TestCreateAndDropTableMigration()); processor.TableExists("TestTable").ShouldBeTrue(); runner.Down(new TestCreateAndDropTableMigration()); processor.TableExists("TestTable").ShouldBeFalse(); }); }
public void CanApplyIndexConvention() { var connection = new SqlConnection(sqlServerConnectionString); connection.Open(); var processor = new SqlServerProcessor(connection, new SqlServerGenerator()); var conventions = new MigrationConventions(); var runner = new MigrationRunner(conventions, processor); runner.Up(new TestIndexNamingConvention()); processor.TableExists("Users").ShouldBeTrue(); runner.Down(new TestIndexNamingConvention()); processor.TableExists("Users").ShouldBeFalse(); }
public void MigrateToLatest() { var asm = Assembly.GetExecutingAssembly(); var announcer = new TextWriterAnnouncer((str) => { Debug.WriteLine(str); }); var context = new RunnerContext(announcer); var options = new MigrationOptions(); var factory = new SqlServer2012ProcessorFactory(); var processor = factory.Create(this._connectionString, announcer, options); var runner = new MigrationRunner(asm, context, processor); runner.MigrateUp(true); }
public void CanApplyIndexConvention() { ExecuteWithSupportedProcessors( processor => { var conventions = new MigrationConventions(); var runner = new MigrationRunner(conventions, processor); runner.Up(new TestIndexNamingConvention()); processor.TableExists("Users").ShouldBeTrue(); runner.Down(new TestIndexNamingConvention()); processor.TableExists("Users").ShouldBeFalse(); }); }
public void CanApplyIndexConvention() { ExecuteWithSupportedProcessors( processor => { var runner = new MigrationRunner(Assembly.GetExecutingAssembly(), _runnerContext, processor); runner.Up(new TestIndexNamingConvention()); processor.TableExists("Users").ShouldBeTrue(); runner.Down(new TestIndexNamingConvention()); processor.TableExists("Users").ShouldBeFalse(); //processor.CommitTransaction(); }); }
public void CanApplyForeignKeyConvention() { ExecuteWithSupportedProcessors( processor => { var runner = new MigrationRunner(Assembly.GetExecutingAssembly(), _runnerContext, processor); runner.Up(new TestForeignKeyNamingConvention()); // This is a hack until MigrationVersionRunner and MigrationRunner are refactored and merged together //processor.CommitTransaction(); processor.ConstraintExists( "Users", "FK_Users_GroupId_Groups_GroupId" ).ShouldBeTrue(); runner.Down( new TestForeignKeyNamingConvention() ); }); }
public void CanSilentlyFail() { var processor = new Mock<IMigrationProcessor>(); processor.Setup(x => x.Process(It.IsAny<CreateForeignKeyExpression>())).Throws(new Exception("Error")); processor.Setup(x => x.Process(It.IsAny<DeleteForeignKeyExpression>())).Throws(new Exception("Error")); var conventions = new MigrationConventions(); var runner = new MigrationRunner(conventions, processor.Object) { SilentlyFail = true }; runner.Up(new TestForeignKeySilentFailure()); runner.CaughtExceptions.Count.ShouldBeGreaterThan(0); runner.Down(new TestForeignKeySilentFailure()); runner.CaughtExceptions.Count.ShouldBeGreaterThan(0); }
public void Update() { IAnnouncer announcer = CreateAnnouncer(); IRunnerContext migrationContext = new RunnerContext(announcer); ProcessorOptions options = new ProcessorOptions { PreviewOnly = false, Timeout = 200 }; IMigrationProcessorFactory factory = new SqlServer2008ProcessorFactory(); Assembly migrationContainer = typeof(InitialDeployment).Assembly; using (IMigrationProcessor processor = factory.Create(connectionString, announcer, options)) { FluentMigrator.Runner.IMigrationRunner runner = new FluentMigrator.Runner.MigrationRunner(migrationContainer, migrationContext, processor); runner.MigrateUp(); } }
public void SetUp() { _applicationContext = new Random().Next(); _migrationList = new SortedList<long, IMigrationInfo>(); _runnerContextMock = new Mock<IRunnerContext>(MockBehavior.Loose); _processorMock = new Mock<IMigrationProcessor>(MockBehavior.Loose); _migrationLoaderMock = new Mock<IMigrationInformationLoader>(MockBehavior.Loose); _profileLoaderMock = new Mock<IProfileLoader>(MockBehavior.Loose); _announcer = new Mock<IAnnouncer>(); _stopWatch = new Mock<IStopWatch>(); _stopWatch.Setup(x => x.Time(It.IsAny<Action>())).Returns(new TimeSpan(1)).Callback((Action a) => a.Invoke()); var options = new ProcessorOptions { PreviewOnly = false }; _processorMock.SetupGet(x => x.Options).Returns(options); _processorMock.SetupGet(x => x.ConnectionString).Returns(IntegrationTestOptions.SqlServer2008.ConnectionString); _runnerContextMock.SetupGet(x => x.Namespace).Returns("FluentMigrator.Tests.Integration.Migrations"); _runnerContextMock.SetupGet(x => x.Announcer).Returns(_announcer.Object); _runnerContextMock.SetupGet(x => x.StopWatch).Returns(_stopWatch.Object); _runnerContextMock.SetupGet(x => x.Target).Returns(Assembly.GetExecutingAssembly().ToString()); _runnerContextMock.SetupGet(x => x.Connection).Returns(IntegrationTestOptions.SqlServer2008.ConnectionString); _runnerContextMock.SetupGet(x => x.Database).Returns("sqlserver"); _runnerContextMock.SetupGet(x => x.ApplicationContext).Returns(_applicationContext); _migrationLoaderMock.Setup(x => x.LoadMigrations()).Returns(()=> _migrationList); _runner = new MigrationRunner(Assembly.GetAssembly(typeof(MigrationRunnerTests)), _runnerContextMock.Object, _processorMock.Object) { MigrationLoader = _migrationLoaderMock.Object, ProfileLoader = _profileLoaderMock.Object, }; _fakeVersionLoader = new TestVersionLoader(_runner, _runner.VersionLoader.VersionTableMetaData); _runner.VersionLoader = _fakeVersionLoader; _processorMock.Setup(x => x.SchemaExists(It.Is<string>(s => s == _runner.VersionLoader.VersionTableMetaData.SchemaName))) .Returns(true); _processorMock.Setup(x => x.TableExists(It.Is<string>(s => s == _runner.VersionLoader.VersionTableMetaData.SchemaName), It.Is<string>(t => t == _runner.VersionLoader.VersionTableMetaData.TableName))) .Returns(true); }