当前位置: 首页>>代码示例>>C#>>正文


C# Migrator.MigrateAll方法代码示例

本文整理汇总了C#中Migrator.MigrateAll方法的典型用法代码示例。如果您正苦于以下问题:C# Migrator.MigrateAll方法的具体用法?C# Migrator.MigrateAll怎么用?C# Migrator.MigrateAll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Migrator的用法示例。


在下文中一共展示了Migrator.MigrateAll方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Execute

        public void Execute()
        {
            var connection = ConfigurationManager.ConnectionStrings["database"];
            var options = new MigrationOptions();
            options.SupportedProviders.Clear();
            options.SupportedProviders.Add(ProviderNames.SQLite);
            options.SupportedProviders.Add(ProviderNames.SqlServer2005);
            options.SupportedProviders.Add(ProviderNames.SqlServer2008);

            var m = new Migrator(connection.ConnectionString, connection.ProviderName, options);

            m.MigrateAll(typeof(MeasuresController).Assembly);
        }
开发者ID:caiokf,项目名称:smart-track,代码行数:13,代码来源:MigrateDatabase.cs

示例2: TestGenerate

        public void TestGenerate()
        {
            SetupGenerateTest();

            // run all migration on second database
            Migrator migrator2 = new Migrator(ConnectionString2, DbPlatform);
            migrator2.MigrateAll(typeof(IntegrationTestsBase).Assembly);

            // generate base-line migration
            var options = new GeneratorOptions
            {
                Namespace = GetType().Namespace,
                IncludedSchemas = { "dbo", "Schema25", "Schema 29" }, // these schemas belong to the Default module
                ExcludedTables = { "Order Space" }, // the excluded tables belong other modules
                IncludeData = true,
            };
            SqlMigrationGeneratorFactory factory = new SqlMigrationGeneratorFactory(ConnectionString2);
            IGenerator generator = factory.Create(options);
            string migration = generator.Generate();
            Assert.IsEmpty(generator.Errors);
            Assert.IsTrue(migration.Contains("[AggregateMigrationExport"), "The generated migration should be an aggregated migration.");

            // compile and execute base-line migration on usual test database
            Assembly assembly = Compile(migration);
            Migrator migrator = new Migrator(ConnectionString, DbPlatform);
            migrator.MigrateAll(assembly, typeof(IntegrationTestsBase).Assembly);

            // check if the schema of the two databases is equal
            CollectionAssert.AreEqual(_database2.Tables.Cast<Table>().Select(t => t.Name).ToArray(), DatabaseSmo.Tables.Cast<Table>().Select(t => t.Name).ToArray(), "The tables differ.");
            IEnumerable<string> script = ScriptDatabase(DatabaseSmo);
            IEnumerable<string> script2 = ScriptDatabase(_database2);
            CollectionAssert.AreEqual(script2.ToArray(), script.ToArray());

            // check if the data was scripted too
            VerifyResultsOfAllMigrations();
        }
开发者ID:dradovic,项目名称:MigSharp,代码行数:36,代码来源:SqlServer2012IntegrationTests.cs

示例3: TestCustomBootstrapping

        public void TestCustomBootstrapping()
        {
            // use a Module selection to verify that the bootstrapping is still considering *all* migrations
            _options.ModuleSelector = moduleName => moduleName == Migration2.Module;
            Migrator migrator = new Migrator(ConnectionString, ProviderName, _options);

            IBootstrapper bootstrapper = MockRepository.GenerateStrictMock<IBootstrapper>();
            bootstrapper.Expect(b => b.BeginBootstrapping(null, null)).IgnoreArguments();
            for (int i = 0; i < Migrations.Count; i++) // assume that all migrations were already performed
            {
                long timestamp = Timestamps[i];
                bootstrapper.Expect(b => b.IsContained(Arg<IMigrationMetadata>.Matches(m => m.Timestamp == timestamp))).Return(true);
            }
            bootstrapper.Expect(b => b.EndBootstrapping(null, null)).IgnoreArguments();
            migrator.UseCustomBootstrapping(bootstrapper);

            migrator.MigrateAll(typeof(Migration1).Assembly);

            // assert Migration1 table was *not* created
            DataTable table = GetTable(new Migration1().Tables[0].Name);
            Assert.IsNull(table);

            // assert Versioning table has necessary entries
            DataTable versioningTable = GetTable(_options.VersioningTableName);
            Assert.AreEqual(Migrations.Count, versioningTable.Rows.Count, "The versioning table is missing entries.");

            bootstrapper.VerifyAllExpectations();
        }
开发者ID:nachojammers,项目名称:MigSharp,代码行数:28,代码来源:IntegrationTestsBase.cs

