如何将数据库放在git(版本控制)下? [英] How can I put a database under git (version control)?

查看:1031
本文介绍了如何将数据库放在git(版本控制)下?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个web应用程序,我需要为一些重大的变化做一个分支,事情是,这些更改需要更改数据库模式,所以我想把整个数据库下git 。

I'm doing a web app, and I need to make a branch for some major changes, the thing is, these changes require changes to the database schema, so I'd like to put the entire database under git as well.

我该怎么办?是否有一个特定的文件夹,我可以保存在一个git存储库?我如何知道哪一个?我如何确保我放置正确的文件夹?

How do I do that? is there a specific folder that I can keep under a git repository? How do I know which one? How can I be sure that I'm putting the right folder?

我需要确定,因为这些更改不向后兼容;

I need to be sure, because these changes are not backward compatible; I can't afford to screw up.

在我的案例中的数据库是PostgreSQL

The database in my case is PostgreSQL

有人建议进行备份,并将备份文件置于版本控制之下,而不是数据库。老实说,我发现真的很难吞咽。

Someone suggested taking backups and putting the backup file under version control instead of the database. To be honest, I find that really hard to swallow.

有更好的方法。

好的,所以没有更好的方法,但我还是不太信服,所以我会改变一下问题:

OK, so there' no better way, but I'm still not quite convinced, so I will change the question a bit:

我想将整个数据库置于版本控制之下,我可以使用什么数据库引擎,以便可以将实际数据库置于版本控制之下,而不是转储?

I'd like to put the entire database under version control, what database engine can I use so that I can put the actual database under version control instead of its dump?

sqlite是git友好的吗?

Would sqlite be git-friendly?

因为这只是开发环境,所以我可以选择我想要的数据库。

Since this is only the development environment, I can choose whatever database I want.

我真正想要的不是跟踪我的发展历史,而是能够从我的新的根本改变分支到当前稳定分支,并且能够例如用当前稳定分支修复一些错误/问题等。这样,当我切换分支,数据库自动变得与我目前的分支兼容。
我真的不在乎真正的数据。

What I really want is not to track my development history, but to be able to switch from my "new radical changes" branch to the "current stable branch" and be able for instance to fix some bugs/issues, etc, with the current stable branch. Such that when I switch branches, the database auto-magically becomes compatible with the branch I'm currently on. I don't really care much about the actual data.

推荐答案

进行数据库转储和版本控制代替。这样它是一个平面文本文件。

Take a database dump, and version control that instead. This way it is a flat text file.

我个人建议你同时保存数据转储和模式转储。这种使用diff的方式很容易看到模式中从修订版本到修订版本的变化。

Personally I suggest that you keep both a data dump, and a schema dump. This way using diff it becomes fairly easy to see what changed in the schema from revision to revision.

如果你做了大的修改,你应该有一个辅助数据库使新模式更改为,而不是触摸旧模式,因为你说你正在分支。

If you are making big changes, you should have a secondary database that you make the new schema changes to and not touch the old one since as you said you are making a branch.

这篇关于如何将数据库放在git(版本控制)下?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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