Ejemplo n.º 1
0
        public void MigrateToLatest()
        {
            var announcer = new TextWriterAnnouncer(s => SharpStarLogger.DefaultLogger.Debug(s));
            var assembly  = Assembly.GetExecutingAssembly();

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

            var options = new MigrationOptions {
                PreviewOnly = false, Timeout = 60
            };

            ReflectionBasedDbFactory factory;

            if (MonoHelper.IsRunningOnMono())
            {
                factory = new MonoSQLiteDbFactory();
            }
            else
            {
                factory = new SqliteDbFactory();
            }

            var connection = factory.CreateConnection(_config.GetProperty(NHibernate.Cfg.Environment.ConnectionString));

            var processor = new SqliteProcessor(connection, new SqliteGenerator(), announcer, options, factory);
            var runner    = new MigrationRunner(assembly, migrationContext, processor);

            runner.MigrateUp(true);
        }
Ejemplo n.º 2
0
        public AutoMigration(IServiceProvider serviceProvider, IHostEnvironment env, MigrationOptions migrationOptions)
        {
            _logger = serviceProvider.GetService <ILogger <AutoMigration> >();
            _assemblyLoadContext   = new MigrationAssemblyLoadContext();
            this._migrationOptions = migrationOptions;
            _serviceProvider       = serviceProvider;

            _env         = env;
            daoFactories = _serviceProvider.GetServices <IDaoFactory>();
            foreach (var item in daoFactories)
            {
                var factory    = item as EFCoreDaoFactory;
                var extensions = factory.dbContextOptions.Extensions;
                var extension  = extensions.FirstOrDefault(e => typeof(RelationalOptionsExtension).IsAssignableFrom(e.GetType()));
                if (extension == null)
                {
                    throw new ServiceFrameworkException($"DbContextOptions error,could not find RelationalOptionsExtension for {factory.FactoryName}");
                }
                if (!_providerAssemblies.ContainsKey(factory.FactoryName))
                {
                    _providerAssemblies.Add(factory.FactoryName, new List <Assembly>());
                }
                _providerAssemblies[factory.FactoryName].Add(extension.GetType().Assembly);
            }
        }
Ejemplo n.º 3
0
        private static void ScriptTo(string dir, long timestamp = -1)
        {
            Directory.CreateDirectory(dir);
            var options = new MigrationOptions();

            options.OnlyScriptSqlTo(dir);
            var             migrator   = new Migrator(_connectionString, DbPlatform.SqlServer2014, options);
            IMigrationBatch migrations = null;

            if (timestamp != -1)
            {
                migrations = migrator.FetchMigrationsTo(_assembly, timestamp);
            }
            else
            {
                migrations = migrator.FetchMigrations(_assembly);
            }
            if (migrations.Steps.First().Direction == MigrationDirection.Down)
            {
                Console.WriteLine("Migration direction = down");
            }
            Console.WriteLine($"{migrations.Steps.Count} pending migrations");
            Console.WriteLine("Writing migration SQL scripts to {dir}");
            migrations.Execute();
            Console.WriteLine("Done");
        }
Ejemplo n.º 4
0
        public void Migrate(Action <IMigrationRunner> runnerAction)
        {
            var before = Stopwatch.StartNew();

            if (ApplicationConfiguration.IsLocal() && !ApplicationConfiguration.IsLocalHostSWDB())
            {
                Log.Debug("Ignoring Migration on remoteDB");
                //avoid misconfiguration to change the schema of a remote database
                return;
            }

            var options = new MigrationOptions {
                PreviewOnly = false, Timeout = 0
            };
            var factory  = GetFactory();
            var assembly = Assembly.GetExecutingAssembly();

            //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 processor = factory.Create(connectionString, announcer, options);
            var runner    = new MigrationRunner(assembly, migrationContext, processor);

            runnerAction(runner);
            Log.Info(String.Format("Migration execution finished in {0}", LoggingUtil.MsDelta(before)));
        }
