我想让我的数据库处于版本控制之下。
我总是希望在那里至少有一些数据(如alumb提到的:用户类型和管理员)。我还经常需要大量生成的测试数据来进行性能度量。
如何对数据库应用版本控制?
我想让我的数据库处于版本控制之下。
我总是希望在那里至少有一些数据(如alumb提到的:用户类型和管理员)。我还经常需要大量生成的测试数据来进行性能度量。
如何对数据库应用版本控制?
当前回答
首先,你必须选择适合你的版本控制系统:
Centralized Version Control system - a standard system where users check out/check in before/after they work on files, and the files are being kept in a single central server Distributed Version Control system - a system where the repository is being cloned, and each clone is actually the full backup of the repository, so if any server crashes, then any cloned repository can be used to restore it After choosing the right system for your needs, you'll need to setup the repository which is the core of every version control system All this is explained in the following article: http://solutioncenter.apexsql.com/sql-server-source-control-part-i-understanding-source-control-basics/
在建立了存储库之后,如果有一个中央版本控制系统,那么就有一个工作文件夹,您可以阅读本文。它展示了如何在开发环境中使用以下命令来设置源代码控制:
通过MSSCCI提供的SQL Server Management Studio, Visual Studio和SQL Server数据工具 一个第三方工具ApexSQL源代码控制
其他回答
不久前,我发现了一个VB bas模块,它使用DMO和VSS对象将整个db脚本删除并转换为VSS。我把它变成了一个VB脚本,并张贴在这里。您可以很容易地取出VSS调用并使用DMO东西来生成所有脚本,然后从调用VBScript的同一个批处理文件调用SVN来检入它们。
版本控制数据库的另一种选择是使用版本控制数据库,现在有几个这样的数据库。
https://www.dolthub.com/blog/2021-09-17-database-version-control/
这些产品没有在其他类型的数据库上应用版本控制——它们是自己的数据库引擎,支持版本控制操作。因此,您需要迁移到它们,或者在它们的基础上开始构建。
我编写了其中一个,DoltDB,它结合了MySQL和Git的接口。看看这里:
https://github.com/dolthub/dolt
我还使用了数据库中通过数据库扩展属性家族存储的一个版本的过程。我的应用程序有脚本的每个版本的步骤(即。从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/
典型的解决方案是根据需要转储数据库并备份这些文件。
根据您的开发平台,可能会有可用的开源插件。编写自己的代码来完成这个任务通常是相当简单的。
注意:您可能希望备份数据库转储,而不是将其放入版本控制中。在版本控制中,文件可能会迅速变大,并导致整个源代码控制系统变慢(我正在回忆CVS的恐怖故事)。
这是围绕发展的“难题”之一。据我所知,没有完美的解决方案。
如果只需要存储数据库结构而不需要存储数据,则可以将数据库导出为SQL查询。(在企业管理器中:右键单击数据库->生成SQL脚本。我建议在选项卡上设置“每个对象创建一个文件”),然后您可以将这些文本文件提交到svn,并使用svn的diff和日志功能。
我将此与一个Batch脚本绑定在一起,该脚本采用一对参数并设置数据库。我还添加了一些额外的查询,输入默认数据,如用户类型和管理用户。(如果你想要更多关于这方面的信息,张贴一些东西,我可以把脚本放在可以访问的地方)
如果你需要保留所有的数据,我建议保留一个数据库备份,并使用Redgate (http://www.red-gate.com/)产品进行比较。它们并不便宜,但它们值每一分钱。