3

I have created a project using Jhipster 6.10. Then, I've generated the entities and checked that everything was working fine. I added a new field into one of the entities using jhipster entity EntityName command. When I reload the project, Liquibase was giving me an error:

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

So I went and cleaned the H2 dev database with gradlew clean, relaunch the project and everthing was working fine.

My question is how should I proceed in PRODUCTION. This question:

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

gives the anwser for maven, but I'm using gradle.

PS: I followed Gael answer on a new dev project in Postgres and run:

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]

  • 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

When I do a: gradlew liquibaseDiffChangelog -PrunList=diffLog I get this error even when liquibase has connected and created the tables using the postgres datasource:

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

  • Try: 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 2s 1 actionable task: 1 executed

Thanks for your help.

Mike
  • 1,059
  • 5
  • 28
  • 51
  • You can use liquibase CLI directly, using maven or gradle for this has little value. See https://docs.liquibase.com/tools-integrations/cli/home.html?Highlight=execute – Gaël Marziou Jul 18 '20 at 22:34
  • While I would also say use the cli, you can do it with gradle (just like maven) by doing ./gradlew liquibaseDiffChangelog -PrunList=diffLog. See our documentation for reference https://www.jhipster.tech/development/#database-updates-with-the-maven-liquibasediff-goal – atomfrede Jul 20 '20 at 14:20
  • @Gaël Marziou I have tried your solution, but it doesn't work for me. I have added the error in the question. Thanks – Mike Aug 25 '20 at 22:10
  • From what I read, you haven't tried what I told you, you used gradle while my advice was to use `liquibase` command directly. – Gaël Marziou Aug 25 '20 at 22:20
  • Sorry @Gaël Marziou I mixed the answers in my head. Thanks for your help as well. There is no ./liquibase.properties to follow your instructions. I couldn't follow the liquibase instructions in here: https://docs.liquibase.com/commands/community/generatechangelog.html Gael, should the instructions from atomfede work? It is the official jhipster site. Thanks – Mike Aug 26 '20 at 09:56
  • If you want to use the liquibase CLI ou must create the liquibase.properties or use command line options. Fred's instructions are correct of course, I just provided an alternative.The crucial point is understanding Liquibase's philosophy which is about immutable migrations, you can cheat with it if your migration has never run in production but once it has run, you should never modify it. – Gaël Marziou Aug 26 '20 at 12:42
  • Thanks @atomfrede but when I do it your way, it does not work (i added the code to the question). It doesnt work following the instructions at jhipster webpage either. – Mike Aug 26 '20 at 19:53

1 Answers1

0

In production if your table have no data:

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

That's all, in next deployment, new table will be created.

In production if your table have data:

  1. Create a new ChangeSet that includes your new changes

for example:

    <changeSet id="20200721000000" author="manual">
        <addColumn tableName="payment">
            <column name="paid" type="bit" />
...
  1. Include your ChangeSet(-file-name) in master.xml

  2. Test your changes in a local database(ideally exported production db) (optional but recommended)

SidMorad
  • 954
  • 12
  • 19
  • I have created the changeset, include it in master.xml, but still getting errors. It doesn't work. Thanks @SidMorad – Mike Aug 31 '20 at 08:56
  • @SidMoard: There is a checksum problem: 2 change sets check sum config/liquibase/changelog/20200828110553_added_entity_ChatRoom.xml::20200828110553-1::jhipster was: 8:45c69e1affafd483e1c99a649712865a but is now: 8:4b8c99621aec5014ee84db01cb7e804f So may be I need another step to make it work. Thanks – Mike Aug 31 '20 at 10:56
  • @Mike 20200828110553_added_entity_ChatRoom.xml must not change after table-creation-event-in-your-production-database. You can use git(assuming is your current version control system) to rollback this file into it's original form. Then checksum problem will disappear. – SidMorad Aug 31 '20 at 12:06
  • Sorry @SidMorad, but it doesnt work for me. I can add new entity, but i can not modify an existing one. I created this example on github https://github.com/Tonterias/liquimvntwoentities/commits/master Thanks you – Mike Sep 17 '20 at 18:47
  • @Mike see [this commit](https://github.com/SidMorad/liquimvntwoentities/commit/14361d48e9d66fbb5a900cd96b9a214285c9f00f) which is suitable method for when your table **has production data**. Cheers – SidMorad Sep 19 '20 at 07:39