DeploymentContributorFilterer icon indicating copy to clipboard operation
DeploymentContributorFilterer copied to clipboard

Ignore schema does not work correctly with unnamed constraints

Open martinsmith123456 opened this issue 5 years ago • 2 comments

This can be reproduced as follows.

  • Build the Dacpac project.
  • Replace the one in AgileSqlClub.SqlPackageFilter.IntegrationTests with the newly built one (the one currently there is missing the DEFAULT 'aaaaa' that would show the problem.
  • In the Schema_Is_Not_Created_When_Name_Is_Ignored integration test add assertion that proc.WasDeploySuccess(); after proc.Run();

The test will now fail as it tried to run an ALTER TABLE adding a default to a table that does not exist.


The issue is that the name for these is blank so attempting to extract the schema from the name does not work.

I can't see a nice way of fixing this though.

In the immediate window extracting the schema name from

((Microsoft.Data.Tools.Schema.Sql.SchemaModel.SqlTable)((Microsoft.Data.Tools.Schema.Sql.SchemaModel.SqlDefaultConstraint)((CreateElementStep)step).SourceElement.ContextObject).DefiningTable).Schema.Name.Parts[0]

would work but this would need reflection to access in the code itself as these are not all public.

Maybe I will resort to parsing it out of the CreateElementStep.Message

Any better suggestions?

martinsmith123456 avatar Jun 05 '19 16:06 martinsmith123456

Can I know if your changes worked or you found a better way to handle this situation? Please let me know. Thank you.

KBSK333000 avatar Jun 09 '20 17:06 KBSK333000

Wow I found this project because I wanted to exclude a specific schema during deployment and noticed the same thing as mentioned above. The generated script still lists the sections for "Dropping unnamed constraint" that reference (in my case default values) for fields in tables from the schema I want to exclude. So I would still have lost something from the tables in the schema I want to be left alone. This was with the DLL release 1.4.4.1 the latest as of now from Mar 8 2019.

P.S. Coming from handcrafted sql scripts and generating bacpac from a VS SQL Database project and using sqlpackage to deploy upgrades to customer databases still feels like a very fragile solution.

jbennink avatar Feb 09 '21 16:02 jbennink