我们已经开始使用 SSDT 来管理我们的脚本部署。最初我们使用 Schema Compare 并取消选中我们不想部署的部分。我们现在需要使用仅包含在发布功能中的 Pre 和 Post-Deploy 脚本,并且我们也在尝试清理我们排除的部分。
在 Publish 中添加了 2 个未在 Schema Compare 中的差异,即使设置尽可能接近,我似乎也无法弄清楚。
第一个是 Publish 脚本想要删除 dacpac 中不存在的表的统计信息,即使DropStatisticsNotInSource
设置为 false。我能够根据SSDT/SqlPackage drop statistics中的 DeploymentFilterContributor 答案解决此问题。
第二个继续难倒我。大多数应用程序安全性是通过授予角色和各种系统帐户成为成员,具体取决于环境,但是也有用户不在开发数据库中的角色(通常是管理员,但也有具有各种权限的实用程序)。我们在不同的环境中有不同的用户。我的长期目标是只让用户担任角色,但我们还没有实现。与此同时,我们需要排除用户被丢弃。我从设置Exclude Users
,开始ExcludeLogins
,ExcludeRoleMembership
这是我们在 Schema Compare 中使用的,效果很好。然而,在 Publish 脚本中,我们得到了REVOKE CONNECT
脚本(但不是DROP LOGIN
or DROP USER
)。
我已经阅读了使用 SqlPackage.exe 发布 DACPAC 时防止删除用户并在 SqlPackage.exe 部署的 dacpac 中创建用户导致登录失败 SqlException(这似乎是一个类似的脚本结果,具有不同的目标,也没有答案)。我尝试将AgileSqlClub.DeploymentFilterContributor与IgnoreType(Login)
, IgnoreType(User)
, IgnoreType(RoleMembership)
, 以及IgnoreType(Permissions)
,一起使用IgnoreSecurity
。前3个没有效果。最后 2 个(我还尝试了等效的 SSDT 配置选项)还删除GRANT
了我想针对 db 角色包含的脚本。
我觉得我应该能够做到这一点,而无需创建自定义DeploymentContributor
并且无需在部署后为所有这些用户编写脚本。我怎样才能摆脱这些REVOKE CONNECT
电话?
此外,如果有人知道 Visual Studio 是否实际上在其路径中调用 SqlPackage.exe 或者正在使用库,我将不胜感激这些信息......我似乎无法让我的机器上的 5 个 SqlPackage.exe 中的任何一个工作使用 VS 使用的内置 .dacpac 和 .publish.xml 文件。
我包括完整的发布配置文件以供参考:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<AdditionalDeploymentContributors>AgileSqlClub.DeploymentFilterContributor</AdditionalDeploymentContributors>
<!--AdditionalDeploymentContributorArguments>SqlPackageFilter0=IgnoreType(Statistics);SqlPackageFilter1=IgnoreType(Login);SqlPackageFilter2=IgnoreType(User);SqlPackageFilter3=IgnoreType(RoleMembership);SqlPackageFilter4=IgnoreSchema(SEQUENCES)</AdditionalDeploymentContributorArguments-->
<!--AdditionalDeploymentContributorArguments>SqlPackageFilter4=IgnoreSchema(SEQUENCES)</AdditionalDeploymentContributorArguments-->
<AdditionalDeploymentContributorArguments>SqlPackageFilter0=IgnoreType(Statistics);SqlPackageFilter1=IgnoreSecurity</AdditionalDeploymentContributorArguments>
<IncludeCompositeObjects>True</IncludeCompositeObjects>
<TargetDatabaseName>BRM</TargetDatabaseName>
<DeployScriptFileName>BRM.sql</DeployScriptFileName>
<TargetConnectionString>Data Source=mydb;Integrated Security=True;Persist Security Info=False;Pooling=False;MultipleActiveResultSets=False;Connect Timeout=60;Encrypt=False;TrustServerCertificate=True</TargetConnectionString>
<BlockOnPossibleDataLoss>True</BlockOnPossibleDataLoss>
<ExcludeAggregates>False</ExcludeAggregates>
<ExcludeApplicationRoles>False</ExcludeApplicationRoles>
<ExcludeAssemblies>True</ExcludeAssemblies>
<ExcludeAsymmetricKeys>True</ExcludeAsymmetricKeys>
<ExcludeBrokerPriorities>True</ExcludeBrokerPriorities>
<ExcludeCertificates>True</ExcludeCertificates>
<ExcludeExternalDataSources>True</ExcludeExternalDataSources>
<ExcludeExternalFileFormats>True</ExcludeExternalFileFormats>
<ExcludeExternalTables>True</ExcludeExternalTables>
<ExcludeFilegroups>True</ExcludeFilegroups>
<ExcludeFileTables>True</ExcludeFileTables>
<ExcludeFullTextCatalogs>True</ExcludeFullTextCatalogs>
<ExcludeFullTextStoplists>True</ExcludeFullTextStoplists>
<ExcludePartitionFunctions>True</ExcludePartitionFunctions>
<ExcludePartitionSchemes>True</ExcludePartitionSchemes>
<ExcludeQueues>True</ExcludeQueues>
<ExcludeRemoteServiceBindings>True</ExcludeRemoteServiceBindings>
<IgnoreRoleMembership>True</IgnoreRoleMembership>
<ExcludeRules>True</ExcludeRules>
<ExcludeSecurityPolicies>True</ExcludeSecurityPolicies>
<ExcludeServices>True</ExcludeServices>
<ExcludeSignatures>True</ExcludeSignatures>
<ExcludeUserDefinedDataTypes>True</ExcludeUserDefinedDataTypes>
<ExcludeUserDefinedTableTypes>True</ExcludeUserDefinedTableTypes>
<ExcludeUsers>True</ExcludeUsers>
<ExcludeXmlSchemaCollections>True</ExcludeXmlSchemaCollections>
<DropObjectsNotInSource>True</DropObjectsNotInSource>
<DropPermissionsNotInSource>False</DropPermissionsNotInSource>
<DropRoleMembersNotInSource>False</DropRoleMembersNotInSource>
<DisableAndReenableDdlTriggers>False</DisableAndReenableDdlTriggers>
<IncludeTransactionalScripts>True</IncludeTransactionalScripts>
<ProfileVersionNumber>1</ProfileVersionNumber>
<DropStatisticsNotInSource>False</DropStatisticsNotInSource>
<ExcludeLogins>True</ExcludeLogins>
<ExcludeAudits>True</ExcludeAudits>
<ExcludeClrUserDefinedTypes>True</ExcludeClrUserDefinedTypes>
<ExcludeCredentials>True</ExcludeCredentials>
<ExcludeCryptographicProviders>True</ExcludeCryptographicProviders>
<ExcludeDatabaseScopedCredentials>True</ExcludeDatabaseScopedCredentials>
<ExcludeDatabaseAuditSpecifications>True</ExcludeDatabaseAuditSpecifications>
<ExcludeEndpoints>True</ExcludeEndpoints>
<ExcludeErrorMessages>True</ExcludeErrorMessages>
<ExcludeEventSessions>True</ExcludeEventSessions>
<ExcludeLinkedServerLogins>True</ExcludeLinkedServerLogins>
<ExcludeLinkedServers>True</ExcludeLinkedServers>
<ExcludeRoutes>True</ExcludeRoutes>
<ExcludeSearchPropertyLists>True</ExcludeSearchPropertyLists>
<ExcludeServerAuditSpecifications>True</ExcludeServerAuditSpecifications>
<ExcludeServerRoleMembership>True</ExcludeServerRoleMembership>
<ExcludeServerRoles>True</ExcludeServerRoles>
<ExcludeServerTriggers>True</ExcludeServerTriggers>
<DoNotDropLogins>True</DoNotDropLogins>
<DoNotDropUsers>True</DoNotDropUsers>
<DoNotDropRoleMembership>True</DoNotDropRoleMembership>
<DoNotDropServerRoleMembership>True</DoNotDropServerRoleMembership>
</PropertyGroup>
<ItemGroup>
<SqlCmdVariable Include="mscrm">
<Value>mscrm</Value>
</SqlCmdVariable>
<SqlCmdVariable Include="sysdb">
<Value>sysdb</Value>
</SqlCmdVariable>
</ItemGroup>
</Project>
VS2015 Update 3 和 SSDT 14.0.61712.050(我认为是最新的)。