private static MigrationRunner GetMigrationRunner(StringWriter sw, MigrateDatabaseContext dbItem, Assembly migrationAssembly)
        {
            Announcer announcer = new TextWriterWithGoAnnouncer(sw)
            {
                ShowSql = true
            };

            var runnerCtx = new RunnerContext(announcer)
            {
                ApplicationContext = dbItem
            };

            if (string.IsNullOrWhiteSpace(dbItem.CurrentDatabaseNamespace))
            {
                throw new ArgumentNullException(nameof(dbItem.CurrentDatabaseNamespace), "<DatabaseNamespace> should not null or empty");
            }

            runnerCtx.Namespace = dbItem.CurrentDatabaseNamespace;

            var options = new ProcessorOptions {
                PreviewOnly = false, Timeout = dbItem.ConnectionTimeout
            };
            var factory = new FluentMigrator.Runner.Processors.SqlServer.SqlServer2014ProcessorFactory();

            using (var processor = factory.Create(dbItem.ConnectionString, announcer, options))
            {
                return(new MigrationRunner(migrationAssembly, runnerCtx, processor));
            }
        }
Пример #2
0
        public void MigrateToLatest()
        {
            try
            {
                var connectionString = _settingsService.ConnectionString(DatabaseContext.DefaultConnectionString);

                var announcer = new NullAnnouncer();

                var assembly = Assembly.GetExecutingAssembly();

                var migrationContext = new RunnerContext(announcer)
                {
                    NestedNamespaces = true,
                    Namespace        = "Database.Migrations",
                    Connection       = connectionString
                };
                var options = new MigrationOptions {
                    PreviewOnly = false, Timeout = 60
                };
                var factory = new FluentMigrator.Runner.Processors.SqlServer.SqlServer2014ProcessorFactory();
                using (var processor = factory.Create(connectionString, announcer, options))
                {
                    var runner = new MigrationRunner(assembly, migrationContext, processor);
                    runner.MigrateUp(true);
                }
            }
            catch (Exception e)
            {
            }
        }
        /// <summary>
        /// Migrate the database to the latest version.
        /// </summary>
        /// <param name="connectionStringName">The name of the connection string.</param>
        public static void MigrateToLatest(string connectionStringName)
        {
            var announcer = new NullAnnouncer();
            var assembly = Assembly.GetAssembly(typeof(CreateCountriesTable));

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

            var options = new MigrationOptions { PreviewOnly = false, Timeout = 60 };
            var factory = new FluentMigrator.Runner.Processors.SqlServer.SqlServer2014ProcessorFactory();
            using (var processor = factory.Create(connectionStringName, announcer, options))
            {
                var runner = new MigrationRunner(assembly, migrationContext, processor);
                runner.MigrateUp(true);
            }
        }
        public static void MigrateToLatest(string connectionString)
        {
            // var announcer = new NullAnnouncer();
            var announcer = new TextWriterAnnouncer(s => System.Diagnostics.Debug.WriteLine(s));
            var assembly = Assembly.GetExecutingAssembly();

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

            var options = new MigrationOptions { PreviewOnly = false, Timeout = 60 };
            var factory = new FluentMigrator.Runner.Processors.SqlServer.SqlServer2014ProcessorFactory();
            using (var processor = factory.Create(connectionString, announcer, options))
            {
                var runner = new MigrationRunner(assembly, migrationContext, processor);
                runner.MigrateUp(true);
            }
        }
        /// <summary>
        /// Migrate the database to the latest version.
        /// </summary>
        /// <param name="connectionStringName">The name of the connection string.</param>
        public static void MigrateToLatest(string connectionStringName)
        {
            var announcer = new NullAnnouncer();
            var assembly  = Assembly.GetAssembly(typeof(CreateCountriesTable));

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

            var options = new MigrationOptions {
                PreviewOnly = false, Timeout = 60
            };
            var factory = new FluentMigrator.Runner.Processors.SqlServer.SqlServer2014ProcessorFactory();

            using (var processor = factory.Create(connectionStringName, announcer, options))
            {
                var runner = new MigrationRunner(assembly, migrationContext, processor);
                runner.MigrateUp(true);
            }
        }
Пример #6
0
        public static void MigrateToLatest(string connectionString, Type sourceNamespace)
        {
            var announcer = new TextWriterAnnouncer(s => System.Diagnostics.Debug.WriteLine(s));
            var assembly  = Assembly.GetAssembly(sourceNamespace);

            var migrationContext = new RunnerContext(announcer)
            {
                Namespace = sourceNamespace.Namespace
            };

            var options = new MigrationOptions {
                PreviewOnly = false, Timeout = 60
            };
            var factory =
                new FluentMigrator.Runner.Processors.SqlServer.SqlServer2014ProcessorFactory();

            using (var processor = factory.Create(connectionString, announcer, options))
            {
                var runner = new MigrationRunner(assembly, migrationContext, processor);
                runner.MigrateUp(true);
            }
        }