Ejemplo n.º 5
0
        private void Do(Action <IMigrationRunner> runnerAct)
        {
            var dir = new DirectoryInfo(outputDir);

            if (!dir.Exists)
            {
                dir.Create();
            }

            var filename = Path.Combine(outputDir, string.Format("migrated-{0:yyyy-MM-dd-HH-mm-ss}.sql", DateTime.Now));

            using (var fs = File.CreateText(filename))
            {
                var announcer = new TextWriterAnnouncer(fs);
                var assembly  = typeof(CreateClientDb).Assembly;

                var migrationContext = MakeContext(announcer);
                var options          = new MigrationOptions {
                    PreviewOnly = false, Timeout = 15
                };
                var processor = MakeProcessor(announcer, options);
                var runner    = new MigrationRunner(assembly, migrationContext, processor);
                runnerAct(runner);
            }

            if (new FileInfo(filename).Length == 0)
            {
                File.Delete(filename);
            }
        }
Ejemplo n.º 6
0
        public void Can_get_migration_id_from_migration_and_correct_leading_or_multiple_underscores()
        {
            var options = new MigrationOptions();
            var id      = options.Conventions.MigrationDocumentId(new _has_problems__with_underscores___(), '/');

            id.Should().Be("migrationrecord/has/problems/with/underscores/5");
        }
Ejemplo n.º 7
0
        private MigrationOptions GetMigrationOptions()
        {
            var options = new MigrationOptions();

            options.Assemblies.Add(Assembly.GetExecutingAssembly());
            return(options);
        }
Ejemplo n.º 8
0
        public void Can_get_migration_id_from_migration()
        {
            var options = new MigrationOptions();
            var id      = options.Conventions.MigrationDocumentId(new First_Migration(), '/');

            id.Should().Be("migrationrecord/first/migration/1");
        }
Ejemplo n.º 9
0
        public void Can_change_migration_document_seperator_to_dash()
        {
            var options = new MigrationOptions();

            options.Conventions.MigrationDocumentId(new First_Migration(), '-')
            .Should().Be("migrationrecord-first-migration-1");
        }
Ejemplo n.º 10
0
        public void Default_resolver_should_be_DefaultMigrationResolver()
        {
            var options = new MigrationOptions();

            options.MigrationResolver.Should().NotBeNull();
            options.MigrationResolver.Should().BeOfType <DefaultMigrationResolver>();
        }
Ejemplo n.º 11
0
        private void MigrateButton_Click(object sender, EventArgs e)
        {
            MigrationOptions options;

            Uri.TryCreate(svnBranchUrlComboBox.Text, UriKind.Absolute, out Uri svnUri);

            options = new MigrationOptions
            {
                SvnUri                = svnUri,
                RepositoryPath        = gitRepositoryPathTextBox.Text,
                WorkingPath           = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()),
                Authors               = this.GetAuthorMapping(),
                Revisions             = this.GetOrderedRevisions(),
                UseExistingRepository = useExistingRepositoryCheckBox.Checked
            };

            if (this.ValidateOptions(options))
            {
                this.PrepareProgressUi("Migrating...");

                tabList.SelectedPage = gitTabListPage;

                migrateBackgroundWorker.RunWorkerAsync(options);
            }
        }
        public static void MigrateUp(string connectionString, string MigrationNamespace, long?toVersion = null)
        {
            var announcer        = new TextWriterAnnouncer(s => System.Diagnostics.Debug.WriteLine(s));
            var assembly         = Assembly.GetExecutingAssembly();
            var migrationContext = new RunnerContext(announcer)
            {
                Namespace = MigrationNamespace
            };
            var options = new MigrationOptions {
                PreviewOnly = false, Timeout = 60
            };
            var factory = new FluentMigrator.Runner.Processors.Postgres.PostgresProcessorFactory();

            using (var processor = factory.Create(connectionString, announcer, options))
            {
                var runner = new MigrationRunner(assembly, migrationContext, processor);
                if (toVersion == null)
                {
                    runner.MigrateUp(true);
                }
                else
                {
                    runner.MigrateUp(toVersion.Value);
                }
            }
        }
Ejemplo n.º 13
0
        public static void MigrateToLatest(string connectionString, string clientId, string certThumbPrint, string authority)
        {
            var announcer = new TextWriterAnnouncer(s => {
                System.Console.WriteLine(s);
                System.Diagnostics.Debug.WriteLine(s);
            });
            var assembly = Assembly.Load("MyAppMigrations");

            var migrationContext = new RunnerContext(announcer)
            {
                Namespace = "MyAppMigrations"
            };

            var options = new MigrationOptions {
                PreviewOnly = false, Timeout = 60
            };
            var factory = new AzureSqlProcessorFactory(clientId, certThumbPrint, authority);

            using (var processor = factory.Create(connectionString, announcer, options))
            {
                var runner = new MigrationRunner(assembly, migrationContext, processor);
                runner.ListMigrations();
                runner.MigrateUp(true);
            }
        }