示例4: TestScriptingAllMigrations

        public void TestScriptingAllMigrations()
        {
            DirectoryInfo targetDirectory = PrepareScriptingDirectory();
            _options.VersioningTableName = "My Versioning Table"; // test overriding the default versioning table name
            _options.OnlyScriptSqlTo(targetDirectory);
            var migrator = new Migrator(ConnectionString, ProviderName, _options);
            migrator.MigrateAll(typeof(Migration1).Assembly);

            // assert that all script files were generated
            List<FileInfo> scriptFiles = targetDirectory.GetFiles(string.Format(CultureInfo.InvariantCulture, "Migration.*.*.sql"))
                .OrderBy(f => int.Parse(Regex.Match(f.Name, @"Migration\..*\.(\d+)\.sql").Groups[1].Value, CultureInfo.InvariantCulture))
                .ToList();
            Assert.AreEqual(Migrations.Count, scriptFiles.Count);
            Assert.AreEqual("Migration." + MigrationExportAttribute.DefaultModuleName + ".1.sql", scriptFiles[0].Name);
            Assert.AreEqual("Migration." + Migration2.Module + ".2.sql", scriptFiles[1].Name);

            // assert Versioning table was *not* created as we are scripting only
            DataTable versioningTable = GetTable(_options.VersioningTableName);
            Assert.IsNull(versioningTable, string.Format(CultureInfo.CurrentCulture, "The '{0}' table was created altough ScriptingMode was ScriptOnly.", _options.VersioningTableName));

            // assert Customer table was *not* created as we are scripting only
            var migration1 = new Migration1();
            DataTable customerTable = GetTable(migration1.Tables[0].Name);
            Assert.IsNull(customerTable, string.Format(CultureInfo.CurrentCulture, "The '{0}' table was created altough ScriptingMode was ScriptOnly.", migration1.Tables[0].Name));

            // execute generated script files against database and recheck results
            IProviderMetadata providerMetadata;
            _options.SupportedProviders.GetProvider(ProviderName, out providerMetadata);
            var info = new ConnectionInfo(ConnectionString, providerMetadata.InvariantName, providerMetadata.SupportsTransactions);
            var factory = new DbConnectionFactory();
            using (IDbConnection connection = factory.OpenConnection(info))
            {
                foreach (FileInfo scriptFile in scriptFiles)
                {
                    Trace.WriteLine(string.Format(CultureInfo.CurrentCulture, "Reading script '{0}':", scriptFile.FullName));
                    string[] scriptLines = File.ReadAllLines(scriptFile.FullName);
                    foreach (string line in scriptLines)
                    {
                        Trace.WriteLine(line);
                    }

                    // group all lines between empty lines into one command (some database platforms require DDL operations to
                    // be executed in separated commands)
                    Trace.WriteLine(Environment.NewLine + string.Format(CultureInfo.CurrentCulture, "Executing script '{0}':", scriptFile.FullName));
                    string commandText = string.Empty;
                    foreach (string line in scriptLines)
                    {
                        if (line.Trim().Length != 0)
                        {
                            commandText += line;
                        }
                        else
                        {
                            ExecuteCommand(commandText, connection);
                            commandText = string.Empty;
                        }
                    }
                    Assert.IsEmpty(commandText, "The script should end with an empty line.");
                }
            }
            VerifyResultsOfAllMigrations();

            // delete script files
            targetDirectory.Delete(true);
        }
开发者ID:nachojammers,项目名称:MigSharp,代码行数:65,代码来源:IntegrationTestsBase.cs

示例5: TestMigration1SucceededByAllOtherMigrations

        public void TestMigration1SucceededByAllOtherMigrations()
        {
            // execute Migration1
            var migrator = new Migrator(ConnectionString, ProviderName, _options);
            Assembly assemblyContainingMigrations = typeof(Migration1).Assembly;
            migrator.MigrateTo(assemblyContainingMigrations, Timestamps[0]);

            // execute all other migrations
            migrator = new Migrator(ConnectionString, ProviderName, _options);
            migrator.MigrateAll(assemblyContainingMigrations);
            Assert.IsTrue(migrator.IsUpToDate(assemblyContainingMigrations));

            VerifyResultsOfAllMigrations();
        }
开发者ID:nachojammers,项目名称:MigSharp,代码行数:14,代码来源:IntegrationTestsBase.cs

示例6: TestMigration1SucceededByAllOtherMigrations

        public void TestMigration1SucceededByAllOtherMigrations()
        {
            // execute Migration1
            var migrator = new Migrator(ConnectionString, ProviderName, _options);
            Assembly assemblyContainingMigrations = typeof(Migration1).Assembly;
            migrator.MigrateTo(assemblyContainingMigrations, Timestamps[0]);

            // execute all other migrations
            migrator = new Migrator(ConnectionString, ProviderName, _options);
            migrator.MigrateAll(assemblyContainingMigrations);

            // make sure there are no more migrations to run
            IMigrationBatch batch = migrator.FetchMigrations(assemblyContainingMigrations);
            Assert.AreEqual(0, batch.ScheduledMigrations.Count);

            VerifyResultsOfAllMigrations();
        }
开发者ID:halad,项目名称:MigSharp,代码行数:17,代码来源:IntegrationTestsBase.cs

示例7: MigrateUp

 public void MigrateUp()
 {
     var migrator = new Migrator(_config.ConnectionString, ProviderNames.SqlServer2008, _options);
     migrator.MigrateAll(typeof(V001_Initial_1).Assembly);
 }
开发者ID:pedershk,项目名称:dotnetprograms,代码行数:5,代码来源:VisualFarmMigrator.cs


注:本文中的Migrator.MigrateAll方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。