microsoft / microsoft/DacFx

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

Open
#781 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
C#
Stars
460
Forks
29
Avg merge
4d 9h
Merged PRs (30d)
7

Description

- 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 .
> 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)

Contributor guide

Open the contributing guide

Research direction

Start with ConfigureExclusions and the SchemaComparison.ExcludedSourceObjects and ExcludedTargetObjects collections shown in the issue, then review how SchemaComparisonExcludedObjectId represents source-only objects. Verify the behavior for the dbo.V_MT view and determine what configuration is required for a source-only exclusion; done means the view is omitted from comparison without affecting the target and the approach is applicable to a named stored procedure.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, sql
Domain
databases, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.