简体   繁体   English

跟踪数据库结构中的更改

[英]tracking changes made in database structure

How would I be able to track all changes to my database? 我如何能够跟踪数据库的所有更改?

I need a way to find out exactly what changes I made to the database so that I can make the same changes on another server. 我需要一种方法来确切地了解我对数据库所做的更改,以便我可以在另一台服务器上进行相同的更改。

For example, if I added a new field in one of the tables, I would like to know what field that was so that I could add that same field to another database. 例如,如果我在其中一个表中添加了一个新字段,我想知道是什么字段,以便我可以将该字段添加到另一个数据库。

The steps people usually go through when facing these problems are: 人们在面对这些问题时经常采取的步骤是:

  1. Change the development db in whatever way is needed at the time. 以当时需要的任何方式更改开发数据库。

  2. Ready to deploy a new version of the application - realize the production database needs to be updated as well while retaining the data. 准备部署新版本的应用程序 - 实现生产数据库也需要在保留数据的同时进行更新。

  3. Dump the production and development schema, manually diff the schema creation scripts. 转储生产和开发模式,手动区分模式创建脚本。 Bang head against wall. 砰地靠在墙上。 Write change scripts that updates the production database. 编写更新生产数据库的更改脚本。

  4. Realize the change scripts needs to be written from the start when updating the development database instead of willy-nilly add and change stuff. 实现更改脚本需要在更新开发数据库时从头开始编写,而不是无所不知地添加和更改内容。

  5. Find a naming scheme for versioning those change scripts so any installation can be updated from a given version to a newer version. 查找用于对这些更改脚本进行版本控制的命名方案,以便可以将任何安装从给定版本更新为更新版本。

  6. place the DB creation and change scripts in source control. 将数据库创建和更改脚本放在源代码管理中。

Make sure you're not repeating 1-3 every time, but get around to do 4-6 so you don't have to repeat 1-3 every time. 确保你不是每次都重复1-3次,而是四处走动,这样你就不必每次都重复1-3次。

Take a look at LiquiBase 看看LiquiBase吧

It allows you to describe database changes as XML so you can maintain your database structure in your VCS just like your code. 它允许您将数据库更改描述为XML,因此您可以像在代码中一样在VCS中维护数据库结构。

A non-automated but useful way to keep track of changes to a db is with the MySQL Query Browser . MySQL查询浏览器是一种非自动但有用的跟踪数据库更改的方法。 It keeps a history of all operations you run while using it. 它保留了您在使用它时运行的所有操作的历史记录。 This makes assembling a change script very straightforward. 这使得组装更改脚本非常简单。

Obviously, this is not a solution if you're looking to replicate all changes made by all users. 显然,如果您希望复制所有用户所做的所有更改,则这不是解决方案。 But if you are just looking to keep a set of changes in the correct order and avoid retyping them, it works pretty well. 但是,如果您只是想以正确的顺序保留一组更改并避免重新输入它们,那么它的效果非常好。

Have you considered using MySQL Replication to do this? 您是否考虑过使用MySQL Replication来执行此操作? You really don't want to implement this yourself unless you have to for some reason. 你真的不想自己实现这个,除非你出于某种原因。

phpmyadmin had a GSoC project involving replication this summer by Tomas Srnka. phpmyadmin今年夏天有一个涉及复制的GSoC项目,由Tomas Srnka完成。 i think it made it's way to trunk already 我认为它已经成为了行李箱的方式

there is many tools to make data compare : - Database Worbench - EMS sql manager - SQL Maestro - Database comparer 有许多工具可以进行数据比较: - Database Worbench - EMS sql manager - SQL Maestro - 数据库比较器

but this tools can also be used for creating update script 但是这个工具也可以用于创建更新脚本

我一直在网上阅读有关模式的信息,这是比较数据库和查找任何更改的有用方法吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM