首页 > 解决方案 > Jhipster 实体子生成器:如何使用 gradle 在 Prod 中创建 liquibase DELTA 更改日志?

问题描述

我使用 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 实体子生成器:如何创建 liquibase DELTA 更改日志?

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

PS:我在 Postgres 的一个新开发项目中关注 Gael 的回答并运行:

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

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

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

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

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

1 秒内构建失败

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

评估设置ITIALIZING [18ms]

  • 出了什么问题:根项目“liquipostgres”中的任务“编译”不明确。候选对象是:'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 DEBUG [liquibase.database.DatabaseFactory]: Key:'password' Value:'**********' 19:22:47.987 DEBUG [liquibase.database.DatabaseFactory]: Key:'user' Value:' liquipostgres' 19:22:47.987 DEBUG [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: FATAL: la autentificaci¾n password fall¾ para el usuario ½liquipostgres╗ (pgjdbc: autodetected server-encoding to be 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) at liquibase.integration.commandline.Main.main(Main.java:159) 原因:liquibase.exception。DatabaseException: org.postgresql.util.PSQLException: FATAL: la autentificaci¾n password fall¾ para el usuario ½liquipostgres╗ (pgjdbc: autodetected server-encoding to be 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 password fall¾ para el usuario ½liquipostgres╗ (pgjdbc: autodetected server-encoding to be 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) at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49) at org.postgresql.jdbc.PgConnection.(PgConnection.java:211) at org.postgresql.Driver .makeConnection(Driver.java:459) at org.postgresql.Driver.connect(Driver.java:261) at liquibase.database.DatabaseFactory.openConnection(DatabaseFactory.java:255) ...省略了 5 个常见框架146) 在 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个常用框架省略146) 在 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个常用框架省略openConnection(DatabaseFactory.java:255) ... 5个常用框架省略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 个已执行

谢谢你的帮助。

标签: gradlejhipster

解决方案


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

  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. 将您的 ChangeSet(-file-name) 包含在master.xml

  2. 在本地数据库(理想情况下导出的生产数据库)中测试您的更改(可选但推荐)


推荐阅读