public void SetUp()
        {
            _conventionMock = new Mock<IMigrationConventions>(MockBehavior.Loose);
            _processorMock = new Mock<IMigrationProcessor>(MockBehavior.Loose);
            _loaderMock = new Mock<IMigrationLoader>(MockBehavior.Loose);

            _vrunner = new MigrationVersionRunner(_conventionMock.Object, _processorMock.Object, _loaderMock.Object);
        }
        public void CanLoadVersion()
        {
            ExecuteWithSupportedProcessors(processor =>
                {
                    var runner = new MigrationVersionRunner(_conventions, processor, new MigrationLoader(_conventions), typeof(MigrationVersionRunnerTests).Assembly, typeof(TestMigration).Namespace);

                    runner.VersionInfo.ShouldNotBeNull();
                });
        }
        private void ExecuteMigrations()
        {
            if (!Path.IsPathRooted(TargetAssembly))
                TargetAssembly = Path.GetFullPath(TargetAssembly);

            Assembly assembly = Assembly.LoadFile(TargetAssembly);
            var runner = new MigrationVersionRunner(new MigrationConventions(), Processor, new MigrationLoader(new MigrationConventions()), assembly, Namespace);
            new TaskExecutor(runner, Version, Steps).Execute(Task);
        }
        public void CanLoadMigrations()
        {
            ExecuteWithSupportedProcessors(processor =>
                {
                    var runner = new MigrationVersionRunner(_conventions, processor, new MigrationLoader(_conventions), typeof(MigrationVersionRunnerTests).Assembly, typeof(TestMigration).Namespace, new TextWriterAnnouncer(System.Console.Out));

                    runner.Migrations.ShouldNotBeNull();
                });
        }
Exemplo n.º 5
0
        private void EnsureMigration()
        {
            var connection = new System.Data.SqlClient.SqlConnection(connectionString);
            connection.Open();
            var processor = new SqlServerProcessor(connection, new SqlServer2000Generator(),
                new TextWriterAnnouncer(System.Console.Out), new ProcessorOptions());
            var conventions = new MigrationConventions();
            var versionRunner = new FluentMigrator.Runner.MigrationVersionRunner(conventions, processor,
                new MigrationLoader(conventions), new NullAnnouncer());
            //var runner = new MigrationRunner(conventions, processor, new TextWriterAnnouncer(System.Console.Out), new StopWatch());
            //runner.Up(new TestCreateAndDropTableMigration());
            versionRunner.MigrateUp();

            versionRunner = null;
            connection = null;
        }
Exemplo n.º 6
0
        public void RunMigration()
        {
            if (!File.Exists(DbFile))
                System.Data.SQLite.SQLiteConnection.CreateFile(DbFile);

            //run migration
            using (SQLiteConnection connection = new SQLiteConnection(ConnectionString))
            {
                var conventions = new MigrationConventions();
                connection.Open();
                var processor = new FluentMigrator.Runner.Processors.Sqlite.SqliteProcessor(connection, new SqliteGenerator());
                var runner = new MigrationVersionRunner(conventions, processor, new MigrationLoader(conventions), typeof(SparkExampleWeb.Models.User));

                //upgrade to latest
                runner.UpgradeToLatest(false);
            }
        }
        public void CanMigrateASpecificVersion()
        {
            ExecuteWithSupportedProcessors(processor =>
                {
                    var runner = new MigrationVersionRunner(_conventions, processor, new MigrationLoader(_conventions), typeof(MigrationVersionRunnerTests).Assembly, "FluentMigrator.Tests.Integration.Migrations", new TextWriterAnnouncer(System.Console.Out), string.Empty);

                    runner.MigrateUp(1);

                    runner.VersionInfo.HasAppliedMigration(1).ShouldBeTrue();
                    processor.TableExists("Users").ShouldBeTrue();

                    runner.Rollback(1);

                    runner.VersionInfo.HasAppliedMigration(1).ShouldBeFalse();
                    processor.TableExists("Users").ShouldBeFalse();
                });
        }
        public void CanMigrateASpecificVersionDown()
        {
            ExecuteWithSupportedProcessors(processor =>
            {
                var runner = new MigrationVersionRunner(_conventions, processor, new MigrationLoader(_conventions), typeof(MigrationVersionRunnerTests).Assembly, "FluentMigrator.Tests.Integration.Migrations");

                runner.MigrateUp(1);

                runner.VersionInfo.HasAppliedMigration(1).ShouldBeTrue();
                processor.TableExists("Users").ShouldBeTrue();

                runner.MigrateDown(1);

                runner.VersionInfo.HasAppliedMigration(1).ShouldBeFalse();
                processor.TableExists("Users").ShouldBeFalse();
            });
        }
