【问题标题】:Jhipster entity sub generator: How to create liquibase DELTA changelogs in Prod using gradle?Jhipster 实体子生成器:如何使用 gradle 在 Prod 中创建 liquibase DELTA 更改日志?
【发布时间】:2020-08-27 01:25:50
【问题描述】:

我使用 Jhipster 6.10 创建了一个项目。然后,我生成了实体并检查了一切是否正常。我使用 jhipster entity EntityName 命令在其中一个实体中添加了一个新字段。当我重新加载项目时,Liquibase 给了我一个错误:

liquibase.exception.ValidationFailedException: Validation Failed:
     2 change sets check sum
          config/liquibase/changelog/20200718175552_added_entity_ChatRoom.xml::20200718175552-1::jhipster was: 8:38306369febaf4b6a6b6ba7a88f73330 but is now: 8:412ef0706ed57049a9803f912e238bbb
          config/liquibase/changelog/20200718175552_added_entity_ChatRoom.xml::20200718175552-1-data::jhipster was: 8:57a6e15b897abad245853f04c91b731e but is now: 8:5c0cf1cea40b2c47cddc2c1173a81567

所以我用 gradlew clean 清理了 H2 开发数据库,​​重新启动项目,一切正常。

我的问题是我应该如何进行生产。这个问题:

Jhipster entity sub generator: How to create liquibase DELTA changelogs?

为 maven 提供 anwser,但我使用的是 gradle。

PS:我在 Postgres 的一个新开发项目上按照 Gael 回答并运行:

D:\JHipster\liquipostgres>gradlew 编译 liquiposrgres:diff

FAILURE:构建失败并出现异常。

  • 出了什么问题:根项目 'liquipostgres' 中的任务 'compile' 不明确。候选对象是:'compileJava'、'compileTestJava'。

  • 尝试:运行 gradlew 任务以获取可用任务的列表。使用 --stacktrace 选项运行以获取堆栈跟踪。使用 --info 或 --debug 选项运行以获得更多日志输出。运行 --scan 以获得完整的见解。

  • 通过https://help.gradle.org获得更多帮助

1 秒内构建失败

FAILURE:构建失败并出现异常。

评估设置ITIALIZING [18ms]

  • 出了什么问题:根项目 'liquipostgres' 中的任务 'compile' 不明确。候选对象是:'compileJava'、'compileTestJava'。

  • 尝试:运行 gradlew 任务以获取可用任务的列表。使用 --stacktrace 选项运行以获取堆栈跟踪。使用 --info 或 --debug 选项运行以获得更多日志输出。运行 --scan 以获得完整的见解。

  • https://help.gradle.org 获得更多帮助 1 秒内构建失败

当我执行以下操作时: gradlew liquibaseDiffChangelog -PrunList=diffLog 即使 liquibase 已连接并使用 postgres 数据源创建表,我也会收到此错误:

19:22:47.959 调试 [liquibase.servicelocator.ServiceLocator]: liquibase.ext.hibernate.database.HibernateSpringBeanDatabase 匹配 liquibase.database.Database 19:22:47.987 调试 [liquibase.database.DatabaseFactory]:属性:19:22:47.987 调试 [liquibase.database.DatabaseFactory]:密钥:'密码' 值:'**********' 19:22:47.987 调试 [liquibase.database.DatabaseFactory]:键:'user' 值:'liquipostgres' 19:22:47.987调试[liquibase.database.DatabaseFactory]:连接到 URL:'jdbc:postgresql://localhost:5432/liquipostgres' 使用 驱动程序:'org.postgresql.Driver' 19:22:48.102 错误 [liquibase.integration.commandline.Main]:运行出现意外错误 Liquibase:org.postgresql.util.PSQLException:致命:la autentificaci¾n 密码 fall¾ para el usuario ½liquipostgres╗ (pgjdbc:自动检测到的服务器编码为 ISO-8859-1,如果消息 不可读,请检查数据库日志和/或主机、端口、数据库名称、 用户、密码、pg_hba.conf)liquibase.exception.DatabaseException: liquibase.exception.DatabaseException: org.postgresql.util.PSQLException:致命:la autentificaci¾n 密码 fall¾ para el usuario ½liquipostgres╗ (pgjdbc: autodetected 服务器编码为 ISO-8859-1,如果消息不可读, 请检查数据库日志和/或主机、端口、数据库名称、用户、密码、 pg_hba.conf) 在 liquibase.integration.commandline.CommandLineUtils.createDatabaseObject(CommandLineUtils.java:132) 在 liquibase.integration.commandline.Main.doMigration(Main.java:1339) 在 liquibase.integration.commandline.Main.run(Main.java:302) 在 liquibase.integration.commandline.Main.main(Main.java:159) 引起:liquibase.exception.DatabaseException: org.postgresql.util.PSQLException:致命:la autentificaci¾n 密码 fall¾ para el usuario ½liquipostgres╗ (pgjdbc: autodetected 服务器编码为 ISO-8859-1,如果消息不可读, 请检查数据库日志和/或主机、端口、数据库名称、用户、密码、 pg_hba.conf) 在 liquibase.database.DatabaseFactory.openConnection(DatabaseFactory.java:263) 在 liquibase.database.DatabaseFactory.openDatabase(DatabaseFactory.java:149) 在 liquibase.integration.commandline.CommandLineUtils.createDatabaseObject(CommandLineUtils.java:97) ...省略了 3 个常见框架 原因:org.postgresql.util.PSQLException: FATAL: la autentificaci¾n 密码 fall¾ para el usuario ½liquipostgres╗ (pgjdbc: autodetected 服务器编码为 ISO-8859-1,如果消息不可读, 请检查数据库日志和/或主机、端口、数据库名称、用户、密码、 pg_hba.conf) 在 org.postgresql.core.v3.ConnectionFactoryImpl.doAuthentication(ConnectionFactoryImpl.java:525) 在 org.postgresql.core.v3.ConnectionFactoryImpl.tryConnect(ConnectionFactoryImpl.java:146) 在 org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:197) 在 org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49) 在 org.postgresql.jdbc.PgConnection.(PgConnection.java:211) 在 org.postgresql.Driver.makeConnection(Driver.java:459) 在 org.postgresql.Driver.connect(Driver.java:261) 在 liquibase.database.DatabaseFactory.openConnection(DatabaseFactory.java:255) ...省略了5个常见的框架