Ejemplo n.º 14
0
        public Migration(MigrationOptions migrationOptions, ILogger logger)
        {
            _options = migrationOptions;
            _logger  = logger;

            if (migrationOptions.IgnoreFile != null)
            {
                if (!migrationOptions.IgnoreFile.Contains(":"))
                {
                    string basePath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
                    migrationOptions.IgnoreFile = Path.Combine(basePath, migrationOptions.IgnoreFile);
                }
                try
                {
                    migrationOptions.IgnoreTableList = File.ReadAllLines(migrationOptions.IgnoreFile);
                    logger.Log("Reading ignore file: " + migrationOptions.IgnoreFile + ". " + migrationOptions.IgnoreTableList.Length + " lines found.", EventType.Info);
                }
                catch (Exception ex) { logger.Log("Error reading ignore file: " + migrationOptions.IgnoreFile + ". " + ex.Message, EventType.Error); }
            }

            if (migrationOptions.OutputFile != null)
            {
                if (!migrationOptions.OutputFile.Contains(":"))
                {
                    string basePath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
                    migrationOptions.OutputFile = Path.Combine(basePath, migrationOptions.OutputFile);
                }
            }
        }
        /// <summary>
        ///     Creates a migration runner for the specified migration assembly against the given connection string.
        /// </summary>
        /// <param name="assembly">The assembly with migrations.</param>
        /// <param name="connectionString">The connection string of the database to migrate.</param>
        /// <param name="outputWriter">
        ///     The writer where output messages should be written (optional - defaults to
        ///     System.Diagnostics.Debug output).
        /// </param>
        /// <returns>A Fluent MigrationRunner instance.</returns>
        public static MigrationRunner Create(Assembly assembly, string connectionString, Action <string> outputWriter = null)
        {
            if (assembly == null)
            {
                throw new ArgumentNullException("assembly");
            }
            if (connectionString == null)
            {
                throw new ArgumentNullException("connectionString");
            }
            if (outputWriter == null)
            {
                outputWriter = s => Debug.WriteLine(s);
            }

            var options = new MigrationOptions {
                PreviewOnly = false
            };
            var announcer        = new TextWriterAnnouncer(outputWriter);
            var migrationContext = new RunnerContext(announcer);

            var processorFactory = new SqlServerProcessorFactory();
            var processor        = processorFactory.Create(connectionString, announcer, options);

            var runner = new MigrationRunner(assembly, migrationContext, processor);

            return(runner);
        }
Ejemplo n.º 16
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="runnerAction"></param>
        public void Migrate(Action <IMigrationRunner> runnerAction)
        {
            var announcer = new TextWriterAnnouncer(s => System.Diagnostics.Debug.WriteLine(s));

            var options = new MigrationOptions {
                PreviewOnly = false, Timeout = 7200
            };

            string dbType = "";

            if (_dbType.Contains("MySql"))
            {
                dbType = "MySql";
            }
            else if (_dbType.Contains("SqlClient"))
            {
                dbType = "SqlServer";
            }
            else if (_dbType.Contains("SQLite"))
            {
                dbType = "SQLite";
            }

            var factory = new FluentMigrator.Runner.Processors.MigrationProcessorFactoryProvider().GetFactory(dbType);

            //var assembly = Assembly.GetExecutingAssembly();


            var migrationContext = new RunnerContext(announcer);
            var processor        = factory.Create(_connectionString, announcer, options);
            var runner           = new MigrationRunner(_assembly, migrationContext, processor);

            runnerAction(runner);
        }
Ejemplo n.º 17
0
        public static void MigrateDown(string connectionString, long?migrationId)
        {
            var announcer = GetAnnouncer();
            var assembly  = Assembly.GetAssembly(typeof(Seed));

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

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

            using (var processor = factory.Create(connectionString, announcer, options))
            {
                var runner = new MigrationRunner(assembly, migrationContext, processor);
                if (migrationId.HasValue)
                {
                    runner.RollbackToVersion(migrationId.Value);
                }
                else
                {
                    runner.Rollback(int.MaxValue);
                }
            }
        }