Exemplo n.º 9
0
        static void MigrateDatabase()
        {
            //make sure the sqlite db file exists
            if (!File.Exists(DbFile))
                System.Data.SQLite.SQLiteConnection.CreateFile(DbFile);

            //run migration
            using (SQLiteConnection connection = new SQLiteConnection(ConnectionString))
            {
                var conventions = new MigrationConventions();
                connection.Open();
                var processor = new FluentMigrator.Runner.Processors.Sqlite.SqliteProcessor(connection, new SqliteGenerator());
                var runner = new MigrationVersionRunner(conventions, processor, new MigrationLoader(conventions));

                //upgrade to latest
                runner.UpgradeToLatest(false);
            }
        }
        private void runMigrationsInNamespace(IMigrationProcessor processor, string @namespace)
        {
            var runner = new MigrationVersionRunner(_conventions, processor, new MigrationLoader(_conventions), typeof(MigrationVersionRunnerTests).Assembly, @namespace);

            runner.MigrateUp();
        }
        public void SqlServerMigrationsAreTransactional()
        {
            var connection = new SqlConnection(sqlServerConnectionString);
            connection.Open();
            var processor = new SqlServerProcessor(connection, new SqlServerGenerator());
            var runner = new MigrationVersionRunner(_conventions, processor, new MigrationLoader(_conventions), typeof(MigrationVersionRunnerTests).Assembly, typeof(InvalidMigration).Namespace);

            try
            {
                runner.MigrateUp();
            }
            catch
            {
            }

            processor.TableExists("Users").ShouldBeFalse();
        }
        public void CanRunMigrations()
        {
            ExecuteWithSupportedProcessors(processor =>
                {
                    var runner = new MigrationVersionRunner(_conventions, processor, new MigrationLoader(_conventions), typeof(MigrationVersionRunnerTests).Assembly, typeof(TestMigration).Namespace);

                    runner.MigrateUp();
                    runner.VersionInfo.HasAppliedMigration(1).ShouldBeTrue();
                    runner.VersionInfo.HasAppliedMigration(2).ShouldBeTrue();
                    runner.VersionInfo.Latest().ShouldBe(2);

                    runner.Rollback(2);
                    runner.VersionInfo.HasAppliedMigration(1).ShouldBeFalse();
                    runner.VersionInfo.HasAppliedMigration(2).ShouldBeFalse();
                    runner.VersionInfo.Latest().ShouldBe(0);

                    runner.RemoveVersionTable();
                });
        }
        private void runMigrationsInNamespace(IMigrationProcessor processor, string @namespace)
        {
            var runner = new MigrationVersionRunner(_conventions, processor, new MigrationLoader(_conventions), typeof(MigrationVersionRunnerTests).Assembly, @namespace, new TextWriterAnnouncer(System.Console.Out));

            runner.MigrateUp();
        }
        public void SqlServerMigrationsAreTransactional()
        {
            var connection = new SqlConnection(IntegrationTestOptions.SqlServer.ConnectionString);
            connection.Open();
            var processor = new SqlServerProcessor(connection, new SqlServer2000Generator(), new TextWriterAnnouncer(System.Console.Out), new ProcessorOptions());
            var runner = new MigrationVersionRunner(_conventions, processor, new MigrationLoader(_conventions), typeof(MigrationVersionRunnerTests).Assembly, typeof(InvalidMigration).Namespace, new TextWriterAnnouncer(System.Console.Out));

            try
            {
                runner.MigrateUp();
            }
            catch
            {
            }

            processor.TableExists("Users").ShouldBeFalse();
        }
        public void SetUp()
        {
            _conventionMock = new Mock<IMigrationConventions>(MockBehavior.Loose);
            _processorMock = new Mock<IMigrationProcessor>(MockBehavior.Loose);
            _loaderMock = new Mock<IMigrationLoader>(MockBehavior.Loose);

            _vrunner = new MigrationVersionRunner(_conventionMock.Object, _processorMock.Object, _loaderMock.Object, new TextWriterAnnouncer(System.Console.Out));
        }
        public void CanMigrateInterleavedMigrations()
        {
            ExecuteWithSupportedProcessors(processor =>
                {
                    runMigrationsInNamespace(processor, "FluentMigrator.Tests.Integration.Migrations.Interleaved.Pass1");
                    runMigrationsInNamespace(processor, "FluentMigrator.Tests.Integration.Migrations.Interleaved.Pass2");
                    runMigrationsInNamespace(processor, "FluentMigrator.Tests.Integration.Migrations.Interleaved.Pass3");

                    processor.TableExists("UserRoles").ShouldBeTrue();
                    processor.TableExists("User").ShouldBeTrue();

                    var runner = new MigrationVersionRunner(_conventions, processor, new MigrationLoader(_conventions), typeof(MigrationVersionRunnerTests).Assembly, "FluentMigrator.Tests.Integration.Migrations.Interleaved.Pass3");

                    runner.VersionInfo.HasAppliedMigration(200909060953).ShouldBeTrue();
                    runner.VersionInfo.HasAppliedMigration(200909060935).ShouldBeTrue();
                    runner.VersionInfo.HasAppliedMigration(200909060930).ShouldBeTrue();

                    runner.VersionInfo.Latest().ShouldBe(200909060953);

                    runner.Rollback(3);

                    processor.TableExists("UserRoles").ShouldBeFalse();
                    processor.TableExists("User").ShouldBeFalse();

                    runner.RemoveVersionTable();
                });
        }
Exemplo n.º 17
0
        /// <summary>Executes sql create database scripts.</summary>
        public void Install()
        {
            IMigrationProcessorFactory processorFactory = ProcessorFactory.GetFactory("SqlServer");
            IMigrationProcessor processor = processorFactory.Create(GetConnectionString());

            MigrationVersionRunner runner = new MigrationVersionRunner(
                new MigrationConventions(),
                processor,
                new MigrationLoader(new MigrationConventions()), typeof(AddTables).Assembly, "Zeus.Installation.Migrations");
            runner.MigrateUp();
        }