Exemple #1
0
        public void MigrateDatabase()
        {
            // See http://stackoverflow.com/questions/7574417/is-it-possible-to-use-fluent-migrator-in-application-start

            // var announcer = new NullAnnouncer();
            var announcer = new FluentMigrator.Runner.Announcers.TextWriterAnnouncer(s => System.Diagnostics.Debug.WriteLine(s));
            var assembly  = Assembly.GetExecutingAssembly();

            var migrationContext = new FluentMigrator.Runner.Initialization.RunnerContext(announcer)
            {
                Namespace             = "Majorsilence.Vpn.Logic.Migrations",
                TransactionPerSession = true
            };

            var options = new FluentMigrator.Runner.Processors.ProcessorOptions()
            {
                PreviewOnly = false, // set to true to see the SQL
                Timeout     = TimeSpan.FromSeconds(60)
            };

            var factory   = new FluentMigrator.Runner.Processors.MySql.MySql5ProcessorFactory();
            var processor = factory.Create(InitializeSettings.DbFactory.ConnectionString, announcer, options);
            var runner    = new FluentMigrator.Runner.MigrationRunner(assembly, migrationContext, processor);

            runner.MigrateUp(true);
        }
        #pragma warning disable 0612
        public Migrator(string connectionString)
        {
            var announcer = new ConsoleAnnouncer()
            {
                ShowSql = true,
            };

            var options = new ProcessorOptions()
            {
                ConnectionString = connectionString,
            };

            var factory   = new FluentMigrator.Runner.Processors.MySql.MySql5ProcessorFactory();
            var processor = factory.Create(connectionString, announcer, options);

            var context = new RunnerContext(announcer)
            {
                AllowBreakingChange = true,
            };

            _runner = new MigrationRunner(
                typeof(Migrator).Assembly,
                context,
                processor);
        }