Пример #1
0
        public static void MigrateToLatest(string connectionString, string migrationAssemblyName)
        {
            var assembly = Assembly.Load(new AssemblyName(migrationAssemblyName));

            var migrationContext = new RunnerContext(Announcer)
            {
                Namespace = migrationAssemblyName + ".Migrations"
            };

            var options = new ProcessorOptions {
                PreviewOnly = false, Timeout = DefaultTimeout
            };
            var factory   = new SqlServer2008ProcessorFactory();
            var processor = factory.Create(connectionString, Announcer, options);
            var runner    = new MigrationRunner(assembly, migrationContext, processor);

            foreach (var a in runner.MigrationAssemblies.Assemblies)
            {
                RunScriptGroup(ScriptRunningGroup.PreMigrationScript, a, processor);
            }

            runner.MigrateUp(true);

            foreach (var a in runner.MigrationAssemblies.Assemblies)
            {
                RunScriptGroup(ScriptRunningGroup.PostMigrationScript, a, processor);
            }
        }
Пример #2
0
        public void Migrate(Action <IMigrationRunner> runnerAction)
        {
            var options = new MigrationOptions
            {
                PreviewOnly = false,
                Timeout     = 0
            };

            var factory          = new SqlServer2008ProcessorFactory();
            var announer         = new TextWriterAnnouncer(s => System.Diagnostics.Debug.WriteLine(s));
            var migrationContext = new RunnerContext(announer);
            var processor        = factory.Create(this.connectionString, announer, options);
            var runner           = new MigrationRunner(Assembly.GetExecutingAssembly(), migrationContext, processor);

            runnerAction(runner);
        }
Пример #3
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();
            }
        }
Пример #4
0
        private static MigrationRunner CreateMigrationRunner(string connectionString)
        {
            var announcer = new TextWriterAnnouncer(s => Debug.WriteLine(s));
            var assembly  = Assembly.GetExecutingAssembly();

            var migrationContext = new RunnerContext(announcer)
            {
                Namespace = "Migrator.Migrations"
            };

            var options = new MigrationOptions {
                PreviewOnly = false, Timeout = 60
            };
            var factory   = new SqlServer2008ProcessorFactory();
            var processor = factory.Create(connectionString, announcer, options);
            var runner    = new MigrationRunner(assembly, migrationContext, processor);

            return(runner);
        }
Пример #5
0
        public void Migrate(Action <IMigrationRunner> runnerAction)
        {
            //using (var announcer = new NullAnnouncer())
            var announcer        = new TextWriterAnnouncer(s => System.Diagnostics.Debug.WriteLine(s));
            var migrationContext = new RunnerContext(announcer)
            {
#if DEBUG
                // will create testdata
                Profile = "development"
#endif
            };
            var options = new MigrationOptions {
                PreviewOnly = false, Timeout = 0
            };
            var factory   = new SqlServer2008ProcessorFactory();
            var assembly  = Assembly.GetExecutingAssembly();
            var processor = factory.Create(_connectionString, announcer, options);
            var runner    = new MigrationRunner(assembly, migrationContext, processor);

            runnerAction(runner);
        }
Пример #6
0
        private static void RunMigration()
        {
            var announcer = new TextWriterAnnouncer(Console.WriteLine)
            {
                ShowSql = true
            };

            var assembly         = Assembly.GetAssembly(typeof(Program));
            var migrationContext = new RunnerContext(announcer);

            var options = new ProcessorOptions
            {
                PreviewOnly = false,  // set to true to see the SQL
                Timeout     = 60
            };
            var factory = new SqlServer2008ProcessorFactory();
            IMigrationProcessor processor = factory.Create(ConnectionString, announcer, options);
            var runner = new MigrationRunner(assembly, migrationContext, processor);

            runner.MigrateUp(true);

            // Or go back down
            //runner.MigrateDown(0);
        }