public IMigrationProcessor CreateMigrationProcessor(RunnerContext context, IDbConnection connection)
        {
            try
            {
                if (connection.State != ConnectionState.Open)
                    connection.Open();

                IMigrationGenerator migrationGenerator;
                using (var command = new SqlCommand("SELECT CAST(LEFT(CAST(SERVERPROPERTY('productversion') AS varchar(50)),CHARINDEX('.',CAST(SERVERPROPERTY('productversion') AS varchar(50)))-1)AS int)", connection as SqlConnection))
                {
                    var version = (int)command.ExecuteScalar();
                    switch (version)
                    {
                        case 9:
                            migrationGenerator = new SqlServer2005Generator();
                            break;

                        case 10:
                            migrationGenerator = new SqlServer2008Generator();
                            break;

                        default:
                            migrationGenerator = new SqlServer2012Generator();
                            //                            throw new Exception(string.Format("无法识别的数据库版本:{0}。", version));
                            break;
                    }
                }

                return new SqlServerProcessor(
                                        connection
                                        , migrationGenerator
                                        , context.Announcer,
                                        new ProcessorOptions
                                        {
                                            PreviewOnly = context.PreviewOnly,
                                            ProviderSwitches = context.ProviderSwitches,
                                            Timeout = context.Timeout
                                        }
                                        , new SqlServerDbFactory());
            }
            finally
            {
                if (connection.State == ConnectionState.Open)
                    connection.Close();
            }
        }
 public void Setup()
 {
     generator = new SqlServer2005Generator();
 }
Пример #3
0
        private static void ExecuteWithSqlServer(IntegrationTestOptions.DatabaseServerOptions serverOptions, TextWriterAnnouncer announcer, SqlServer2005Generator generator, Action<IMigrationProcessor> test, bool tryRollback)
        {
            using (var connection = new SqlConnection(serverOptions.ConnectionString))
            {
                var processor = new SqlServerProcessor(connection, generator, announcer, new ProcessorOptions(), new SqlServerDbFactory());
                test(processor);

                if (tryRollback && !processor.WasCommitted)
                {
                    processor.RollbackTransaction();
                }
            }
        }
Пример #4
0
        protected static void ExecuteWithSqlServer2005(Action<IMigrationProcessor> test, bool tryRollback)
        {
            var serverOptions = IntegrationTestOptions.SqlServer2005;

            if (!serverOptions.IsEnabled)
                return;

            var announcer = new TextWriterAnnouncer(System.Console.Out);
            announcer.Heading("Testing Migration against MS SQL Server 2005");
            var generator = new SqlServer2005Generator();

            ExecuteWithSqlServer(serverOptions, announcer, generator, test, tryRollback);
        }