Ejemplo n.º 18
0
        private Migrator GetMigrator()
        {
            var options = new MigrationOptions();

            options.SupportedProviders.Set(new [] { ProviderNames.SqlServer2008 });
            return(new Migrator(_connectionString, ProviderNames.SqlServer2008, options));
        }
Ejemplo n.º 19
0
        public static void RunMigrations(string connectionString, string migration)
        {
            // var announcer = new NullAnnouncer();
            var announcer = new TextWriterAnnouncer(s => System.Diagnostics.Debug.WriteLine(s));
            var assembly = Assembly.GetExecutingAssembly();

            var migrationContext = new RunnerContext(announcer)
            {
                Namespace = "Azimuth.Migrations",
                WorkingDirectory = "Migrations"
            };

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

            switch (migration)
            {
                case "Run migrations":
                    runner.MigrateUp(true);
                    break;
                case "Drop all tables":
                    runner.RollbackToVersion(201408091845);
                    runner.Rollback(1);
                    break;
            }
        }
Ejemplo n.º 20
0
 public void VerityIsWarningSuppressedIsFalseByDefault()
 {
     var options = new MigrationOptions();
     Assert.IsFalse(options.IsWarningSuppressed(ProviderName, Type, 0, 0));
     Assert.IsFalse(options.IsWarningSuppressed(ProviderName, Type, 1, 0));
     Assert.IsFalse(options.IsWarningSuppressed(ProviderName, Type, 1, 1));
 }
Ejemplo n.º 21
0
        public static void AddNetCleanDbContext <T>(
            this IServiceCollection services,
            Action <DbContextOptionsBuilder> options,
            MigrationOptions migration = MigrationOptions.Migrate) where T : DbContext
        {
            services.AddDbContextPool <T>(options);

            services.AddScoped <DbContext>(provider => provider.GetRequiredService <T>());

            services.AddScoped <IUnitOfWork>(provider => provider.GetRequiredService <T>() as IUnitOfWork);

            switch (migration)
            {
            case MigrationOptions.EnsureDeleteAndCreated:
            {
                services.BuildServiceProvider().GetRequiredService <T>().Database.EnsureDeleted();
                services.BuildServiceProvider().GetRequiredService <T>().Database.EnsureCreated();
            }
            break;

            case MigrationOptions.EnsureCreated:
                services.BuildServiceProvider().GetRequiredService <T>().Database.EnsureCreated();
                break;

            case MigrationOptions.Migrate:
                services.BuildServiceProvider().GetRequiredService <T>().Database.Migrate();
                break;

            default:
                break;
            }
        }
Ejemplo n.º 22
0
 public void VerifyIsWarningSuppressedIsFalseByDefault()
 {
     var options = new MigrationOptions();
     Assert.IsFalse(options.IsWarningSuppressed(Platform, Type, 0, 0));
     Assert.IsFalse(options.IsWarningSuppressed(Platform, Type, 1, 0));
     Assert.IsFalse(options.IsWarningSuppressed(Platform, Type, 1, 1));
 }
Ejemplo n.º 23
0
        private static void Validate(IMigrationReport report, out string errors, out string warnings)
        {
            IEnumerable <ProviderInfo> providerInfos;
            MigrationOptions           options = GetOptions(out providerInfos);

            Validate(providerInfos, options, report, out errors, out warnings);
        }
Ejemplo n.º 24
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)
            {
            }
        }
Ejemplo n.º 25
0
 public static void AssertNotFrozen(this MigrationOptions opts, string action)
 {
     if (opts.Freeze)
     {
         throw new InvalidOperationException($"Can't {action}, schema is frozen");
     }
 }
Ejemplo n.º 26
0
        public void VerifyIsWarningSuppressedIsFalseByDefault()
        {
            var options = new MigrationOptions();

            Assert.IsFalse(options.IsWarningSuppressed(Platform, Type, 0, 0));
            Assert.IsFalse(options.IsWarningSuppressed(Platform, Type, 1, 0));
            Assert.IsFalse(options.IsWarningSuppressed(Platform, Type, 1, 1));
        }
