Can Flyway or Liquibase generate an update script instead of updating the database directly?

前端 未结 5 1073
难免孤独
难免孤独 2020-12-31 04:14

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

5条回答
  •  误落风尘
    2020-12-31 04:29

    What you want is a schema diff tool. I remember hearing that TOAD has a rather powerful one. Hibernate will also try to generate schema update scripts based on the entities it detects and the database metadata.

    However what you need is... to not do that and instead use Flyway to make all your database changes. That is you should turn of Hibernates automatic schema updates and write the schema updates yourself going forward. Every time you want to make a change to the database you have to write a schema update.

    Some people capture the SQL output of how hibernates schema update as a way of getting automated schema evolution updates. The problem is that hibernate is typically wrong especially if add a @NotNull column.

    Also in terms of your admin I believe Flyway can output based on its schema_version table and the SQL/Java migration scripts the SQL output it will run thus your DBA could run it outside of Flyway (If it doesn't this would be an easy feature to add).

提交回复
热议问题