예제 #1
0
        private TSqlModel CreateFilteredModel(SchemaBasedFilter schemaFilter, TSqlModel model)
        {
            ModelFilterer modelFilterer = new ModelFilterer(schemaFilter);

            TSqlModel filteredModel = modelFilterer.CreateFilteredModel(model);

            _trash.Add(filteredModel);
            return(filteredModel);
        }
예제 #2
0
        public void TestUpdateDacpacWithFilteredModel()
        {
            // Given a model with objects that use "dev", "test" and "prod" schemas
            var    model = CreateTestModel();
            string existingPackagePath = GetTestFilePath("original.dacpac");

            BuildPackage(model, existingPackagePath);

            // When saving a dacpac for deployment to production (filtering to exclude "dev" and "test" schemas)
            var           schemaFilter  = new SchemaBasedFilter("dev", "test");
            ModelFilterer modelFilterer = new ModelFilterer(schemaFilter);

            modelFilterer.UpdateDacpacModelWithFilter(existingPackagePath);

            // Then expect only the "prod" schema objects to remain in the new package
            var filteredModel = _trash.Add(new TSqlModel(existingPackagePath));

            Assert.AreEqual(TopLevelProdElementCount, CountTablesViewsAndSchemas(filteredModel));
        }
예제 #3
0
        /// <summary>
        /// Runs the model filtering example. This shows how to filter a model and save a new
        /// dacpac with the updated model. You can also update the model in the existing dacpac;
        /// the unit tests in TestFiltering.cs show how this is performed.
        /// </summary>
        public static void RunFilteringExample()
        {
            // Given a model with objects that use "dev", "test" and "prod" schemas
            string devPackagePath = GetFilePathInCurrentDirectory("dev.dacpac");
            var    scripts        = SampleScripts;
            string productionPackagePath;

            using (TSqlModel model = new TSqlModel(SqlServerVersion.Sql110, new TSqlModelOptions()))
            {
                AddScriptsToModel(model, scripts);

                Console.WriteLine("Saving test scripts to package '" + devPackagePath + "'");
                DacPackageExtensions.BuildPackage(devPackagePath, model, new PackageMetadata());


                Console.WriteLine("Objects found in original package: '" + devPackagePath + "'");
                PrintTablesViewsAndSchemas(model);

                productionPackagePath = GetFilePathInCurrentDirectory("production.dacpac");

                // When saving a dacpac for deployment to production (filtering to exclude "dev" and "test" schemas)
                var           schemaFilter  = new SchemaBasedFilter(model.CollationComparer, new [] { "dev", "test" });
                ModelFilterer modelFilterer = new ModelFilterer(schemaFilter);


                Console.WriteLine("Creating filtered 'production' package: '" + productionPackagePath + "'");
                modelFilterer.CreateFilteredDacpac(devPackagePath, productionPackagePath);
            }


            // Then expect only the "prod" schema objects to remain in the new package
            using (TSqlModel filteredModel = new TSqlModel(productionPackagePath))
            {
                Console.WriteLine("Objects found in filtered package: '" + productionPackagePath + "'");
                PrintTablesViewsAndSchemas(filteredModel);
            }

            // If we publish the dacpac to a database, we can see that only the production schema is
            // present (debug into this method or view the console output listing only production elements)
            PublishProductionDacpacAndVerifyContents(productionPackagePath);
        }
예제 #4
0
        public static void Run()
        {
            Directory.CreateDirectory(GetTestDir(_ModelCompareDacsPath));
            Directory.CreateDirectory(GetTestDir(_compareResultsPath));
            _sourceDacpacPath = GetTestFilePath(_ModelCompareDacsPath, "sourceDatabase.dacpac");
            DacPackageExtensions.BuildPackage(_sourceDacpacPath, CreateTestModel(_testSourceScripts), new PackageMetadata());
            _destinationDacPacPath = GetTestFilePath(_ModelCompareDacsPath, "destinationDatabase.dacpac");
            DacPackageExtensions.BuildPackage(_destinationDacPacPath, CreateTestModel(_testDestinationScripts), new PackageMetadata());

            using (TSqlModel sourcemodel = new TSqlModel(_sourceDacpacPath),
                   destmodel = new TSqlModel(_destinationDacPacPath))
            {
                // Filtering to exclude log schema
                var           schemaFilter  = new SchemaBasedFilter("log");
                ModelFilterer modelFilterer = new ModelFilterer(schemaFilter);
                TSqlModel     smodel        = modelFilterer.CreateFilteredModel(sourcemodel);
                TSqlModel     dmodel        = modelFilterer.CreateFilteredModel(destmodel);

                CompareTSqlModels(smodel, dmodel);
            }
        }
예제 #5
0
        /// <summary>
        /// Runs the model filtering example. This shows how to filter a model and save a new
        /// dacpac with the updated model. You can also update the model in the existing dacpac;
        /// the unit tests in TestFiltering.cs show how this is performed.
        /// </summary>
        public static void RunFilteringExample()
        {
            // Given a model with objects that use "dev", "test" and "prod" schemas
            string devPackagePath = GetFilePathInCurrentDirectory("dev.dacpac");
            var scripts = SampleScripts;
            using (TSqlModel model = new TSqlModel(SqlServerVersion.Sql110, new TSqlModelOptions()))
            {
                AddScriptsToModel(model, scripts);

                Console.WriteLine("Saving test scripts to package '"+devPackagePath+"'");
                DacPackageExtensions.BuildPackage(devPackagePath, model, new PackageMetadata());

                Console.WriteLine("Objects found in original package: '" + devPackagePath + "'");
                PrintTablesViewsAndSchemas(model);

            }

            string productionPackagePath = GetFilePathInCurrentDirectory("production.dacpac");

            // When saving a dacpac for deployment to production (filtering to exclude "dev" and "test" schemas)
            var schemaFilter = new SchemaBasedFilter("dev", "test");
            ModelFilterer modelFilterer = new ModelFilterer(schemaFilter);

            Console.WriteLine("Creating filtered 'production' package: '"+productionPackagePath+"'");
            modelFilterer.CreateFilteredDacpac(devPackagePath, productionPackagePath);

            // Then expect only the "prod" schema objects to remain in the new package
            using (TSqlModel filteredModel = new TSqlModel(productionPackagePath))
            {
                Console.WriteLine("Objects found in filtered package: '" + productionPackagePath + "'");
                PrintTablesViewsAndSchemas(filteredModel);
            }

            // If we publish the dacpac to a database, we can see that only the production schema is
            // present (debug into this method or view the console output listing only production elements)
            PublishProductionDacpacAndVerifyContents(productionPackagePath);
        }