修改实体后jhipster liquibase验证错误 [英] jhipster liquibase validation error after modify entity

查看:74
本文介绍了修改实体后jhipster liquibase验证错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将一个字段作为 CLOB 添加到我的实体中.使用 JHipster CLI 时,添加它没有问题.

I was trying to add an field to my entity as a CLOB. When using the JHipster CLI it was no problem to add it.

现在,当我尝试启动我的应用程序时,我从 liquibase 收到以下验证错误:

Now, when i trying to start my application i get the following validation error from liquibase:

liquibase.exception.ValidationFailedException: Validation Failed:
     1 change sets check sum
          config/liquibase/changelog/20170221193921_xxxxxxxx.xml::20170221193921-1::jhipster was: 7:d8b3f42d8d4d523c7b14f93b4c7657c7 but is now: 7:a2a365179a0d231c2771ebd79f51b1fc

我还尝试了以下方法:

./mvnw liquibase:clearCheckSums

结果是BUILD SUCCESS.

我也试过 ./mvnw liquibase:update 和 updateSQL,结果一样.

i also tried ./mvnw liquibase:update and updateSQL, same result.

谁能告诉我 JHipster 有什么问题?

Can anyone tell me what my problem is with JHipster?

推荐答案

当我们使用 liquibase 时,以后发生的所有实体更改都应作为单独的更改日志进行捕获(例如,更改表格,如添加新列).Jhipster cli 似乎总是覆盖实体(以更改者为准)对应的 liquibase 文件(通常是 'config/liquibase/changelog/20180607110114_ added_entity_Employee.xml' 模式).因此实体 liquibase 文件的校验和会随着它现在有新内容而改变.在您的数据库中,有一个名为 DATABASECHANGELOG 的表,其中存储应用了所有变更日志以及校验和数据.

When we use liquibase all entity changes that happen later should be captured as separate changelogs(For eg. altering a table like adding a new column). Jhipster cli always seems to overwrite the entities(whichever changed) corresponding liquibase files(usually of the pattern 'config/liquibase/changelog/20180607110114_added_entity_Employee.xml'). Therefore the entities liquibase file's checksum changes as it has new content now. And in your database, there is a table called DATABASECHANGELOG which stores which all changeLogs were applied and this has checksum data.

现在,当您启动应用程序时,您将收到错误消息,因为您修改后实体校验和的最新 liquibase changeLog 与您上次运行的(数据库将具有此 liquibase 文件的校验和)不同.

Now when you start your application you will get error because your latest liquibase changeLog of modified entity's checksum is different from the last time(database will have a checksum for this liquibase file for previous verison) you ran.

mvn liquibase:clearCheckSums 除非需要,否则大多数情况下都不是正确的方法.这实际上清除了数据库中的所有校验和.你忘记了发生的变化,而这通常不是有意的.liquibase 的这些功能很有意义,例如当您想要回滚已应用的新更改时.如果您清除校验和并运行应用程序,它会计算新的校验和,您会丢失跟踪,如果没有引起足够的注意,可能会给您带来麻烦.

mvn liquibase:clearCheckSums is not the right approach most of the time unless needed. This actually clears all checksums in the database. You lose track of the changes that had happened which is usually not intended. These features of liquibase makes sense for eg like when you want to rollback the new changes you have applied. If you clear checksums and run the application it will compute new checksums you lose the track and can get you into trouble if not enough attention is paid.

正确的解决方案:

  1. 使用 jhipster entity sub-generatorjdl import直接手动更改实体 对实体进行更改.
  2. 现在检查实体对应的 liquibase 文件是否已更改.通常名称包含 '.._ added_entity_...' .例如.'config/liquibase/changelog/20180607110114_ added_entity_Employee.xml'.
  3. 将该文件恢复到原来的状态,以防它被覆盖.Git 在这里有助于恢复.
  4. 如果您现在启动应用程序,您将不会收到验证校验和错误,因为文件的校验和匹配.
  5. 但是我们对实体所做的更改并未在 liquibase 中捕获.为此,您必须运行 mvn liquibase:diff.这将生成一个 changeLog 文件.手动检查一次并将其添加到 liquibase 的 master.xml 文件中.添加到主文件是必须的,因为 liquibase 为所有更改日志引用此文件.
  6. 如果您现在运行应用程序,如果未应用更改日志,则 liquibase 将尝试在数据库上应用这些新更改.
  1. Make changes to your entities using jhipster entity sub-generator or jdl import or manual changes to your entities directly.
  2. Now check if the entities corresponding liquibase file was changed or not. Usually name contains '.._added_entity_...' . For eg. 'config/liquibase/changelog/20180607110114_added_entity_Employee.xml'.
  3. Revert that file back to what it was in case it was overwritten. Git is helpful here for reverting.
  4. If you start the application now you will not get validation checksum error as checksum of the file matches.
  5. But the change we made to entity is not captured in liquibase. For this you have to run mvn liquibase:diff. This will generate a changeLog file. Check it manually once and add it to liquibase's master.xml file. Adding to master file is must as liquibase refers to this file for all changeLogs.
  6. If you run the application now, if the changeLogs were not applied, then liquibase will try to apply these new changes on the database.

总而言之,jhipster cli 会覆盖实体 liquibase 文件.恢复它们并运行 mvn liquibase:diff 以在新的 changeLog 中捕获对实体的新更改,而不是覆盖以前生成的 liquibase 文件.我们可以看到校验和错误得到解决,并且在 liquibase 中也捕获了数据库更改.

To summarize, jhipster cli overwrites the entities liquibase files. Revert them and run mvn liquibase:diff to capture the new changes to the entites in a new changeLog instead of overwriting the previously generated liquibase file. We can see that checksum error is resolved and also database changes are captured in liquibase as well.

参考资料:
- 如何处理 liquibase 和 Jhipster 数据库更新.使用 Database updates

这篇关于修改实体后jhipster liquibase验证错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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