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

查看:382
本文介绍了修改实体后,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的表,该表存储了所有已应用的changeLogs并具有校验和数据.

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 importmanual changes to your entities directly对实体进行更改.
  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会针对所有changeLogs引用此文件.
  6. 如果立即运行应用程序,如果未应用changeLogs,那么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

References:
- How to deal with liquibase and Jhipster database updates. Check heading with Database updates

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

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