Ejemplo n.º 27
0
 public void VerifySuppressWarningWithSize()
 {
     var options = new MigrationOptions();
     options.SuppressWarning(Platform, Type, SuppressCondition.WhenSpecifiedWithSize);
     Assert.IsFalse(options.IsWarningSuppressed(Platform, Type, null, null));
     Assert.IsTrue(options.IsWarningSuppressed(Platform, Type, 1, null));
     Assert.IsFalse(options.IsWarningSuppressed(Platform, Type, 1, 1));
 }
Ejemplo n.º 28
0
 public void VerifySuppressWarningAlways()
 {
     var options = new MigrationOptions();
     options.SuppressWarning(Platform, Type, SuppressCondition.Always);
     Assert.IsTrue(options.IsWarningSuppressed(Platform, Type, null, null));
     Assert.IsTrue(options.IsWarningSuppressed(Platform, Type, 1, null));
     Assert.IsTrue(options.IsWarningSuppressed(Platform, Type, 1, 1));
 }
Ejemplo n.º 29
0
        /// <summary>
        /// Adds configuration for <see cref="MigrationsMiddleware"/> into <see cref="IServiceCollection"/>.
        /// </summary>
        /// <param name="setupAction">Setup migration options.</param>
        /// <returns>This instance of <see cref="KormBuilder"/>.</returns>
        public KormBuilder AddKormMigrations(Action <MigrationOptions> setupAction = null)
        {
            Services.AddMemoryCache();
            MigrationOptions options = SetupMigrationOptions(setupAction);

            _migrationsRunner = new MigrationsRunner(ConnectionSettings.ConnectionString, options);
            return(this);
        }
Ejemplo n.º 30
0
 public static void AssertColumnDeleteAllowed(this MigrationOptions opts, string table, string column, string field)
 {
     opts.AssertNotFrozen($"change '{field}' of '{column}' of '{table}'");
     if (!opts.AllowDataloss)
     {
         throw new InvalidOperationException($"Can't migrate column '{column}' of '{table}', {field} can't be changed without dataloss");
     }
 }
Ejemplo n.º 31
0
 public void VerifySuppressWarningWithSizeAndScale()
 {
     var options = new MigrationOptions();
     options.SuppressWarning(ProviderName, Type, SuppressCondition.WhenSpecifiedWithSizeAndScale);
     Assert.IsFalse(options.IsWarningSuppressed(ProviderName, Type, 0, 0));
     Assert.IsFalse(options.IsWarningSuppressed(ProviderName, Type, 1, 0));
     Assert.IsTrue(options.IsWarningSuppressed(ProviderName, Type, 1, 1));
 }
Ejemplo n.º 32
0
        public void VerityIsWarningSuppressedIsFalseByDefault()
        {
            var options = new MigrationOptions();

            Assert.IsFalse(options.IsWarningSuppressed(ProviderName, Type, 0, 0));
            Assert.IsFalse(options.IsWarningSuppressed(ProviderName, Type, 1, 0));
            Assert.IsFalse(options.IsWarningSuppressed(ProviderName, Type, 1, 1));
        }
Ejemplo n.º 33
0
 public static void AssertColumnDeleteAllowed(this MigrationOptions opts, string table, string column)
 {
     opts.AssertNotFrozen($"delete '{column}' of '{table}'");
     if (!opts.AllowDataloss)
     {
         throw new InvalidOperationException($"Can't delete column '{column}' of '{table}', dataloss is not allowed");
     }
 }
Ejemplo n.º 34
0
 public void VerifySuppressWarningAlways()
 {
     var options = new MigrationOptions();
     options.SuppressWarning(ProviderName, Type, SuppressCondition.Always);
     Assert.IsTrue(options.IsWarningSuppressed(ProviderName, Type, 0, 0));
     Assert.IsTrue(options.IsWarningSuppressed(ProviderName, Type, 1, 0));
     Assert.IsTrue(options.IsWarningSuppressed(ProviderName, Type, 1, 1));
 }
Ejemplo n.º 35
0
        private static void Validate(IEnumerable <ProviderInfo> providerInfos, MigrationOptions options, IMigrationReport report, out string errors, out string warnings)
        {
            var validator = new Validator(providerInfos, options);
            IMigrationReporter reporter = A.Fake <IMigrationReporter>();

            A.CallTo(() => reporter.Report(A <IMigrationContext> ._)).Returns(report);
            IMigrationReporter[] reporters = new[] { reporter };
            validator.Validate(reporters, out errors, out warnings);
        }
