简体   繁体   English

如何让 DACPAC 只更新一个架构?

[英]How to make DACPAC update only one schema?

I have a VS2013 solution with *.sqlproj project that contains objects specific to this solution.我有一个带有 *.sqlproj 项目的 VS2013 解决方案,其中包含特定于此解决方案的对象。 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.默认情况下,DACPAC 会更新我不需要的整个数据库。

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.我试图编写部署贡献者http://msdn.microsoft.com/en-us/library/dn268597(v=vs.103).aspx但似乎没有办法将它放在解决方案文件夹中,因为它必须放在 SQL Server 的 Program Files 子文件夹中。

I use Bamboo to create deployment packages and the application is hosted on Microsoft Azure with Azure SQL database.我使用 Bamboo 创建部署包,并且该应用程序托管在带有 Azure SQL 数据库的 Microsoft Azure 上。

Is there any way I can deploy DB changes only within my schema using DACPAC or other automatic means?有什么方法可以使用 DACPAC 或其他自动方式仅在我的架构中部署数据库更改?

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.将 SqlPackage.exe 和其他 DAC DLL 复制到您的解决方案中的一个文件夹,或由您的部署团队控制的文件夹。 Also copy your contributor DLL to that same folder.还将您的贡献者 DLL 复制到同一个文件夹。 Then make sure that when deploying you use SqlPackage.exe from that location.然后确保在部署时从该位置使用 SqlPackage.exe。 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.由于将检查与 Microsoft.Data.Tools.Schema.Sql.dll 位于同一文件夹中的任何 DLL 的扩展名,因此您可以使用此方法在部署期间包含您的贡献者,而无需安装到系统范围的位置。

  2. Filter out objects related to other schemas from your dacpac, and then deploy with DropObjectsNotInSource = false.从您的 dacpac 中过滤出与其他架构相关的对象,然后使用 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 .请注意,我编写的API 教程中涵盖了这个基本主题,此示例项目中有一些示例。 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.听起来您已经编写了选项 #1(本教程有一个简化版本,只阻止添加,而不是更改/删除),但您可以看到它们之间的比较。 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.示例还展示了如何使用我们的 API 进行发布(这直接映射到使用 SqlPackage.exe)以及如何轻松测试和验证贡献者行为。

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.您可以使用DacpacMerge库构建部署,这会将数据库中的模型与单个模式的模型合并到新的 DacPac 中。 This new generated Dacpac can be deployed without affecting the other objects, as they are the same as the database current definition.这个新生成的 Dacpac 可以在不影响其他对象的情况下部署,因为它们与数据库当前定义相同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM