示例#1
0
        private static string GetMigrationsToExecute(out MigrationPath migrationsToExecute)
        {
            var path           = TestHelpers.SetupMigrationsForTests(true, Guid.NewGuid());
            var filesToProcess = new FileSelection(path).GetFiles();

            migrationsToExecute = new MigrationPath(filesToProcess);
            return(path);
        }
示例#2
0
        public void verify_tasks_are_ready_for_migration_execution()
        {
            var migrationPath = TestHelpers.SetupMigrationsForTests(true, Guid.NewGuid());

            var filesToProcess      = new FileSelection(migrationPath).GetFiles();
            var migrationsToExecute = new MigrationPath(filesToProcess);

            Assert.True(migrationsToExecute.Ready());

            TestHelpers.TearDownMigrationsTested(migrationPath);
        }
示例#3
0
        public void verify_tasks_are_for_up_migration_when_up_migration_called()
        {
            var path = TestHelpers.SetupMigrationsForTests(true, Guid.NewGuid());

            var filesToProcess      = new FileSelection(path).GetFiles();
            var migrationsToExecute = new MigrationPath(filesToProcess);

            foreach (var migration in migrationsToExecute.Path(Migration.Up))
            {
                Assert.Equal(Migration.Up, migration.MigrationType);
            }

            TestHelpers.TearDownMigrationsTested(path);
        }
示例#4
0
        private MigrationPath _BuildMigrationPathUsingSequentialVersions(IContentMigrator migrator, int fromVersion,
            int toVersion)
        {
            MigrationPath migrationPath = new MigrationPath();

            while (fromVersion != toVersion) {
                IMigrationSegment segment = _FindExactMigration(migrator, fromVersion, fromVersion + 1);
                if (segment == null) return null;

                migrationPath.Add(segment);
                fromVersion++;
            }

            return migrationPath;
        }
示例#5
0
        public void verify_tasks_are_ordered_for_down_migration()
        {
            var path = TestHelpers.SetupMigrationsForTests(true, Guid.NewGuid());

            var filesToProcess      = new FileSelection(path).GetFiles();
            var migrationsToExecute = new MigrationPath(filesToProcess);
            var migrateUpMigrations = migrationsToExecute.Path(Migration.Down);

            foreach (var migration in migrateUpMigrations)
            {
                Assert.Equal(Migration.Down, migration.MigrationType);
            }

            TestHelpers.TearDownMigrationsTested(path);
        }
示例#6
0
        private object _MigrateContent(object content, int contentVersion, int targetVersion, IContentMigrator migrator)
        {
            MigrationPath migrationPath = _BuildMigrationPath(migrator, contentVersion, targetVersion);

            foreach (IMigrationSegment migrationSegment in migrationPath)
            {
                try {
                    content = migrator.MigrateContent(content, migrationSegment.FromVersion, migrationSegment.ToVersion);
                } catch (Exception ex) {
                    throw new Exception("Error when migrating from version " + contentVersion + " to version " + targetVersion, ex);
                }
            }

            return(content);
        }
示例#7
0
        public void verify_tasks_are_ordered_for_up_migration()
        {
            var path = TestHelpers.SetupMigrationsForTests(true, Guid.NewGuid());

            var filesToProcess      = new FileSelection(path).GetFiles();
            var migrationsToExecute = new MigrationPath(filesToProcess);
            var migrateUpMigrations = migrationsToExecute.Path(Migration.Up);

            Assert.Equal("01 05 2001.doing-whatever.up.cql", migrateUpMigrations[0].TaskFile.Name);
            Assert.Equal("01 01 2003.doing-stuff.up.cql", migrateUpMigrations[1].TaskFile.Name);
            Assert.Equal("01 08 2006.doing-something.up.cql", migrateUpMigrations[2].TaskFile.Name);
            Assert.Equal("march 01 2009.doing-other-bits.up.cql", migrateUpMigrations[3].TaskFile.Name);
            Assert.Equal("01 02 2010.doing-more-stuff.up.cql", migrateUpMigrations[4].TaskFile.Name);

            TestHelpers.TearDownMigrationsTested(path);
        }
示例#8
0
        public void verify_migration_execution()
        {
            var path = TestHelpers.SetupMigrationsForTests(true, Guid.NewGuid());

            var filesToProcess      = new FileSelection(path).GetFiles();
            var migrationsToExecute = new MigrationPath(filesToProcess);

            var upResult = migrationsToExecute.Migrate(Migration.Up);

            Assert.True(upResult);

            var downResult = migrationsToExecute.Migrate(Migration.Down);

            Assert.True(downResult);

            TestHelpers.TearDownMigrationsTested(path);
        }
示例#9
0
文件: Schema.cs 项目: devlaf/carver
        public static void BuildDatabaseSchema(IDbConnection connection)
        {
            connection.Execute(sql_m0_migrations_create);

            var executedMigrations = connection.Query <string>(@"SELECT name FROM migrations");

            foreach (var unExecutedMigration in MigrationPath.Where(x => !executedMigrations.Contains(x.Key)))
            {
                foreach (var command in unExecutedMigration.Value)
                {
                    connection.Execute(command);
                }

                connection.Execute(@"INSERT INTO migrations (name, execution_date) VALUES (@Name, CURRENT_TIMESTAMP)",
                                   new { Name = unExecutedMigration.Key });
            }
        }
示例#10
0
        private MigrationPath _BuildMigrationPathUsingSequentialVersions(IContentMigrator migrator, int fromVersion, int toVersion)
        {
            MigrationPath migrationPath = new MigrationPath();

            while (fromVersion != toVersion)
            {
                IMigrationSegment segment = _FindExactMigration(migrator, fromVersion, fromVersion + 1);
                if (segment == null)
                {
                    return(null);
                }

                migrationPath.Add(segment);
                fromVersion++;
            }

            return(migrationPath);
        }