从版本化mysql模式开始,没有过多的技巧.好的解决方案? [英] Starting with versioning mysql schemata without overkill. Good solutions?

查看:107
本文介绍了从版本化mysql模式开始,没有过多的技巧.好的解决方案?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经意识到必须开始对数据库模式进行版本控制和更改.因此,我阅读了SO上有关该主题的现有文章,但不确定如何进行.

I've arrived at the point where I realise that I must start versioning my database schemata and changes. I consequently read the existing posts on SO about that topic but I'm not sure how to proceed.

我基本上是一个单人公司,不久前我甚至没有为我的代码使用版本控制.我在Windows环境中,使用Aptana(IDE)和SVN(带有Tortoise).我从事PHP/mysql项目.

I'm basically a one man company and not long ago I didn't even use version control for my code. I'm on a windows environment, using Aptana (IDE) and SVN (with Tortoise). I work on PHP/mysql projects.

什么是有效且充分(绝不过度)版本数据库模式的方法?

What's a efficient and sufficient (no overkill) way to version my database schemata?

我在某些项目中确实有一两个自由职业者,但是我不希望进行大量分支和合并.因此,基本上,我想跟踪并发架构到我的代码修订版.

I do have a freelancer or two in some projects but I don't expect a lot of branching and merging going on. So basically I would like to keep track of concurrent schemata to my code revisions.

[edit] 瞬时解决方案:目前,我决定只要提交标签(稳定版本),就将进行模式转储以及一个包含必要初始数据的文件.在现阶段,这对我来说似乎已经足够.[/edit]

[edit] Momentary solution: for the moment I decided I will just make a schema dump plus one with the necessary initial data whenever I'm going to commit a tag (stable version). That seems to be just enough for me at the current stage.[/edit]

[edit2] plus我现在还使用了第三个文件,称为increments.sql,在其中将所有更改与日期等放置在一起,以便于在一个文件中轻松跟踪更改历史记录.我不时将更改集成到其他两个文件中,并清空crements.sql [/edit]

[edit2]plus I'm now also using a third file called increments.sql where I put all the changes with dates, etc. to make it easy to trace the change history in one file. from time to time I integrate the changes into the two other files and empty the increments.sql[/edit]

推荐答案

我认为这个问题值得一个现代的答案,所以我将自己提出.当我在2009年提出问题时,我不认为 Phinx 已经存在,而且肯定是Laravel不存在.

I think this question deserves a modern answer so I'm going to give it myself. When I wrote the question in 2009 I don't think Phinx already existed and most definitely Laravel didn't.

今天,这个问题的答案非常明确:编写增量数据库迁移脚本,每个脚本都具有updown方法,并在安装或更新应用程序时运行所有这些脚本或其中的一个增量.显然,可以将迁移脚本添加到您的VCS中.

Today, the answer to this question is very clear: Write incremental DB migration scripts, each with an up and a down method and run all these scripts or a delta of them when installing or updating your app. And obviously add the migration scripts to your VCS.

正如开头提到的那样,PHP世界中有当今出色的工具,可帮助您轻松管理迁移. Laravel具有内置的DB迁移功能,包括相应的Shell命令.每个人都有一个与Phinx类似的功能强大的框架不可知解决方案.

As mentioned in the beginning, there are excellent tools today in the PHP world which help you manage your migrations easily. Laravel has DB migrations built-in including the respective shell commands. Everyone else has a similarly powerful framework agnostic solution with Phinx.

Artisan迁移(Laravel)和Phinx的工作原理相同.对于数据库中的每个更改,请创建一个新的迁移,使用纯SQL或内置的查询构建器来编写up和down方法并运行artisan migrate resp. phinx migrate在控制台中.

Both Artisan migrations (Laravel) and Phinx work the same. For every change in the DB, create a new migration, use plain SQL or the built-in query builder to write the up and down methods and run artisan migrate resp. phinx migrate in the console.

这篇关于从版本化mysql模式开始,没有过多的技巧.好的解决方案?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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