Jhipster实体子生成器:如何创建liquibase DELTA更改日志? [英] Jhipster entity sub generator: How to create liquibase DELTA changelogs?

查看:159
本文介绍了Jhipster实体子生成器:如何创建liquibase DELTA更改日志?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

jhipster --version

5.3.4

我正在评估JHipster,并正在测试它如何处理数据库DDL修改.在测试中,我创建了一个Jhipster项目,然后运行jhipster import-jdl model.jh. JHipster生成了所有集成测试,并且一切看起来都不错.所以我部署到生产中.但是后来我意识到我定义了一组实体之间的错误关系.当我打算声明many-to-one关系时,原始的model.jh文件声明了one-to-many关系.

I'm evaluating JHipster and am testing how it handles database DDL modifications. In my test I created a Jhipster project and then ran jhipster import-jdl model.jh. JHipster generated all the integration test and everything looked good. So I deployed to production. But then I realized that I defined the wrong relationship between a set of entities. The original model.jh file declared a one-to-many relationship when I meant to declare a many-to-one relationship.

为了解决这种关系,我尝试了三种方法.首先,我尝试更正model.jh文件中的关系,然后重新运行jhipster import-jdl.这样就做出了我需要的正确更改,除了它覆盖了liquibase更改日志文件,而不是创建仅包含增量的新更改日志条目.

In order to fix this relationship I tried three approaches. First I tried to correct the relationship in the model.jh file and rerun jhipster import-jdl. This made the correct changes that I need, except that it overwrote the liquibase changelog files instead of creating a new changelog entry containing just the delta.

因此,我还原了该更改,并尝试使用实体子生成器.它也修改了原始变更日志文件,而不是创建增量变更日志文件.因此,我还原了这些更改以尝试另一种方法.

So I reverted that change, and tried to use the entity sub generator. It too modified the original changelog files rather than creating a delta changelog file. So I reverted those changes to try another approach.

我手动对实体进行了更改,然后使用了mvn liquibase:diff.这种方法最接近我需要的方法.它确实创建了一个新的变更日志,而不是更新原始文件.但是,新的变更日志正在尝试改变方式,而不仅仅是与关系相关联的列.它试图更改表中几个不相关列的数据类型.它从现有列中删除了注释/评论.简而言之,它基本上是从头开始重新定义整个表,并进行了比我尝试进行的较小更改所需的更改更多的更改.我最终也恢复了这种方法.

I made the changes to the entities manually, and then used mvn liquibase:diff. This approach came the closest to what I needed. It did create a new changelog rather than updating the original files. But, the new changelog was trying to change way more than just the column associated with the relationship. It was trying to change datatypes on several non-related columns in the table. It removed remarks/comments from existing columns. In short, it was basically redefining the whole table from scratch with way more changes than are necessary for the small change I was trying to make. I ended up reverting on this approach too.

因此,我的问题是,对于那些经验丰富的JHipster和liquibase用户,您如何在已将其实体投入生产后对其进行修改?您是手动创建变更日志,还是有一种自动生成变更日志的好方法?

So, my question is, for those of you who are experienced users of JHipster and liquibase, how to you modify your entities after they have already been in use in production? Do you just create your changelogs manually, or is there a good way to auto generate them?

推荐答案

  1. 在您的JDL中进行更改并导入
  2. 将由实体生成器(包括master.xml)引起的对数据库变更日志文件的更改还原到数据库
  3. 编译Java(Liquibase将检查编译后的代码)并运行命令以生成Liquibase更改日志
    • 行家:./mvnw compile liquibase:diff
    • 等级:./gradlew compileJava liquibaseDiffChangelog -PrunList=diffLog
  1. Make changes in your JDL and import it
  2. Revert the changes to the database changelog files caused by the entity generator (including master.xml)
  3. Compile the Java (Liquibase checks against compiled code) and run the command to generate the Liquibase changelog
    • Maven: ./mvnw compile liquibase:diff
    • Gradle: ./gradlew compileJava liquibaseDiffChangelog -PrunList=diffLog

步骤3-5记录在JHipster的使用数据库"中文档.请注意,这些步骤仅在您在开发人员中使用本地数据库的情况下才有效,而当前不适用于H2.

Steps 3-5 are documented in JHipster's "Using a Database" docs. Note that these steps only work if you are using a local database in dev, it currently does not work with H2.

您可以在Github上的该分支中,将这些步骤视为 /a>.

You can see these steps as commits in this branch on Github.

这篇关于Jhipster实体子生成器:如何创建liquibase DELTA更改日志?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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