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();
        }
Esempio n. 2
0
        private static void Main()
        {
            CommandLineOptions options;
            CommandLineParser parser;
            if (DisplayHelp(Environment.CommandLine, out options, out parser))
            {
                Console.WriteLine(GetUsageMessage(parser));
                Environment.Exit(SuccessExitCode);
            }

            string connectionString;
            string migrationNamespace;
            string moduleName;
            string versioningTableName;
            string versioningTableSchema;
            string[] includedSchemas;
            string[] excludedTables;
            bool includeData;
            try
            {
                ParseCommandLineArguments(options, parser, ConfigurationManager.ConnectionStrings,
                    out connectionString,
                    out migrationNamespace,
                    out moduleName,
                    out versioningTableName,
                    out versioningTableSchema,
                    out includedSchemas,
                    out excludedTables,
                    out includeData);
            }
            catch (InvalidCommandLineArgumentException x)
            {
                Console.Error.WriteLine(x.Message);
                Environment.Exit(x.ExitCode);
                throw; // will not be executed; just to satisfy R#
            }
            var factory = new SqlMigrationGeneratorFactory(connectionString);
            var generateOptions = new GeneratorOptions
            {
                Namespace = migrationNamespace,
                ModuleName = moduleName,
                VersioningTableName = versioningTableName,
                VersioningTableSchema = versioningTableSchema,
                IncludeData = includeData,
            };
            foreach (string includedSchema in includedSchemas)
            {
                generateOptions.IncludedSchemas.Add(includedSchema);
            }
            foreach (string excludedTable in excludedTables)
            {
                generateOptions.ExcludedTables.Add(excludedTable);
            }
            IGenerator generator = factory.Create(generateOptions);
            string migration = generator.Generate();
            if (generator.Errors.Any())
            {
                Console.Error.WriteLine("Following errors have occured:");
                Console.Error.WriteLine(string.Join(Environment.NewLine, generator.Errors));
                Environment.Exit(UnsuccessfulExitCode);
            }
            Clipboard.SetText(migration, TextDataFormat.UnicodeText);
            Console.WriteLine("The generation of the migration was successful and is now available in your clipboard.");
        }
Esempio n. 3
0
        [STAThread] // for setting the clipboard
        private static void Main()
        {
            CommandLineOptions options;
            CommandLineParser  parser;

            if (DisplayHelp(Environment.CommandLine, out options, out parser))
            {
                Console.WriteLine(GetUsageMessage(parser));
                Environment.Exit(SuccessExitCode);
            }

            string connectionString;
            string migrationNamespace;
            string moduleName;
            string versioningTableName;
            string versioningTableSchema;

            string[] includedSchemas;
            string[] excludedTables;
            bool     includeData;

            try
            {
                ParseCommandLineArguments(options, parser, ConfigurationManager.ConnectionStrings,
                                          out connectionString,
                                          out migrationNamespace,
                                          out moduleName,
                                          out versioningTableName,
                                          out versioningTableSchema,
                                          out includedSchemas,
                                          out excludedTables,
                                          out includeData);
            }
            catch (InvalidCommandLineArgumentException x)
            {
                Console.Error.WriteLine(x.Message);
                Environment.Exit(x.ExitCode);
                throw; // will not be executed; just to satisfy R#
            }
            var factory         = new SqlMigrationGeneratorFactory(connectionString);
            var generateOptions = new GeneratorOptions
            {
                Namespace             = migrationNamespace,
                ModuleName            = moduleName,
                VersioningTableName   = versioningTableName,
                VersioningTableSchema = versioningTableSchema,
                IncludeData           = includeData,
            };

            foreach (string includedSchema in includedSchemas)
            {
                generateOptions.IncludedSchemas.Add(includedSchema);
            }
            foreach (string excludedTable in excludedTables)
            {
                generateOptions.ExcludedTables.Add(excludedTable);
            }
            IGenerator generator = factory.Create(generateOptions);
            string     migration = generator.Generate();

            if (generator.Errors.Any())
            {
                Console.Error.WriteLine("Following errors have occured:");
                Console.Error.WriteLine(string.Join(Environment.NewLine, generator.Errors));
                Environment.Exit(UnsuccessfulExitCode);
            }
            Clipboard.SetText(migration, TextDataFormat.UnicodeText);
            Console.WriteLine("The generation of the migration was successful and is now available in your clipboard.");
        }