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

查看:32
本文介绍了如何将数据库置于 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天全站免登陆