How to make DACPAC update only one schema?

半腔热情 提交于 2019-12-21 01:26:22

问题


I have a VS2013 solution with *.sqlproj project that contains objects specific to this solution. The issue is that this is database common also for other projects.

My problem is to automatically deploy changes within my schema to database without affecting other objects. By default DACPAC updates whole database that is not desired in my case.

I tried to write deployment contributor http://msdn.microsoft.com/en-us/library/dn268597(v=vs.103).aspx but it seems there is no way to have it within solution folder, as it have to be placed in Program Files subfolder of SQL server.

I use Bamboo to create deployment packages and the application is hosted on Microsoft Azure with Azure SQL database.

Is there any way I can deploy DB changes only within my schema using DACPAC or other automatic means?


回答1:


Your two options are as follows:

  1. Copy SqlPackage.exe and the other DAC DLLs to a folder inside your solution, or one controlled by your deployment team. Also copy your contributor DLL to that same folder. Then make sure that when deploying you use SqlPackage.exe from that location. Since any DLL in the same folder as Microsoft.Data.Tools.Schema.Sql.dll will be checked for extensions you can use this method to get your contributor included during deployment, without the need to install to a system-wide location.

  2. Filter out objects related to other schemas from your dacpac, and then deploy with DropObjectsNotInSource = false. This is less ideal since it won't drop objects that you delete, but the benefit is that you can do it at build time / before passing to the deployment team.

Note that this basic topic is covered in the API tutorial I wrote, with some samples of that in this samples project. It sounds like you have option #1 written already (the tutorial has a simplified version that only blocks additions, not alters/drops), but you can see a comparison between them. Also the samples show how to publish using our APIs (this maps directly to using SqlPackage.exe) and how to easily test and validate contributor behavior.




回答2:


You can build a deployment using the DacpacMerge library, this will merge the model from the database with the model for a single schema, into a new DacPac. This new generated Dacpac can be deployed without affecting the other objects, as they are the same as the database current definition.



来源:https://stackoverflow.com/questions/23550081/how-to-make-dacpac-update-only-one-schema

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!