Ejemplo n.º 36
0
        public void VerifySuppressWarningWithSizeAndScale()
        {
            var options = new MigrationOptions();

            options.SuppressWarning(ProviderName, Type, SuppressCondition.WhenSpecifiedWithSizeAndScale);
            Assert.IsFalse(options.IsWarningSuppressed(ProviderName, Type, 0, 0));
            Assert.IsFalse(options.IsWarningSuppressed(ProviderName, Type, 1, 0));
            Assert.IsTrue(options.IsWarningSuppressed(ProviderName, Type, 1, 1));
        }
Ejemplo n.º 37
0
 private static void AssertModulesAreNotSelected(MigrationOptions options, params string[] moduleNames)
 {
     foreach (string moduleName in moduleNames)
     {
         var metadata = A.Fake<IMigrationMetadata>();
         A.CallTo(() => metadata.ModuleName).Returns(moduleName);
         Assert.IsFalse(options.MigrationSelector(metadata), "Module '{0}' should not be selected.", moduleName);
     }
 }
Ejemplo n.º 38
0
        private static void Validate(MigrationOptions options, IMigrationReport report, out string errors, out string warnings)
        {
            var validator = new Validator(options);
            IMigrationReporter reporter = MockRepository.GenerateStub <IMigrationReporter>();

            reporter.Expect(r => r.Report(null)).IgnoreArguments().Return(report);
            IMigrationReporter[] reporters = new[] { reporter };
            validator.Validate(reporters, out errors, out warnings);
        }
Ejemplo n.º 39
0
        private static MigrationRunner GetRunner(string connectionString, IMigrationProcessorFactory factory)
        {
            var announcer = new NullAnnouncer();
            var assembly = Assembly.GetExecutingAssembly();
            var migrationContext = new RunnerContext(announcer) { Namespace = "Migrations" };
            var options = new MigrationOptions { PreviewOnly = false, Timeout = 60 };
            var processor = factory.Create(connectionString, announcer, options);

            return new MigrationRunner(assembly, migrationContext, processor);
        }
Ejemplo n.º 40
0
 public void Migrate(Action<IMigrationRunner> runnerAction)
 {
     var options = new MigrationOptions { PreviewOnly = false, Timeout = 0 };
     var factory = new FluentMigrator.Runner.Processors.MigrationProcessorFactoryProvider().GetFactory(_dbType);
     var announcer = new TextWriterAnnouncer(s => System.Diagnostics.Debug.WriteLine(s));
     var migrationContext = new RunnerContext(announcer);
     var processor = factory.Create(_connectionString, announcer, options);
     var runner = new MigrationRunner(_migrationAssembly, migrationContext, processor);
     runnerAction(runner);
 }
Ejemplo n.º 41
0
        public virtual void Setup()
        {
            _options = new MigrationOptions();
            _options.SupportedProviders.Set(new[] { ProviderName }); // avoid validation errors/warnings from other providers

            // initialize IntegrationTestContext
            IProviderMetadata providerMetadata;
            IProvider provider = _options.SupportedProviders.GetProvider(ProviderName, out providerMetadata);
            IntegrationTestContext.Initialize(_options, provider.GetSupportsAttributes());
        }
Ejemplo n.º 42
0
 public void VerifySuppressWarningCombined()
 {
     var options = new MigrationOptions();
     options.SuppressWarning(ProviderName, Type, SuppressCondition.WhenSpecifiedWithoutSize);
     options.SuppressWarning(ProviderName, Type, SuppressCondition.WhenSpecifiedWithSize);
     options.SuppressWarning(ProviderName, Type, SuppressCondition.WhenSpecifiedWithSizeAndScale);
     Assert.IsTrue(options.IsWarningSuppressed(ProviderName, Type, null, null));
     Assert.IsTrue(options.IsWarningSuppressed(ProviderName, Type, 1, null));
     Assert.IsTrue(options.IsWarningSuppressed(ProviderName, Type, 1, 1));
 }
Ejemplo n.º 43
0
 public MigrationBatch(
     IEnumerable<IMigrationStep> upMigrations,
     IEnumerable<IMigrationStep> downMigrations,
     IVersioning versioning,
     MigrationOptions options)
 {
     _upMigrations = upMigrations;
     _downMigrations = downMigrations;
     _versioning = versioning;
     _options = options;
 }
