Flyway或Liquibase可以生成更新脚本,而不是直接更新数据库吗? [英] Can Flyway or Liquibase generate an update script instead of updating the database directly?

查看:184
本文介绍了Flyway或Liquibase可以生成更新脚本,而不是直接更新数据库吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,有一点背景。我有一套Java应用程序,一些基于JPA,一些不是。要创建我的数据库,我正在使用Hibernates模式导出为使用JPA的用户生成创建脚本。那些不使用JPA我手动生成脚本。然后在使用ANT安装应用程序时运行这些程序。对于更新,应用程序安装程序只需将更新脚本应用于数据库。



为了改进数据库更新的管理,我一直在寻找Flyway和Liquibase。两者似乎都差不多要做我想做的事情(旁白:因为我们有所有已有的SQL / DDL脚本,所以我现在更喜欢Flyway)。我能看到的问题是它们都直接更新数据库。这对很多安装都很好,但不是全部。

我想要对数据库运行Flyway / Liquibase并生成一个更新脚本,该脚本合并了使数据库保持最新所需的所有更新 - 包括任何Flyway / Liquibase需要对自己的桌子进行更改。这将允许我(或更重要的是数据库管理员)在应用程序之外运行更新脚本来更新数据库。然后,我可以在我的应用程序中使用Flyway / Liquibase纯粹验证数据库是最新的。



是否可以使用Flyway或Liquibase或任何其他工具为什么?

解决方案

  • Liquibase处理它相当好。它以当前状态查看数据库,发现未应用的更改集并在 update 命令生成SQL脚本sql_output> sql输出模式



    使用适当的数据库迁移工具而不是Hibernate生成器是无论如何,最终会出现Hibernate不支持的情况。对于我们来说,它正在放弃一个独特的索引并用另一个索引替代它您还可以启用 hibernate.hbm2ddl.auto = validate ,以确保数据库结构和实体bean之间的兼容性。


    First, a little background. I have a set of Java applications, some based on JPA, some not. To create my databases I am currently using Hibernates schema export to generate create scripts for those using JPA. Those not using JPA I generate the scripts by hand. These are then run during application installation using ANT. For updates the application installer simply applies update scripts to the database.

    To improve the management of database updates I have been looking at Flyway and Liquibase. Both seem to almost do what I want, (aside: I am preferring Flyway at the moment because of all the pre-existing SQL/DDL scripts we have). The issue I can see is that they both update the database directly. This is fine for a lot of installations but not all.

    What I would like to do is run Flyway/Liquibase against the database and generate an update script that incorporates all the updates needed to bring the database up to date - including any changes Flyway/Liquibase needs to make to its own tables. This would allow me (or more importantly a database admin) to run the update script outside of the application(s) to update the database. I could then use Flyway/Liquibase within my application purely to verify that the database is up to date.

    Is it possible to do this with Flyway or Liquibase or any other tool for that matter?

    解决方案

    Liquibase handles it quite fine. It looks at your database at the current state, finds unapplied changesets and generates an SQL script with update command in sql output mode.

    Using a proper database migration tool instead of Hibernate generator is the way to go in any case, sooner or later you'll end up with a situation that Hibernate does not support. For us it was dropping an unique index and replacing it with another. You can also enable hibernate.hbm2ddl.auto=validate to feel safe about the compatibility between database structure and entity beans.

    这篇关于Flyway或Liquibase可以生成更新脚本,而不是直接更新数据库吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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