Skip to content

How to ignore items only in the source database and not in target database #781

@azerios

Description

@azerios
  • SqlPackage or DacFx Version: 170.3.93
  • .NET Framework (Windows-only) or .NET Core: .NET Core 10
  • Environment (local platform and source/target platforms):

Steps to Reproduce:

I have one view to ignore that is only in the source database, I tried to ignore it with these lines and not any of them seems to work

private void ConfigureExclusions(SchemaComparison comparison) {
// It is crucial to make this call to TSqlModel to initialize the TypeClass objects before we create any SchemaComparisonExcludedObjectId instances that reference them. If we try to create a SchemaComparisonExcludedObjectId with a TypeClass before it is initialized, it will throw a NullReferenceException. This is a quirk of how the DacFx library loads metadata about SQL object types. By creating an instance of TSqlModel and accessing the TypeClass property, we ensure that all the necessary type information is loaded and available for our exclusions.
using var model = new TSqlModel(SqlServerVersion.Sql150, new TSqlModelOptions());

  // Object exclusions migrated from the Redgate project <ProjectFilter>.
  var exclusions = new SchemaComparisonExcludedObjectId[] {
  	// View: (@NAME = 'V_MT')
  	new(View.TypeClass, new ObjectIdentifier("dbo", "V_MT")),
  	new(View.TypeClass, new ObjectIdentifier("V_MT")),
  	new(View.TypeClass, new ObjectIdentifier("dbo.V_MT")),
  	new(View.TypeClass, new ObjectIdentifier("dbo.[V_MT]")),
  	new(View.TypeClass, new ObjectIdentifier("[dbo].[V_MT]")),
  	new(
        View.TypeClass, // Object type
        new ObjectIdentifier("[dbo].[V_MT]"), // Schema + name
        null, // No target type (source-only)
        null  // No target identifier
    ),
  	new(
        View.TypeClass, // Object type
        new ObjectIdentifier("dbo", "V_MT"), // Schema + name
        null, // No target type (source-only)
        null  // No target identifier
    )
  };

  foreach (var exclusion in exclusions) {
  	comparison.ExcludedSourceObjects.Add(exclusion);
  	comparison.ExcludedTargetObjects.Add(exclusion);
  }

}

Did this occur in prior versions? If not - which version(s) did it work in?

Is is possible to guide me to ignore this view ?

I'll try to apply the solution to Stored procedure that I have to ignore by specific name

(DacFx/SqlPackage/SSMS/Azure Data Studio)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions