Jhipster 实体子生成器:如何使用 gradle 在 Prod 中创建 liquibase DELTA 变更日志?
Jhipster entity sub generator: How to create liquibase DELTA changelogs in Prod using gradle?
我使用 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 开发数据库,重新启动项目,一切正常。
我的问题是我应该如何进行生产。本题:
给出了 maven 的答案,但我正在使用 gradle。
PS:我在 Postgres 的一个新开发项目中遵循了 Gael 的回答,运行:
D:\JHipster\liquipostgres>gradlew compile liquiposrgres:diff
FAILURE: Build failed with an exception.
What went wrong: Task 'compile' is ambiguous in root project 'liquipostgres'. Candidates are: 'compileJava', 'compileTestJava'.
Try: Run gradlew tasks to get a list of available tasks. Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
Get more help at https://help.gradle.org
BUILD FAILED in 1s
FAILURE: Build failed with an exception.
Evaluating settingsITIALIZING [18ms]
出了什么问题:任务 'compile' 在根项目 'liquipostgres' 中不明确。候选人是:'compileJava', 'compileTestJava'.
尝试:运行gradlew 任务以获取可用任务列表。 运行 使用 --stacktrace 选项获取堆栈跟踪。 运行 使用 --info 或 --debug 选项以获得更多日志输出。 运行 使用 --scan 以获得完整的见解。
在 https://help.gradle.org 获得更多帮助
1 秒内构建失败
当我执行以下操作时:gradlew liquibaseDiffChangelog -P运行List=diffLog 即使 liquibase 已连接并使用 postgres 数据源创建表,我也会收到此错误:
19:22:47.959 DEBUG [liquibase.servicelocator.ServiceLocator]:
liquibase.ext.hibernate.database.HibernateSpringBeanDatabase matches
liquibase.database.Database 19:22:47.987 DEBUG
[liquibase.database.DatabaseFactory]: Properties: 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]: Connecting to
the URL:'jdbc:postgresql://localhost:5432/liquipostgres' using
driver:'org.postgresql.Driver' 19:22:48.102 ERROR
[liquibase.integration.commandline.Main]: Unexpected error running
Liquibase: org.postgresql.util.PSQLException: FATAL: la
autentificaci¾n password fall¾ para el usuario ½liquipostgres╗
(pgjdbc: autodetected server-encoding to be ISO-8859-1, if the message
is not readable, please check database logs and/or host, port, dbname,
user, password, 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, if the message is not readable,
please check database logs and/or host, port, dbname, user, password,
pg_hba.conf)
at liquibase.integration.commandline.CommandLineUtils.createDatabaseObject(CommandLineUtils.java:132)
at liquibase.integration.commandline.Main.doMigration(Main.java:1339)
at liquibase.integration.commandline.Main.run(Main.java:302)
at liquibase.integration.commandline.Main.main(Main.java:159) Caused by: 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, if the message is not readable,
please check database logs and/or host, port, dbname, user, password,
pg_hba.conf)
at liquibase.database.DatabaseFactory.openConnection(DatabaseFactory.java:263)
at liquibase.database.DatabaseFactory.openDatabase(DatabaseFactory.java:149)
at liquibase.integration.commandline.CommandLineUtils.createDatabaseObject(CommandLineUtils.java:97)
... 3 common frames omitted Caused by: org.postgresql.util.PSQLException: FATAL: la autentificaci¾n password
fall¾ para el usuario ½liquipostgres╗ (pgjdbc: autodetected
server-encoding to be ISO-8859-1, if the message is not readable,
please check database logs and/or host, port, dbname, user, password,
pg_hba.conf)
at org.postgresql.core.v3.ConnectionFactoryImpl.doAuthentication(ConnectionFactoryImpl.java:525)
at org.postgresql.core.v3.ConnectionFactoryImpl.tryConnect(ConnectionFactoryImpl.java:146)
at 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 common frames omitted
FAILURE: Build failed with an exception.
- What went wrong: Execution failed for task ':liquibaseDiffChangeLog'.
Process 'command 'C:\Program Files\Java\jdk-11.0.5\bin\java.exe'' finished with non-zero exit value -1
尝试:运行 使用 --stacktrace 选项获取堆栈跟踪。 运行 使用 --info 或 --debug 选项以获得更多日志输出。 运行 使用 --scan 以获得完整的见解。
- 获取更多帮助
2 秒内构建失败 1 个可操作任务:1 个已执行
感谢您的帮助。
如果您的 table 没有数据:
delete from databasechangelog where id = 'create-table-changeset-id';
drop table table_name;
就是这样,在下一次部署中,将创建新的table。
如果您的 table 有数据:
- 创建包含您的新更改的新变更集
例如:
<changeSet id="20200721000000" author="manual">
<addColumn tableName="payment">
<column name="paid" type="bit" />
...
在 master.xml
中包含您的 ChangeSet(-文件名)
在本地数据库(最好是导出生产数据库)中测试您的更改(可选但推荐)
我使用 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 开发数据库,重新启动项目,一切正常。
我的问题是我应该如何进行生产。本题:
给出了 maven 的答案,但我正在使用 gradle。
PS:我在 Postgres 的一个新开发项目中遵循了 Gael 的回答,运行:
D:\JHipster\liquipostgres>gradlew compile liquiposrgres:diff
FAILURE: Build failed with an exception.
What went wrong: Task 'compile' is ambiguous in root project 'liquipostgres'. Candidates are: 'compileJava', 'compileTestJava'.
Try: Run gradlew tasks to get a list of available tasks. Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
Get more help at https://help.gradle.org
BUILD FAILED in 1s
FAILURE: Build failed with an exception.
Evaluating settingsITIALIZING [18ms]
出了什么问题:任务 'compile' 在根项目 'liquipostgres' 中不明确。候选人是:'compileJava', 'compileTestJava'.
尝试:运行gradlew 任务以获取可用任务列表。 运行 使用 --stacktrace 选项获取堆栈跟踪。 运行 使用 --info 或 --debug 选项以获得更多日志输出。 运行 使用 --scan 以获得完整的见解。
在 https://help.gradle.org 获得更多帮助 1 秒内构建失败
当我执行以下操作时:gradlew liquibaseDiffChangelog -P运行List=diffLog 即使 liquibase 已连接并使用 postgres 数据源创建表,我也会收到此错误:
19:22:47.959 DEBUG [liquibase.servicelocator.ServiceLocator]: liquibase.ext.hibernate.database.HibernateSpringBeanDatabase matches liquibase.database.Database 19:22:47.987 DEBUG [liquibase.database.DatabaseFactory]: Properties: 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]: Connecting to the URL:'jdbc:postgresql://localhost:5432/liquipostgres' using driver:'org.postgresql.Driver' 19:22:48.102 ERROR [liquibase.integration.commandline.Main]: Unexpected error running Liquibase: org.postgresql.util.PSQLException: FATAL: la autentificaci¾n password fall¾ para el usuario ½liquipostgres╗ (pgjdbc: autodetected server-encoding to be ISO-8859-1, if the message is not readable, please check database logs and/or host, port, dbname, user, password, 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, if the message is not readable, please check database logs and/or host, port, dbname, user, password, pg_hba.conf) at liquibase.integration.commandline.CommandLineUtils.createDatabaseObject(CommandLineUtils.java:132) at liquibase.integration.commandline.Main.doMigration(Main.java:1339) at liquibase.integration.commandline.Main.run(Main.java:302) at liquibase.integration.commandline.Main.main(Main.java:159) Caused by: 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, if the message is not readable, please check database logs and/or host, port, dbname, user, password, pg_hba.conf) at liquibase.database.DatabaseFactory.openConnection(DatabaseFactory.java:263) at liquibase.database.DatabaseFactory.openDatabase(DatabaseFactory.java:149) at liquibase.integration.commandline.CommandLineUtils.createDatabaseObject(CommandLineUtils.java:97) ... 3 common frames omitted Caused by: org.postgresql.util.PSQLException: FATAL: la autentificaci¾n password fall¾ para el usuario ½liquipostgres╗ (pgjdbc: autodetected server-encoding to be ISO-8859-1, if the message is not readable, please check database logs and/or host, port, dbname, user, password, pg_hba.conf) at org.postgresql.core.v3.ConnectionFactoryImpl.doAuthentication(ConnectionFactoryImpl.java:525) at org.postgresql.core.v3.ConnectionFactoryImpl.tryConnect(ConnectionFactoryImpl.java:146) at 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 common frames omitted
FAILURE: Build failed with an exception.
- What went wrong: Execution failed for task ':liquibaseDiffChangeLog'.
Process 'command 'C:\Program Files\Java\jdk-11.0.5\bin\java.exe'' finished with non-zero exit value -1
尝试:运行 使用 --stacktrace 选项获取堆栈跟踪。 运行 使用 --info 或 --debug 选项以获得更多日志输出。 运行 使用 --scan 以获得完整的见解。
- 获取更多帮助
2 秒内构建失败 1 个可操作任务:1 个已执行
感谢您的帮助。
如果您的 table 没有数据:
delete from databasechangelog where id = 'create-table-changeset-id';
drop table table_name;
就是这样,在下一次部署中,将创建新的table。
如果您的 table 有数据:
- 创建包含您的新更改的新变更集
例如:
<changeSet id="20200721000000" author="manual">
<addColumn tableName="payment">
<column name="paid" type="bit" />
...
在
中包含您的 ChangeSet(-文件名)master.xml
在本地数据库(最好是导出生产数据库)中测试您的更改(可选但推荐)