Skip to content

SchemaComparison.Compare and SchemaComparisonResult.PublishChangesToProject ignores DropDmlTriggersNotInSource and SchemaDifference.Included property #595

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
maciejw opened this issue Mar 29, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@maciejw
Copy link

maciejw commented Mar 29, 2025

Tested on:

  • DacFx Version: 162.1.172, 162.2.111, 162.3.566, 162.4.92, 162.5.57 as well as 170.0.76-preview
  • .NET Framework 4.8
  • Environment (local platform and source/target platforms): WIndows 11

Steps to Reproduce:
Lets assume we have the following

  1. We have database schema in our initial dacpac as follows
CREATE TABLE [dbo].[Table1] (
    Id INT NOT NULL,
    Col1 nvarchar(50)
)
GO
CREATE TRIGGER [dbo].[Trigger1]
    ON [dbo].[Table1]
    AFTER INSERT
    AS PRINT 'Inserted';
GO

we are updating the project with it using

var comparisonResult = new SchemaComparison(source, target).Compare();
var publishResult = comparisonResult.PublishChangesToProject(projectPath, DacExtractTarget.SchemaObjectType);
  1. We have database schema in our modified dacpac as follows:
CREATE TABLE [dbo].[Table1] (
    Id INT NOT NULL,
    Col1 nvarchar(50),
    Col2 nvarchar(50)  -- added
)
GO

-- Trigger1 removed

CREATE TRIGGER [dbo].[Trigger2] -- added
    ON [dbo].[Table1]
    AFTER UPDATE
    AS PRINT 'updated';
GO

CREATE TABLE [dbo].[Table2] ( -- added
    Id INT NOT NULL,
    Col1 nvarchar(50)
)
GO
  1. we are updating the project with it using
var comparisonResult = new SchemaComparison(source, target){
    Options = {
        DropDmlTriggersNotInSource = false,
    }
}.Compare();
var publishResult = comparisonResult.PublishChangesToProject(projectPath, DacExtractTarget.SchemaObjectType);

this results in Trigger1 being removed from the project.
3. we update the the project using following

var comparisonResult = new SchemaComparison(source, target){}.Compare();
comparisonResult.Exclude(GerTrigger1Difference(comparisonResult));
var publishResult = comparisonResult.PublishChangesToProject(projectPath, DacExtractTarget.SchemaObjectType);

this results in Trigger1 being removed from the project.

From what I can see calling Include and Exclude method works only for top level objects, not second level like triggers.
I've checked this in DeploymentPlanModifier I added to this SchemaComparison.Oprions and drop trigger is present in DeploymentPlanContributorContext.ComparisonResult.ElementsToDrop but there is no operation in DeploymentPlanContributorContext.PlanHandle, I though I could fix it by removing DeploymentStep with this drop, from the plan.
I've also tried to add this trigger to SchemaComparison.ExcludedTargetObjects instance property it did not make any difference.

SchemaComparison in this example uses dacpac as source, because I have tests that build a package from those scripts above before Compare.

Clicking Exclude on trigger works in VS 2022 17.13.5 UI, trigger will not be deleted from the project. I'm 95% sure VS does not use DacFx internally for schema comparison and updating the project (I think this is the class Microsoft.Data.Tools.Schema.SchemaModel.ModelComparisonResult that corresponds to Microsoft.SqlServer.Dac.SchemaComparisonResult I'm using), its difficult to be sure when I was analyzing VS code in ilspy sadly I'm not the MS employee :)

I want to automate synchronization of a database in my project by ignoring some objects that I know I have to deal with later. but I dont want to do it manually every time I sync it, because database development is ongoing and we have too many objects to click through in UI.

Did this occur in prior versions? I dont think so 162.0.52 is not compatible with my project I would have to change few things

@maciejw maciejw added the bug Something isn't working label Mar 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant