我想让我的数据库处于版本控制之下。
我总是希望在那里至少有一些数据(如alumb提到的:用户类型和管理员)。我还经常需要大量生成的测试数据来进行性能度量。
如何对数据库应用版本控制?
我想让我的数据库处于版本控制之下。
我总是希望在那里至少有一些数据(如alumb提到的:用户类型和管理员)。我还经常需要大量生成的测试数据来进行性能度量。
如何对数据库应用版本控制?
当前回答
在Red Gate,我们提供了一个工具,SQL Source Control,它使用SQL Compare技术将数据库与TFS或SVN存储库链接起来。该工具集成到SSMS中,让您像往常一样工作,只是现在允许提交对象。
对于基于迁移的方法(更适合于自动化部署),我们提供了SQL Change Automation(以前称为ReadyRoll),它作为Visual Studio项目创建和管理一组增量脚本。
在SQL源代码控制中,可以指定静态数据表。它们作为INSERT语句存储在源代码控制中。
如果您正在讨论测试数据,我们建议您要么使用工具生成测试数据,要么通过您定义的部署后脚本生成测试数据,要么简单地将生产备份恢复到开发环境。
其他回答
使用更改脚本将数据库脚本保存到版本控制中是一种好方法,这样您就可以升级您拥有的任何一个数据库。此外,您可能希望保存不同版本的模式,这样就可以创建完整的数据库,而不必应用所有的更改脚本。处理脚本应该是自动化的,这样您就不必做手工工作了。
我认为为每个开发者提供一个独立的数据库,而不是使用一个共享的数据库是很重要的。这样,开发人员就可以独立于其他开发人员创建测试用例和开发阶段。
自动化工具应该具有处理数据库元数据的方法,这些元数据可以告诉您哪些数据库处于何种开发状态,哪些表包含版本可控数据等等。
每个推荐RedGate工具的人都要加1分,还有额外的建议和警告。
SqlCompare also has a decently documented API: so you can, for instance, write a console app which syncs your source controlled scripts folder with a CI integration testing database on checkin, so that when someone checks in a change to the schema from their scripts folder it's automatically deployed along with the matching application code change. This helps close the gap with developers who are forgetful about propagating changes in their local db up to a shared development DB (about half of us, I think :) ).
A caveat is that with a scripted solution or otherwise, the RedGate tools are sufficiently smooth that it's easy to forget about SQL realities underlying the abstraction. If you rename all the columns in a table, SqlCompare has no way to map the old columns to the new columns and will drop all the data in the table. It will generate warnings but I've seen people click past that. There's a general point here worth making, I think, that you can only automate DB versioning and upgrade so far - the abstractions are very leaky.
在VS 2010中,使用数据库项目。
脚本化数据库 对脚本或直接进行更改 您的db服务器 使用数据>同步 模式比较
使一个完美的DB版本解决方案,并使同步DB的微风。
我建议使用比较工具为您的数据库临时设计一个版本控制系统。两个好的替代方案是xSQL模式比较和xSQL数据比较。
现在,如果您的目标是只对数据库的模式进行版本控制,那么您可以简单地使用xSQL schema Compare来生成模式的xSQL快照,并在版本控制中添加这些文件。然后,要恢复或更新到特定版本,只需将数据库的当前版本与目标版本的快照进行比较。
Also, if you want to have the data under version control as well, you can use xSQL Data Compare to generate change scripts for you database and add the .sql files in your version control. You could then execute these scripts to revert / update to any version you want. Keep in mind that for the 'revert' functionality you need to generate change scripts that, when executed, will make Version 3 the same as Version 2 and for the 'update' functionality, you need to generate change scripts that do the opposite.
最后,通过一些基本的批处理编程技能,您可以使用命令行版本的xSQL Schema Compare和xSQL Data Compare来自动化整个过程
免责声明:我隶属于xSQL。
典型的解决方案是根据需要转储数据库并备份这些文件。
根据您的开发平台,可能会有可用的开源插件。编写自己的代码来完成这个任务通常是相当简单的。
注意:您可能希望备份数据库转储,而不是将其放入版本控制中。在版本控制中,文件可能会迅速变大,并导致整个源代码控制系统变慢(我正在回忆CVS的恐怖故事)。