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

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

问题描述

我经常遇到以下问题.

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

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,呃.

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 中,有一个 migration -- 更改数据库的快速脚本.

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

你生成一个迁移文件,里面有增加db版本的规则(比如增加一个列)和降级版本的规则(比如删除一个列).每次迁移都有编号,并有一个表格记录您当前的数据库版本.

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:migrate"的命令,该命令会查看您的版本并应用所需的脚本.您可以通过类似的方式向下迁移.

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天全站免登陆