是否有一个版本控制系统用于数据库结构更改? [英] Is there a version control system for database structure changes?

查看:206
本文介绍了是否有一个版本控制系统用于数据库结构更改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我经常遇到以下问题。

我对项目进行了一些更改,需要在数据库中创建新的表或列。我使数据库修改并继续我的工作。通常,我记得写下更改,以便它们可以在实时系统上复制。但是,我不总是记得我改变了什么,我不总是记得写下来。

I work on some changes to a project that require new tables or columns in the database. I make the database modifications and continue my work. Usually, I remember to write down the changes so that they can be replicated on the live system. However, I don't always remember what I've changed and I don't always remember to write it down.

所以,我推动现场系统并得到一个大的,明显的错误,没有 NewColumnX ,ugh。

So, I make a push to the live system and get a big, obvious error that there is no NewColumnX, ugh.

无论这可能不是这种情况的最佳实践,是否有针对数据库的版本控制系统?我不在乎具体的数据库技术。我只想知道是否存在。如果它碰巧使用MS SQL Server,那么很好。

Regardless of the fact that this may not be the best practice for this situation, is there a version control system for databases? I don't care about the specific database technology. I just want to know if one exists. If it happens to work with MS SQL Server, then great.

推荐答案

在Ruby on Rails中, href =http://wiki.rubyonrails.org/rails/pages/UnderstandingMigrations =noreferrer>迁移 - 用于更改数据库的快速脚本。

In Ruby on Rails, there's a concept of a migration -- a quick script to change the database.

您生成一个迁移文件,它具有增加数据库版本的规则(如添加列)和降级版本的规则(如删除列)。每个迁移都被编号,并且一个表会跟踪您当前的数据库版本。

You generate a migration file, which has rules to increase the db version (such as adding a column) and rules to downgrade the version (such as removing a column). Each migration is numbered, and a table keeps track of your current db version.

要向上迁移,请运行一个名为db:迁移,它查看您的版本并应用所需的脚本。您可以以类似的方式迁移。

To migrate up, you run a command called "db:migrate" which looks at your version and applies the needed scripts. You can migrate down in a similar way.

迁移脚本本身保存在版本控制系统中 - 无论何时更改您在新脚本中签入的数据库,任何开发人员都可以应用它将其本地数据库带到最新版本。

The migration scripts themselves are kept in a version control system -- whenever you change the database you check in a new script, and any developer can apply it to bring their local db to the latest version.

这篇关于是否有一个版本控制系统用于数据库结构更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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