jhipster - 使用 JDL 修改 JHipster 实体的正确过程

标签 jhipster liquibase jdl

我正在使用 Monolith 和基于磁盘的 H2 数据库试用 JHipster(版本 6.4.1)。我在 JDL 中创建了一些实体,并使基本的 CRUD 网页正常工作。现在我对这个过程感到满意,我想添加字段并重命名其他字段。我想我可以简单地更新 JDL,重新导入 JDL,启动应用程序,然后查看更改的结果。我看到的是 ValidationFailedException来自 Liquibase 和应用程序由于数据库问题抛出 HTTP 500 错误。

我到处寻找有关处理这种看似常见的开发场景的正确流程的指导。我寻找指南的大部分地方(例如 https://www.jhipster.tech/creating-an-entity)都讨论将 JDL 导入为一次性操作,而不讨论如何逐步更改和导入 JDL。

我已经尝试了一些在 SO 上看到的建议,例如不覆盖更改日志,执行 liquibase:diff ,并将其添加到 master.xml .这仍然会导致 ValidationFailedException .在master.xml我看到评论 <!-- jhipster-needle-liquibase-add-changelog - JHipster will add liquibase changelogs here -->这让我相信 JHipster 应该承担繁重的工作,但我只是错过了一步。

我绝不是 JHipster 或 Liquibase 专家,但我想学习。我如何才能毫不费力地执行简单的实体更新?

[更新更多细节]

重新导入更新后的 JDL 后,我通过使用 rm -rf target/h2db/db 清除数据库成功地消除了数据库验证错误。 .

我对我的更改很满意,感觉提交是有序的。我看到的是

  • master.xml不变
  • 第一个 JDL 导入的变更日志已修改为包含我所做的更新

如果我了解 liquibase 的工作原理,我会预料到

  1. 不会触及任何现有的变更日志
  2. 将创建一个全新的变更日志文件,其中仅包含我在这一轮所做的 JDL 变更
  3. master.xml只是因为它包含一个额外的更改日志条目,指向在第 2 项中创建的文件

我是否误解了 Liquibase 如何表示数据库架构的演变?

最佳答案

您引用的页面似乎包含一些更新实体的说明。 Farther down the page我看到了这个:

Updating an existing entity

The entity configuration is saved in a specific .json file, in the .jhipster directory. So if you run the sub-generator again, using an existing entity name, you can update or regenerate the entity.

When you run the entity sub-generator for an existing entity, you will be asked a question ‘Do you want to update the entity? This will replace the existing files for this entity, all your custom code will be overwritten’ with following options:

  • Yes, re generate the entity - This will just regenerate your entity. Tip: This can be forced by passing a --regenerate flag when running the sub-generator
  • Yes, add more fields and relationships - This will give you questions to add more fields and relationships
  • Yes, remove fields and relationships - This will give you questions to remove existing fields and relationships from the entity
  • No, exit - This will exit the sub-generator without changing anything

You might want to update your entity for the following reasons:

  • You want to add/remove fields and relationships to an existing entity
  • You want to reset your entity code to its original state
  • You have updated JHipster, and would like to have your entity generated with the new templates
  • You have modified the .json configuration file (the format is quite close to the questions asked by the generator, so it’s not very complicated), so you can have a new version of your entity
  • You have copy/pasted the .json file, and want a new entity that is very close to the copied entity

关于jhipster - 使用 JDL 修改 JHipster 实体的正确过程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59184050/

相关文章:

javascript - 如何使用 jhipster 和 Angular 在选项中显示图片?

microservices - Jhipster import-jdl不生成实体

angular - Jhipster下载过程中如何更改文件名(java + angular)

java - Spring boot 1.5.2 - 加载 Logo 后 Web 应用程序停止?

sql - 防止删除不存在的序列、创建现有用户时出现错误

mysql - 当将 liquibase 与 mysql 一起使用时,出现连接关闭后不允许操作错误

java - JHipster JDL studio 不接受应用程序标签

angular - Angular JHipster 项目中的自定义日期选择器选项

webpack - Jhipster:如何覆盖 prod webpack 配置文件的 SERVER_API_URL

intellij-idea - 在Lombok注释的类上,Gradle构建失败