Ejemplo n.º 44
0
 public void Migrate(Action<IMigrationRunner> runnerAction)
 {
     var options = new MigrationOptions { PreviewOnly = false, Timeout = 0 };
     var factory = new FluentMigrator.Runner.Processors.SqlServer.SqlServer2008ProcessorFactory();
     var assembly = Assembly.GetExecutingAssembly();
     var announcer = new TextWriterAnnouncer(s => System.Diagnostics.Debug.WriteLine(s));
     var migrationContext = new RunnerContext(announcer);
     var processor = factory.Create(this._connectionString, announcer, options);
     var runner = new MigrationRunner(assembly, migrationContext, processor);
     runnerAction(runner);
 }
Ejemplo n.º 45
0
 public MigrationBatch(
     IEnumerable<IMigrationStep> migrations,
     IEnumerable<IMigrationMetadata> unidentifiedMigrations,
     IVersioning versioning,
     MigrationOptions options)
 {
     _migrations = migrations;
     _scheduledMigrations = new ReadOnlyCollection<IScheduledMigrationMetadata>(_migrations.Select(s => s.Metadata).ToList());
     _unidentifiedMigrations = new ReadOnlyCollection<IMigrationMetadata>(unidentifiedMigrations.ToList());
     _versioning = versioning;
     _options = options;
 }
        public static void MigrateToLatest()
        {
            var connectionString = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
            var migrationAssembly=  Assembly.GetExecutingAssembly();
            var announcer = new TextWriterAnnouncer(s => System.Diagnostics.Debug.WriteLine(s));
            var migrationContext = new RunnerContext(announcer);
            var factory = new FluentMigrator.Runner.Processors.SqlServer.SqlServer2008ProcessorFactory();
            var options = new MigrationOptions { PreviewOnly = false, Timeout = 0 };
            var processor = factory.Create(connectionString, announcer, options);

            var runner = new MigrationRunner(migrationAssembly, migrationContext, processor);
            runner.MigrateUp();
        }
Ejemplo n.º 47
0
        public void MigrateToLatest()
        {
            var announcer = new TextWriterAnnouncer(s => Debug.WriteLine(s));
            var assembly = Assembly.GetExecutingAssembly();

            var migrationContext = new RunnerContext(announcer);
            var options = new MigrationOptions { PreviewOnly = false, Timeout = 60 };
            var factory = new FluentMigrator.Runner.Processors.SqlServer.SqlServer2012ProcessorFactory();
            using (var processor = factory.Create(connectionString, announcer, options))
            {
                var runner = new MigrationRunner(assembly, migrationContext, processor);
                runner.MigrateUp(true);
            }
        }
Ejemplo n.º 48
0
        public void MigrateToLatest()
        {
            var asm = Assembly.GetExecutingAssembly();
            var announcer = new TextWriterAnnouncer((str) =>
            {
                Debug.WriteLine(str);
            });
            var context = new RunnerContext(announcer);
            var options = new MigrationOptions();
            var factory = new SqlServer2012ProcessorFactory();
            var processor = factory.Create(this._connectionString, announcer, options);
            var runner = new MigrationRunner(asm, context, processor);

            runner.MigrateUp(true);
        }
Ejemplo n.º 49
0
        public static void MigrateToLatest(string connectionString)
        {
            var announcer = new NullAnnouncer();
            var assembly = Assembly.GetExecutingAssembly();

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

            var options = new MigrationOptions { PreviewOnly = false, Timeout = 60 };
            var factory = new FluentMigrator.Runner.Processors.SqlServer.SqlServer2012ProcessorFactory();
            var processor = factory.Create(connectionString, announcer, options);
            var runner = new MigrationRunner(assembly, migrationContext, processor);
            runner.MigrateUp(true);
        }
Ejemplo n.º 50
0
        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 = "Zoo.Models.Migrations"
            };

            var options = new MigrationOptions { PreviewOnly = false, Timeout = 60 };
            var factory = new FluentMigrator.Runner.Processors.SqlServer.SqlServer2012ProcessorFactory();
            var processor = factory.Create(connectionString, announcer, options);
            var runner = new MigrationRunner(assembly, migrationContext, processor);
            runner.MigrateUp(true);
        }
        private static MigrationRunner GetRunner(string connectionString)
        {
            var announcer = new TextWriterAnnouncer(Console.WriteLine);
            var assembly = Assembly.GetExecutingAssembly();

            var migrationContext = new RunnerContext(announcer)
            {
                Namespace = "Rainfall.Integration.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;
        }
Ejemplo n.º 52
0
        /// <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);
            }
        }
