简体   繁体   English

#if DEBUG 等效于 SQL 数据库项目?

[英]#if DEBUG equivalent in SQL Database Projects?

I am trying to / wondering if you can have environment-specific coding in an SQL Database Project, particularly in the PostDeploymentScript.sql我正在尝试/想知道您是否可以在 SQL 数据库项目中进行特定于环境的编码,特别是在PostDeploymentScript.sql

I know it would be possible to add SQL server environmental-specific code in the.sql file but I was wondering more along the lines of how you would do a C# compile-time statement, such as #if DEBUG { } ?我知道可以在 .sql 文件中添加 SQL 服务器特定环境代码,但我想知道更多关于如何执行 C# 编译时语句,例如#if DEBUG { }

This would be, say, if a DEBUG configuration had values differing from RELEASE but were the same no matter what SQL Server it were being deployed to.这就是说,如果 DEBUG 配置的值与 RELEASE 不同,但无论它被部署到哪个 SQL 服务器,它们都是相同的。

Here's a mock-up example of what it would look like in my head, if it worked这是一个模型示例,如果它有效,它在我脑海中的样子

It appears that SSDT does provide functionality for customising deployments, by the means of DeploymentPlanModifier extensions. SSDT 似乎确实通过DeploymentPlanModifier扩展提供了自定义部署的功能。 Here might be a good starting point to delve into the subject. 这可能是深入研究该主题的良好起点

After briefly skimming through the help topic, however, I have a suspicion that this particular functionality is only available if you use DACPAC deployment for your projects.然而,在简要浏览了帮助主题之后,我怀疑只有在您的项目中使用 DACPAC 部署时才能使用此特定功能。 It might not work if your preferred deployment method is the generation of change scripts via the Schema Compare tool.如果您首选的部署方法是通过架构比较工具生成更改脚本,则它可能不起作用。 That, and the amount of C# code that needs to be written is, how shall I put this, looks almost prohibitive.那,还有需要写的C#的代码量,怎么说呢,看着都让人望而却步。

Barring that, the simplest solution I see is to use a dedicated SQLCMD variable which would control the deployment logic.除此之外,我看到的最简单的解决方案是使用专用的 SQLCMD 变量来控制部署逻辑。 However, that means you and your team would have to change its value before any deployment to an environment other than the default.但是,这意味着您和您的团队必须在将任何部署到默认环境以外的环境之前更改其值。 Unless you will find a way to completely automate this process, eventually people will start making mistakes.除非你能找到一种方法来完全自动化这个过程,否则最终人们会开始犯错误。

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

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