如何使用liquibase diffChangeLog和当前的变更日志作为参考(生成增量变更集) [英] how to use liquibase diffChangeLog with the current changelog as reference (to generate incremental change set)

查看:431
本文介绍了如何使用liquibase diffChangeLog和当前的变更日志作为参考(生成增量变更集)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个现有数据库,并已使用 generateChangeLog命令行创建了初始变更日志.效果很好:-)

I have an existing database and have used the generateChangeLog command line to create the initial changelog. This works fine :-)

但是现在我希望开发人员使用他们已经知道/已经使用的所有工具/过程来开发数据库和代码,并使用脚本来生成适当的任何增量更改集.

But now I want the developers to use all the tools/processes they know/use already to develop the database and code and use a script to generate any incremental change sets as appropriate.

也就是说,使用当前的更改日志(属性文件中的changeLogFile)作为基础引用,对开发人员数据库的当前状态(属性文件中的url/用户名/密码)进行比较.

That is: do a diff against the current state of the developer's database (url/username/password in the properties file) using the current changelog (changeLogFile in the properties file) as the base reference.

似乎没有简便的方法-我想出的最好的方法是:

There seems no easy way to do this - the best I've come up with is:

  1. 创建一个新的临时数据库.
  2. 使用liquibase通过覆盖连接URL初始化临时数据库(更改日志中当前包含的内容):liquibase --url=jdbc:mysql://localhost:3306/tempbase update
  3. 使用liquibase通过区分两个数据库来在变更日志中生成变更集: liquibase --referenceUrl=jdbc:mysql://localhost:3306/tempbase --referenceUsername=foo --referencePassword=baz diffChangeLog
  4. 删除临时数据库.
  5. 同步变更集:liquibase changelogSync
  1. Create a new temporary database.
  2. Use liquibase to initialise the temp database (to what is currently in the changelog) by overriding the connection url: liquibase --url=jdbc:mysql://localhost:3306/tempbase update
  3. Use liquibase to generate a changeset in the changelog by diff'ing the two databases: liquibase --referenceUrl=jdbc:mysql://localhost:3306/tempbase --referenceUsername=foo --referencePassword=baz diffChangeLog
  4. Drop the temporary database.
  5. Synchronise the changeset: liquibase changelogSync

但是必须有更好的方法...

but there must be a better way...

推荐答案

您是正确的,liquibase无法将变更日志文件与数据库进行比较.唯一的真实选择是将您的开发人员数据库与一个实际的liquibase管理的数据库进行比较,或者至少一个临时创建的数据库进行比较.

You are right that liquibase cannot compare a changelog file with a database. The only real option is to compare your developer database with an actual liquibase-managed database, or at least one temporarily created.

我建议的更好的方法是首先考虑将开发人员转移到编写liquibase changeSets.它与他们以前使用的工具不同,但是它具有巨大的优势,他们将知道他们想要进行的更改是一种可以一直进行到生产的更改.任何基于diff的过程(例如使用diffChangeLog)通常都会正确猜测更改的内容,但并非总是如此,而且这些差异通常要等到生产后才能发现.

What I would suggest as the better way is to consider shifting the developers to author liquibase changeSets in the first place. It is different tooling than they may be used to, but it has the huge advantage that they will know that the change they wanted to make is the one that will make it all the way to production. Any diff-based process (such as using diffChangeLog) will usually guess right about what changed, but not always and those differences are often not noticed until into production.

Liquibase具有各种功能,例如格式化的SQL更改日志,旨在进行过渡从直接针对他们的数据库的开发人员到通过Liquibase跟踪更改,因为一旦进行了这种转换,许多事情就会变得容易得多.

Liquibase has various features such as formatted SQL changelogs that are designed to make the transition from developers working directly against their database to tracking changes through Liquibase because once that transition is made many things get much easier.

这篇关于如何使用liquibase diffChangeLog和当前的变更日志作为参考(生成增量变更集)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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