简体   繁体   English

最好的git mysql版本系统?

[英]Best git mysql versioning system?

I've started using git with a small dev team of people who come and go on different projects; 我已经开始使用git和一个小型开发团队来进行不同的项目; it was working well enough until we started working with Wordpress. 它工作得很好,直到我们开始使用Wordpress。 Because Wordpress stores a lot of configurations in MySQL, we decided we needed to include that in our commits. 因为Wordpress在MySQL中存储了很多配置,所以我们决定在提交中包含它。

This worked well enough (using msyql dump on pre-commits, and pushing the dumped file into mysql on post-checkout) until two people made modifications to plugins and committed, then everything broke again. 这很好用(在预提交时使用msyql dump,并在post-checkout上将转储的文件推送到mysql),直到两个人对插件进行修改并提交,然后一切都再次破坏。

I've looked at every solution I could find, and thought Liquibase was the closest option, but wouldn't work for us. 我看过我能找到的每一个解决方案,并认为Liquibase是最接近的选择,但对我们不起作用。 It requires you to specify schema in XML, which isn't really possible because we are using plugins which insert data/tables/modifications automatically into the DB. 它要求您在XML中指定模式,这实际上是不可能的,因为我们使用的插件会自动将数据/表/修改插入到数据库中。
I plan on putting a bounty on it in a few days to see if anyone has the "goldilocks solution" of: 我计划在几天内给它一个赏金,看看是否有人有以下的“金发女郎解决方案”:

The question: 问题:
Is there a way to version control a MySQL database semantically (not using diffs EDIT: meaning that it doesn't just take the two versions and diff it, but instead records the actual queries run in sequence to get from the old version to the current one) without the requirement of a developer written schema file, and one that can be merged using git. 有没有办法在语义上对MySQL数据库进行版本控制(不使用diffs EDIT:意味着它不仅仅采用两个版本并对其进行区分,而是记录按顺序运行的实际查询以从旧版本到当前版本一)没有开发人员编写的模式文件的要求,以及可以使用git合并的文件。

I know I can't be the only one with such a problem, but hopefully there is somebody with a solution? 我知道我不可能是唯一一个有这样问题的人,但希望有人有解决方案吗?

The proper way to handle db versioning is through a version script which is additive-only. 处理数据库版本控制的正确方法是通过仅添加的版本脚本。 Due to this nature, it will conflict all the time as each branch will be appending to the same file. 由于这种性质,它将一直冲突,因为每个分支将附加到同一文件。 You want that. 你想要那个。 It makes the developers realize how each others' changes affect the persistence of their data. 它使开发人员意识到彼此的更改如何影响其数据的持久性。 Rerere will ensure you only resolve a conflict once though. Rerere将确保您只解决一次冲突。 (see my blog post that touches on rerere sharing: http://dymitruk.com/blog/2012/02/05/branch-per-feature/ ) (请参阅我的博客文章,其中涉及到rerere共享: http//dymitruk.com/blog/2012/02/05/branch-per-feature/

Keep wrapping each change within a if then clause that checks the version number, changes the schema or modifies lookup data or something else, then increments the version number. 继续将每个更改包装在if then子句中,该子句检查版本号,更改架构或修改查找数据或其他内容,然后增加版本号。 You just keep doing this for each change. 你只是为每次改变都这样做。

in psuedo code, here is an example. 在psuedo代码中,这是一个例子。

if version table doesn't exist
  create version table with 1 column called "version"
  insert the a row with the value 0 for version
end if
-- now someone adds a feature that adds a members table
if version in version table is 0
  create table members with columns id, userid, passwordhash, salt
    with non-clustered index on the userid and pk on id
  update version to 1
end if
-- now some one adds a customers table
if version in version table is 1
  create table customers with columns id, fullname, address, phone
    with non-clustered index on fullname and phone and pk on id
  update version to 2
end if
-- and so on

The benefit of this is that you can automatically run this script after a successful build of your test project if you're using a static language - it will always roll you up to the latest. 这样做的好处是,如果您使用的是静态语言,则可以在成功构建测试项目后自动运行此脚本 - 它始终会将您推送到最新版本。 All acceptance tests should pass if you just updated to the latest version. 如果您刚刚更新到最新版本,所有验收测试都应该通过。

The question is, how do you work on 2 different branches at the same time? 问题是,你如何在两个不同的分支机构同时工作? What I have done in the past is just spun up a new instance that's delimited in the db name by the branch name. 我过去所做的只是创建一个新的实例,该实例在分支名称的db名称中分隔。 Your config file is cleaned (see git smudge/clean) to set the connection string to point to the new or existing instance for that branch. 您的配置文件已清除(请参阅git smudge / clean)以将连接字符串设置为指向该分支的新实例或现有实例。

If you're using an ORM, you can automate this script generation as, for example, nhibernate will allow you to export the graph changes that are not reflected in the db schema yet as a sql script. 如果您正在使用ORM,则可以自动生成此脚本,例如,nhibernate将允许您将未在db模式中反映的图形更改导出为sql脚本。 So if you added a mapping for the customer class, NHibernate will allow you to generate the table creation script. 因此,如果您为客户类添加了映射,NHibernate将允许您生成表创建脚本。 You just script the addition of the if-then wrapper and you're automated on the feature branch. 您只需添加if-then包装器的脚本,然后在功能分支上自动执行。

The integration branch and the release candidate branch have some special requirements that will require wiping and recreating the db if you are resetting those branches. 集成分支和发布候选分支有一些特殊要求,如果要重置这些分支,则需要擦除和重新创建数据库。 That's easy to do in a hook by ensuring that the new revision git branch --contains the old revision. 通过确保新版本的git branch --contains旧版本,在钩子中很容易做到。 If not, wipe and regenerate. 如果没有,擦拭并再生。

I hope that's clear. 我希望这很清楚。 This has worked well in the past and requires the ability for each developer to create and destroy their own instances of dbs on their machines, although could work on a central one with additional instance naming convention. 这在过去运行良好,并且需要每个开发人员能够在他们的机器上创建和销毁他们自己的dbs实例,尽管可以在具有附加实例命名约定的中央实例上工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM