新权威Jhipster

New authority Jhipster

我按照文章https://www.jhipster.tech/tips/025_tip_create_new_authority.html中的那些说明添加了一个新权限“ROLE_CLIENT”之后,我重新启动了我的项目,出现了一个错误:

2021-07-13 00:22:46.592  WARN 3596 --- [  restartedMain] iguration$LoadBalancerCaffeineWarnLogger : Spring Cloud LoadBalancer is currently working with the default cache. You can switch to using Caffeine cache, by adding it and org.springframework.cache.caffeine.CaffeineCacheManager to the classpath.
2021-07-13 00:22:46.806 ERROR 3596 --- [ gateway-task-1] t.j.c.liquibase.AsyncSpringLiquibase     : Liquibase could not start correctly, your database is NOT ready: Validation Failed:
     1 change sets check sum
          config/liquibase/changelog/00000000000000_initial_schema.xml::00000000000001::jhipster was: 8:06225dfc05215e6b13d8a4febd3fd90f but is now: 8:2272077bd3e9baf389312f0e018e5795


liquibase.exception.ValidationFailedException: Validation Failed:
     1 change sets check sum
          config/liquibase/changelog/00000000000000_initial_schema.xml::00000000000001::jhipster was: 8:06225dfc05215e6b13d8a4febd3fd90f but is now: 8:2272077bd3e9baf389312f0e018e5795

        at liquibase.changelog.DatabaseChangeLog.validate(DatabaseChangeLog.java:299)
        at liquibase.Liquibase.lambda$update(Liquibase.java:237)
        at liquibase.Scope.lambda$child[=10=](Scope.java:160)
        at liquibase.Scope.child(Scope.java:169)
        at liquibase.Scope.child(Scope.java:159)
        at liquibase.Scope.child(Scope.java:138)
        at liquibase.Liquibase.runInScope(Liquibase.java:2370)
        at liquibase.Liquibase.update(Liquibase.java:217)
        at liquibase.Liquibase.update(Liquibase.java:203)
        at liquibase.integration.spring.SpringLiquibase.performUpdate(SpringLiquibase.java:321)
        at liquibase.integration.spring.SpringLiquibase.afterPropertiesSet(SpringLiquibase.java:275)
        at org.springframework.boot.autoconfigure.liquibase.DataSourceClosingSpringLiquibase.afterPropertiesSet(DataSourceClosingSpringLiquibase.java:46)
        at tech.jhipster.config.liquibase.AsyncSpringLiquibase.initDb(AsyncSpringLiquibase.java:118)
        at tech.jhipster.config.liquibase.AsyncSpringLiquibase.lambda$afterPropertiesSet[=10=](AsyncSpringLiquibase.java:93)
        at tech.jhipster.async.ExceptionHandlingAsyncTaskExecutor.lambda$createWrappedRunnable(ExceptionHandlingAsyncTaskExecutor.java:78)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
        at java.base/java.lang.Thread.run(Thread.java:834)

顺便说一句,我使用的是微服务架构和JWT认证。

这是正常的:Liquibase 变更集应该是 immutable。

这就是为什么 Liquibase 在数据库变更日志 table 中记录每个变更集条目的 md5 校验和,以检测当前变更日志中的内容与实际 运行 数据库中的内容之间的差异。

当您修改 authority.csv 时,变更集的校验和发生了变化,Liquibase 正确地抱怨了。

因此,您有 3 个备选解决方案:

  1. 创建一个单独的变更集以仅插入您的新权限(生产中的首选方式)
  2. 在使用像 DBeaver 这样的数据库客户端连接到数据库时清除变更集的校验和列,并删除 DATABASECHANGELOG table 中变更日志行的 MD5SUM 列。看看https://docs.liquibase.com/concepts/basic/databasechangelog-table.html
  3. 删除您的数据库以从头开始重新启动,如果您不关心您的数据,这可能适用于开发数据库

最后的建议:从 official docs also from JHipster doc

了解更多关于 Liquibase 的信息