Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

jhipster --version

5.3.4

I'm evaluating JHipster and am testing how it handles database DDL modifications. In my test I created a Jhipster project and then ran jhipster import-jdl model.jh. JHipster generated all the integration test and everything looked good. So I deployed to production. But then I realized that I defined the wrong relationship between a set of entities. The original model.jh file declared a one-to-many relationship when I meant to declare a many-to-one relationship.

In order to fix this relationship I tried three approaches. First I tried to correct the relationship in the model.jh file and rerun jhipster import-jdl. This made the correct changes that I need, except that it overwrote the liquibase changelog files instead of creating a new changelog entry containing just the delta.

So I reverted that change, and tried to use the entity sub generator. It too modified the original changelog files rather than creating a delta changelog file. So I reverted those changes to try another approach.

I made the changes to the entities manually, and then used mvn liquibase:diff. This approach came the closest to what I needed. It did create a new changelog rather than updating the original files. But, the new changelog was trying to change way more than just the column associated with the relationship. It was trying to change datatypes on several non-related columns in the table. It removed remarks/comments from existing columns. In short, it was basically redefining the whole table from scratch with way more changes than are necessary for the small change I was trying to make. I ended up reverting on this approach too.

So, my question is, for those of you who are experienced users of JHipster and liquibase, how to you modify your entities after they have already been in use in production? Do you just create your changelogs manually, or is there a good way to auto generate them?

like image 256
axiopisty Avatar asked Oct 25 '18 21:10

axiopisty


1 Answers

  1. Make changes in your JDL and import it
  2. Revert the changes to the database changelog files caused by the entity generator (including master.xml)
  3. Compile the Java (Liquibase checks against compiled code) and run the command to generate the Liquibase changelog
    • Maven: ./mvnw compile liquibase:diff
    • Gradle: ./gradlew compileJava liquibaseDiffChangelog -PrunList=diffLog
  4. Add the new changelog to master.xml
  5. Start your app, liquibase will run the changelog and your database will be up-to-date

Steps 3-5 are documented in JHipster's "Using a Database" docs. Note that these steps only work if you are using a local database in dev, it currently does not work with H2.

You can see these steps as commits in this branch on Github.

like image 75
Jon Ruddell Avatar answered Sep 28 '22 07:09

Jon Ruddell