Put MySQL database under version control?(将 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 数据库置于版本控制之下?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:将 MySQL 数据库置于版本控制之下?


基础教程推荐
- 如何在 SQL 中将 Float 转换为 Varchar 2021-01-01
- MySQL 中的类型:BigInt(20) 与 Int(20) 2021-01-01
- oracle区分大小写的原因? 2021-01-01
- 在多列上分布任意行 2021-01-01
- 表 './mysql/proc' 被标记为崩溃,应该修复 2022-01-01
- 二进制文件到 SQL 数据库 Apache Camel 2021-01-01
- 什么是 orradiag_<user>文件夹? 2022-01-01
- mysql选择动态行值作为列名,另一列作为值 2021-01-01
- 在 MySQL 中:如何将表名作为存储过程和/或函数参数传递? 2021-01-01
- 如何根据该 XML 中的值更新 SQL 中的 XML 2021-01-01