简体   繁体   English

版本控制DDL更改

[英]Version controlling DDL changes

I'm trying to work out the best way to version changes in SQL. 我正在尝试找出SQL版本更改的最佳方法。 I know that there are products like Redgate and Microsoft's SSDT, but equally I'm wondering if a more manual process might make it easier to automate deployments. 我知道有像Redgate和Microsoft的SSDT这样的产品,但是同样地,我想知道是否可以通过更手动的过程来简化自动化部署。

I have the following requirements 我有以下要求

  • Must be able to produce diffs on table structure 必须能够在表格结构上产生差异
  • Must be able to automate changes against the database 必须能够自动对数据库进行更改
  • Must be able to blame changes and view commit comments 必须能够责怪更改并查看提交评论

If I was using Redgate or SSDT, would I need to generate deployment scripts from the current state of the database? 如果我使用Redgate或SSDT,是否需要从数据库的当前状态生成部署脚本?

Currently I'm wondering if placing change scripts and a syncronised create script into git/svn would be the easiest way to deliver this. 目前,我想知道是否将更改脚本和同步创建脚本放入git / svn是最简单的方法。 But the likelyhood of the two getting out of sync make me uneasy. 但是,两个人可能不同步,这让我感到不安。

Keeping change scripts in source control is a pain because to get back to a specific point in time you need to run the base create and then all the change scripts + you have to write manual rollback scripts (if you need them) 将更改脚本保留在源代码管理中是一件很痛苦的事情,因为要回到特定的时间点,您需要运行基本创建,然后运行所有更改脚本,并且必须编写手动回滚脚本(如果需要)

Writing manual change scripts also is a pain as you have to actual write the scripts and well this is the year 2015 so don't do that! 编写手动更改脚本也很麻烦,因为您必须实际编写脚本,而这是2015年,所以不要这样做!

So I would really recommend using either SSDT or redgate, redgate is cool but SSDT is free and also includes design time checking and refactoring so if you do something like renaming a table in SSDT it will generate a sp_rename rather than dropping the first table and creating a new one (which is what the redgate tool would do) 因此,我真的建议您使用SSDT或redgate,redgate很酷,但是SSDT是免费的,并且还包括设计时检查和重构,因此,如果您在SSDT中重命名表,它将生成sp_rename而不是删除第一个表并创建一个新的(这是redgate工具会执行的操作)

Whichever you use there are command line version of the tools to do a compare / deploy when you actually want to release so just have the checked in code show the state you want the database to be in when you do the release. 无论使用哪种工具,都有命令行版本的工具可以在您实际要发布时进行比较/部署,因此签入的代码仅在发布时显示您希望数据库处于的状态。

For your requirements, both redgate and ssdt will do all three (except number 3 which is taken care of by having your database represented by create statements in source control) 根据您的要求,redgate和ssdt都将执行全部三个操作(第3个除外,第3个通过在源代码管理中使用create语句表示数据库来解决)

The only thing you don't mention is static or reference data, to handle this either use the redgate data compare tool or you could possibly use the redgate source control ssms add-in if you are not going to use ssdt which lets you link tables to csv files. 您唯一没有提到的是静态数据或参考数据,可以使用redgate数据比较工具来处理此问题,或者如果您不打算使用ssdt来链接表,则可以使用redgate源代码控制ssms加载项到csv文件。

If you are going to use SSDT then use a post-deploy script and have a merge statement for each table you need to store in source control. 如果要使用SSDT,请使用部署后脚本,并为需要存储在源代码管理中的每个表提供合并语句。

SSDT rocks and really is the way forward for anyone developing T-Sql code (even if they don't realise it yet!) 对于所有开发T-Sql代码的人来说,SSDT确实是前进的方向(即使他们还没有意识到!)

Ed 埃德

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

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