Skip to content

Instantly share code, notes, and snippets.

@yelhouti
Last active July 16, 2023 18:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yelhouti/bcefa769a421dd60298b34ad653a4d86 to your computer and use it in GitHub Desktop.
Save yelhouti/bcefa769a421dd60298b34ad653a4d86 to your computer and use it in GitHub Desktop.
jhipster generation upgrades

Code Generation

There two main approches of handling upgrades when using a code generator:

  1. The generated code is never touched (only extended...), and regeneration only updates these files
  2. Generated code is stored in a separate branch where generation is done no changes are done manually, the generated branch is merged with master at each upgrade

I find the first approach hard to work with for two reasons:

  1. some files can't be extended like package.json ...
  2. Extending all the files makes for bigger code base and adding simple changes can add a lot of work

the second approch can also be combursume, when you need to merge a big project but I find it to be the best tradeoff

Jhipster

For Jhipster (up to now), all the code is generated in the beggining from a JDL file (jhipster.jh)

In our case we use two blueprints:

npx jhipster import-jdl --blueprints primeng-blueprint jhipster.jh

This automatically creates our initial commit and we create a new branch import-jdl form this same commit.

Update JHipster or Blueprints versions

Next time we want to regenarate the project:

  1. we switch back to the branch import-jdl
git checkout import-jdl
  1. we update the jhipster version and blueprints in its package.json and install them:
npm install
  1. delete all the files except the ones we need to avoid keeping file not generated anymore:
rm -rf !(".git"|".jhipster"|"jhipster.jh"|"node_modules"|".yo-rc.json")
  1. modify .yo-rc to remove deleted entities and remove them from the .jhipster folder and restore liquibase files
  2. regenarte the project:
jhipster import-jdl --blueprints primeng-blueprint,composite-key-server jhipster.jh

When we want to only add a field, or make a small change and there is no risk of forgetting an old file..., we can just regenerate on top of the old files without mentionning the blueprints... by running:

jhipster import-jdl jhipster.jh --force

Once the project is inproducation the command above breaks liquibase, this was known issue as was fixed by creating the diff of the liquibase file manually, now this possible with the new flag: --incremental-changelog

jhipster import-jdl --incremental-changelog  jhipster.jh

There is a bug when using incremental changelogs and generating fake-data (relationship fake-data is not present). To fix this you can add --skip-fake-data carefull, not update application-dev.yml and remove faker profile And change back "skipFakeData": false in .yo-rc.json

Often, you don't want to merge directly into master, (you don't have the permissions, their is a CI you want to go through...) in this case:

  • you create a branch merge-import-jdl from master
  • merge into it
  • fix your tests...
  • amend the extra commit if one was added for merging or add a new one for merging
  • use git log to make sure that you did NOT amend the commit just created in import-jdl in this branch history,with AT MOST ONE for your tests fixes... (the one you ammend)
  • create a pull request WITHOUT the option squash commits, to endup with the commit from import-jdl inside master, so that, hopefully, next merges don't require you to resolve the same conflicts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment