寻找数据库版本控制的解决方案 [英] Looking for solution for database versioning

查看:43
本文介绍了寻找数据库版本控制的解决方案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题描述:

在我们的项目中,我们有一个生产数据库"和许多开发人员".我们想知道如何管理和安装更改.我们已经有了一些程序,但需要很多时间,有时会导致错误.

In our project we have one "production database" and many "devs". We want to know how we can manage and install the changes. We already have some procedures but it takes a lot of time and sometimes causes errors.

我们不能丢失数据 - 所以我们不能使用删除表".我们只能使用alter table".

We can't lose data - so we can't use "drop table". We can only use "alter table".

我们实际的数据库版本控制程序"是这样的:

Our actual "db versioning procedure" is like this:

  • 我们有一个名为 [actual_version] 的表,其中包含已安装数据库架构的实际版本
  • 我们有一个名为changes_script.sql"的文件,其中包含所有数据库更改 - 该文件存储在 SVN 上

当开发人员想要在 SVN 上提交新修订时,他需要通过添加更改_script.sql一个块:

When a developer wants to commit a new revision on SVN he needs to change_script.sql by adding a block:

if ([acctual_version].version < "23")) {
    --- sql script ----
updateVersionTo("23")
end if 

当我们想要升级数据库架构时,我们只需执行"change_scripts.sql

When we want to upgrade the database schema we just "execute" the change_scripts.sql

有人有更好的主意吗?

推荐答案

Red Gate 的 Sql Compare 工具可以比较两个表(或两个 DDL 脚本集合,或一组脚本到一个表等)并为您生成迁移脚本.

Red Gate's Sql Compare tool can compare two tables (or two collections of DDL scripts, or one set of scripts to a table, etc) and generate the migration script for you.

如果您使用 Ruby,您可以查看Ruby 迁移",这是一种在代码中进行数据库版本控制的正式方式.(.NET 中有类似的东西,例如 RikMigrationsFluent Migrator,我相信其他平台也存在类似的东西).

If you're working in Ruby you can look into "Ruby Migrations", which is a formalized way of doing DB versioning in code. (There are similar things in .NET such as RikMigrations and Fluent Migrator, and I'm sure similar things exist for other platforms as well).

正如 Randy Minder 所说,您也可以使用 VS DB 版本为您管理架构,尽管我认为 RedGate 工具工作起来同样简单,并且不会将您绑定到特定平台或 IDE.

As Randy Minder said, you can also use VS DB Edition to manage your schema for you, although I think the RedGate tools work just as easily and don't tie you to a specific platform or IDE.

这篇关于寻找数据库版本控制的解决方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