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 数据库置于版本控制之下?
基础教程推荐
- MySQL根据从其他列分组的值,对两列之间的值进行求和 2022-01-01
- 带更新的 sqlite CTE 2022-01-01
- 带有WHERE子句的LAG()函数 2022-01-01
- MySQL 5.7参照时间戳生成日期列 2022-01-01
- 从字符串 TSQL 中获取数字 2021-01-01
- 使用 VBS 和注册表来确定安装了哪个版本和 32 位 2021-01-01
- 如何在 CakePHP 3 中实现 INSERT ON DUPLICATE KEY UPDATE aka upsert? 2021-01-01
- ORA-01830:日期格式图片在转换整个输入字符串之前结束/选择日期查询的总和 2021-01-01
- CHECKSUM 和 CHECKSUM_AGG:算法是什么? 2021-01-01
- while 在触发器内循环以遍历 sql 中表的所有列 2022-01-01
