将MySQL数据库置于版本控制之下? [英] Put MySQL database under version control?

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

问题描述

我目前正在为我的PHP项目使用SVN。我想我应该让我的数据库在版本控制下,但什么是最好的方法呢?我只是在SVN的项目中创建一个db文件夹,将SQL更改粘贴到一个名为from_1.0_to_2.0.sql的文件并提交?

I'm currently using SVN for my PHP projects. I was thinking I should get my database under version control too, but what's the best way to do that? Do I just make a db-folder in my project in SVN, paste SQL changes into a file called from_1.0_to_2.0.sql and commit?

推荐答案

无论何时对数据库进行更改,都应在迁移中保存这些更改,以便稍后在更新代码的同时在其他服务器上运行。但你基本上有正确的想法。您可以编写一些工具,使其更自动化;例如版本每个文件,然后在您的数据库中创建一个表如 migration_version ,它将包含数据库的当前版本。然后,您可以创建一个迁移脚本,该脚本将运行使数据库更新所需的所有迁移。

Whenever you make changes to your database, you should save those changes in a migration, that you can then later on run on other servers at the same time you update your code. But you basically got the right idea. You can write some tools to make it more automated; for example version each file, and then create a table like migration_version in your database, which will contain the current version of the database. You can then create a migrate script that will run all the migrations required to get the database up-to-date.

请注意,如果要双向数据库版本控制所以你可以还原到以前的数据库版本),你需要为每个版本写入所需的查询。

Note that if you want bi-directional db versioning (so that you can revert back to previous db version too), you need to write the required queries for that too for each version.

还有一些工具,可以帮助您可以书写迁移,例如 MySQLdiff

There are also some tools that can aid you in writing the migrations, such as MySQLdiff

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

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