Ejemplo n.º 53
0
        public void Migrate(Action<IMigrationRunner> runnerAction)
        {
            var options = new MigrationOptions { PreviewOnly = false, Timeout = 0 };
            var factory = new FluentMigrator.Runner.Processors.Sqlite.SqliteProcessorFactory();
            var assembly = Assembly.GetExecutingAssembly();

            //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 processor = factory.Create(this.connectionString, announcer, options);
            var runner = new MigrationRunner(assembly, migrationContext, processor);
            runnerAction(runner);
        }
Ejemplo n.º 54
0
        public static void MigrateDownOne(string connectionString)
        {
            var announcer = new TextWriterAnnouncer(s => System.Diagnostics.Debug.WriteLine(s));
            var assembly = Assembly.GetExecutingAssembly();

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

            var options = new MigrationOptions { PreviewOnly = false, Timeout = 60 };
            var factory = new FluentMigrator.Runner.Processors.SqlServer.SqlServer2012ProcessorFactory();
            using (var processor = factory.Create(connectionString, announcer, options))
            {
                var runner = new MigrationRunner(assembly, migrationContext, processor);
                runner.VersionLoader.LoadVersionInfo();
                runner.ListMigrations();
                runner.MigrateDown(runner.VersionLoader.VersionInfo.Latest() - 1);
            }
        }
Ejemplo n.º 55
0
        public IMigrationBatch Prepare(long timestamp, MigrationOptions options)
        {
            // import all migrations
            IReadOnlyCollection<ImportedMigration> availableMigrations;
            IReadOnlyCollection<ImportedAggregateMigration> availableAggregateMigrations;
            _importer.ImportAll(out availableMigrations, out availableAggregateMigrations);

            // create migration batch
            var executedMigrations = new List<IMigrationMetadata>(_versioning.ExecutedMigrations);
            var migrationSelector = new MigrationSelector(availableMigrations, executedMigrations);
            IEnumerable<ApplicableMigration> applicableMigrations;
            IEnumerable<IMigrationMetadata> unidentifiedMigrations;
            migrationSelector.GetMigrationsTo(timestamp, options.MigrationSelector, out applicableMigrations, out unidentifiedMigrations);
            var migrationAggregator = new MigrationAggregator(applicableMigrations, availableMigrations, availableAggregateMigrations);
            var migrationSteps = migrationAggregator.Aggregate();
            return new MigrationBatch(
                migrationSteps,
                unidentifiedMigrations,
                _versioning,
                _configuration);
        }
Ejemplo n.º 56
0
 public Validator(MigrationOptions options)
 {
     _options = options;
 }
Ejemplo n.º 57
0
 private static void ExecuteMigration(string connectionString, DbPlatform dbPlatform, MigrationOptions options, string assemblyPath, long timestamp, string[] additionalAssemblyPaths)
 {
     var migrator = new Migrator(connectionString, dbPlatform, options);
     IMigrationBatch batch = migrator.FetchMigrationsTo(assemblyPath, timestamp, additionalAssemblyPaths);
     batch.Execute();
 }
Ejemplo n.º 58
0
 internal static void Initialize(MigrationOptions options, IEnumerable<SupportsAttribute> supportsAttributes)
 {
     _options = options;
     _supportsAttributes = supportsAttributes;
 }
Ejemplo n.º 59
0
 internal static void Initialize(MigrationOptions options, ProviderInfo providerInfo)
 {
     _options = options;
     _providerInfo = providerInfo;
 }
Ejemplo n.º 60
0
        public virtual void Setup()
        {
            _options = new MigrationOptions();
            _options.SupportedPlatforms.Set(new[] { DbPlatform }); // avoid validation errors/warnings from other providers

            // initialize IntegrationTestContext
            IProviderFactory providerFactory = new ProviderFactory();
            var providerLocator = new ProviderLocator(providerFactory);
            ProviderInfo providerInfo = providerLocator.GetExactly(DbPlatform);
            IntegrationTestContext.Initialize(_options, providerInfo);
        }