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

我总是希望在那里至少有一些数据(如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源代码控制

其他回答

首先,你必须选择适合你的版本控制系统:

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源代码控制

每个推荐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.

你可能想看看Liquibase (http://www.liquibase.org/)。即使您不使用该工具本身,它也能很好地处理数据库变更管理或重构的概念。

我同意ESV的答案,正是出于这个原因,我开始了一个小项目,以帮助维护一个非常简单的文件中的数据库更新,然后可以在一个很长的源代码之外进行维护。它允许对开发人员以及UAT和生产进行轻松的更新。该工具适用于SQL Server和MySQL。

项目的一些特点:

允许模式更改 允许值树填充 允许单独的测试数据插入,例如。UAT 允许回滚选项(不是自动的) 维护对SQL server和MySQL的支持 有能力导入现有的数据库到版本控制与一个简单的命令(SQL server仅…仍在开发MySQL)

请查看代码以获得更多信息。

如果您有一个小型数据库,并且希望对整个数据库进行版本化,那么这个批处理脚本可能会有所帮助。它将MSSQL数据库MDF文件分离、压缩并检入Subversion。

如果您主要想要版本化您的模式,并且只有少量的引用数据,您可以使用SubSonic Migrations来处理它。这样做的好处是您可以轻松地向上或向下迁移到任何特定的版本。