我想让我的数据库处于版本控制之下。

我总是希望在那里至少有一些数据(如alumb提到的:用户类型和管理员)。我还经常需要大量生成的测试数据来进行性能度量。

如何对数据库应用版本控制?


当前回答

我还使用了数据库中通过数据库扩展属性家族存储的一个版本的过程。我的应用程序有脚本的每个版本的步骤(即。从1.1移动到1.2)。部署时,它会查看当前版本,然后逐个运行脚本,直到到达最后一个应用程序版本。没有脚本有直接的“最终”版本,即使部署在干净的DB上也会通过一系列升级步骤进行部署。

Now what I like to add is that I've seen two days ago a presentation on the MS campus about the new and upcoming VS DB edition. The presentation was focused specifically on this topic and I was blown out of the water. You should definitely check it out, the new facilities are focused on keeping schema definition in T-SQL scripts (CREATEs), a runtime delta engine to compare deployment schema with defined schema and doing the delta ALTERs and integration with source code integration, up to and including MSBUILD continuous integration for automated build drops. The drop will contain a new file type, the .dbschema files, that can be taken to the deployment site and a command line tool can do the actual 'deltas' and run the deployment. I have a blog entry on this topic with links to the VSDE downloads, you should check them out: http://rusanu.com/2009/05/15/version-control-and-your-database/

其他回答

因为我们的应用程序必须跨多个rdbms工作,所以我们使用与数据库无关的Torque格式(XML)将模式定义存储在版本控制中。我们还以以下XML格式对数据库的引用数据进行版本控制(其中“关系”是其中一个引用表):

  <Relationship RelationshipID="1" InternalName="Manager"/>
  <Relationship RelationshipID="2" InternalName="Delegate"/>
  etc.

然后,我们使用自己开发的工具来生成从数据库版本X到版本X + 1所需的模式升级和引用数据升级脚本。

您还可以考虑迁移解决方案。它们允许您在c#代码中指定数据库模式,并使用MSBuild上下滚动数据库版本。

我目前正在使用DbUp,它工作得很好。

这是一个非常古老的问题,然而,许多人甚至现在都在试图解决这个问题。他们所要做的就是研究Visual Studio数据库项目。没有这一点,任何数据库开发看起来都很薄弱。从代码组织到部署再到版本控制,它简化了一切。

典型的解决方案是根据需要转储数据库并备份这些文件。

根据您的开发平台,可能会有可用的开源插件。编写自己的代码来完成这个任务通常是相当简单的。

注意:您可能希望备份数据库转储,而不是将其放入版本控制中。在版本控制中,文件可能会迅速变大,并导致整个源代码控制系统变慢(我正在回忆CVS的恐怖故事)。

我写了这个应用程序一段时间前,http://sqlschemasourcectrl.codeplex.com/,它会扫描你的MSFT SQL db的经常你想,并自动转储你的对象(表,视图,procs,函数,SQL设置)到SVN。效果非常好。我把它和unduddle一起使用(它可以让我在签到时收到提醒)