将 MySQL 数据库置于版本控制之下?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4883735/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 18:38:04  来源:igfitidea点击:

Put MySQL database under version control?

mysqldatabaseversion-control

提问by

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?

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

采纳答案by reko_t

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_versionin 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.

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

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.

请注意,如果您想要双向 db 版本控制(以便您也可以恢复到以前的 db 版本),您也需要为每个版本编写所需的查询。

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

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

回答by VonC

Note that recently (December 2012), you have another option: DBV (DataBase Version)

请注意,最近(2012 年 12 月),您还有另一个选择:DBV(数据库版本)

It is based on this Github project, and is a database version control web application featuring schema management, revision scripts, and more.

它基于这个Github 项目,是一个数据库版本控制 Web 应用程序,具有模式管理、修订脚本等功能。

database schema

数据库模式

回答by Brandon

Check out

查看

Liquibase

Liquibase

http://www.liquibase.org/quickstart

http://www.liquibase.org/quickstart

The idea is this:

这个想法是这样的:

All database changes are stored in a human readable yet trackable form and checked into source control.- Liquibase.orgfront page

所有数据库更改都以人类可读但可跟踪的形式存储,并检查到源代码管理中。- Liquibase.org首页

This is a fantastic piece of software that allows you to version your database, in roughly the same process as the top rated answer, except this wheel has already been written and is ready to roll. I use it at work, it's a fantastic solution. Implement it yourself if you want to learn how it works, but Liquibase works great if you want a tool to get things done.

这是一款出色的软件,可让您对数据库进行版本控制,其过程与评分最高的答案大致相同,只是此轮子已经编写完毕并可以滚动。我在工作中使用它,这是一个很棒的解决方案。如果您想了解它是如何工作的,请自己实施它,但如果您想要一个工具来完成工作,Liquibase 非常有用。

回答by fluminis

You can use the MySQL Workbench tool.

您可以使用MySQL Workbench 工具

The file generated with the modeling tool could esaly be saved under SVN. The tool allows you to synchronise your database with the model in bidirectionnal way.

使用建模工具生成的文件可以很容易地保存在 SVN 下。该工具允许您以双向方式将数据库与模型同步。

回答by Srneczek

Migrations in Laravel- PHP framework seems really useful but there is one big BUT. There is only online tool for designing schema in Laravel ORM language called "Eloquent" (here). So it is still unusable if you need to design and maintain database of some serious project.

Laravel 中的迁移- PHP 框架似乎非常有用,但有一个很大的 BUT。Laravel ORM 语言中只有一个用于设计模式的在线工具,称为“Eloquent”(这里)。所以如果你需要设计和维护一些严肃项目的数据库,它仍然无法使用。

回答by Ganesh Kandu

kdbvmay its helpful its upgrade your mysql database to current latest version from older without tracking change in mysql tables

kdbv可能有助于将您的 mysql 数据库从旧版本升级到当前最新版本,而无需跟踪 mysql 表中的更改