FAILURE:构建失败并出现异常。

  • 出了什么问题:任务“:liquibaseDiffChangeLog”执行失败。

Process 'command 'C:\Program Files\Java\jdk-11.0.5\bin\java.exe'' 以非零退出值 -1 结束

  • 尝试:使用 --stacktrace 选项运行以获取堆栈跟踪。使用 --info 或 --debug 选项运行以获得更多日志输出。运行 --scan 以获得完整的见解。

  • 通过https://help.gradle.org获得更多帮助

在 2 秒内构建失败 1 个可操作的任务:1 个已执行

感谢您的帮助。

【问题讨论】:

  • 你可以直接使用 liquibase CLI,使用 maven 或 gradle 没有什么价值。见docs.liquibase.com/tools-integrations/cli/…
  • 虽然我也会说使用 cli,但您可以通过 ./gradlew liquibaseDiffChangelog -PrunList=diffLog 使用 gradle(就像 maven)来实现。请参阅我们的文档以供参考jhipster.tech/development/…
  • @Gaël Marziou 我已经尝试过您的解决方案,但它对我不起作用。我在问题中添加了错误。谢谢
  • 从我读到的,你还没有尝试过我告诉你的,你使用了 gradle 而我的建议是直接使用liquibase 命令。
  • 对不起@Gaël Marziou 我在脑海中混合了答案。也感谢您的帮助。没有 ./liquibase.properties 可以按照您的指示进行操作。我无法按照此处的 liquibase 说明进行操作:docs.liquibase.com/commands/community/generatechangelog.html Gael,atomfede 的说明是否有效?这是官方的 jhipster 网站。谢谢

标签: gradle jhipster


【解决方案1】:

如果您的表没有数据,则在生产中:

  1. delete from databasechangelog where id = 'create-table-changeset-id';
  2. drop table table_name;

就是这样,在下一次部署中,将创建新表。

如果您的表有数据,则在生产中:

  1. 创建一个包含新更改的新变更集

例如:

    <changeSet id="20200721000000" author="manual">
        <addColumn tableName="payment">
            <column name="paid" type="bit" />
...
  1. master.xml中包含你的ChangeSet(-file-name)

  2. 在本地数据库(最好是导出的生产数据库)中测试您的更改(可选但推荐)

【讨论】:

  • 我已经创建了变更集,将其包含在 master.xml 中,但仍然出现错误。它不起作用。谢谢@SidMorad
  • @SidMoard:存在校验和问题:2 个更改集校验和 config/liquibase/changelog/20200828110553_added_entity_ChatRoom.xml::20200828110553-1::jhipster 是:8:45c69e1affafd483e1c99a649712865a 现在是:8 4b8c99621aec5014ee84db01cb7e804f 所以我可能需要另一个步骤才能让它工作。谢谢
  • @Mike 20200828110553_added_entity_ChatRoom.xml 在 table-creation-event-in-your-production-database 之后不得更改。您可以使用 git(假设是您当前的版本控制系统)将此文件回滚为其原始形式。然后校验和问题就会消失。
  • 对不起@SidMorad,但它对我不起作用。我可以添加新实体,但不能修改现有实体。我在github上创建了这个例子github.com/Tonterias/liquimvntwoentities/commits/master谢谢你
  • @Mike 请参阅this commit,当您的表有生产数据时,这是合适的方法。干杯
猜你喜欢
  • 2019-03-30
  • 1970-01-01
  • 1970-01-01
  • 2020-02-16
  • 2016-08-01
  • 1970-01-01
  • 2013-09-29
  • 1970-01-01
  • 2011-03-18
相关资源
最近更新 更多