jhipster / generator-jhipster

JHipster is a development platform to quickly generate, develop, & deploy modern web applications & microservice architectures.
https://www.jhipster.tech
Apache License 2.0
21.31k stars 4.01k forks source link

Add liquibase-maven-plugin to generate changelog #499

Closed rasheedamir closed 9 years ago

rasheedamir commented 9 years ago

I think feature should be provided to generate changelog through "liquibase-maven-plugin". I know there is hot reload which offers feature to create chagelog automatically but I think there should be support to generate it through maven plugin as well.

I can work on it!

Altaflux commented 9 years ago

Hi rasheedamir,

I tried working on something similar a week ago for Gradle and did not had the success I expected. There were some issues I thought they were not the effort or could be work around.

You could in fact generate a full changeLog but not a differential changeLog. Databases tend to generate much more information about the schema that liquibase can read when running the Diff command but can't fully expose in a changeLog xml. This will generate a lot of garbage in the changeLog and probably won't get some things right.

Even if your intention is to only generate full ChangeLogs they will be tied to your database implementation as it will generate lots of database specific data and database specific types which will break liquibase portability purpose.

I even tried using a plugin that allowed Liquibase to use Hibernate as a database to generate the ChangeLog, it was quite difficult and had to fight some bugs inside liquibase which haven't been fixed.

The issues I stumbled with that approach where the following: 1- A bug in liquibase.integration.commandline.CommandLineUtils (Have a Fix)

2- Generating full changeLogs against hibernate is not a bad approach but Liquibase cannot understand javax.validation so the changeLog's dataTypes will be full size, you would have to add the corresponding @Column attributes and set there lengths and precision. Besides there is a bug that constrains in the same entity could be named the same which you would have to modify manually. Plus liquibase is really dumb at reading some stuff the Sequences, they will NOT be correctly generated.

3- I tried comparing PostgreSQL against hibernate, and it did gave me the differences but as stated before it brought a lot of differences that where database specific and Hibernate specific plus as mentioned on point number 2 the changeLog tried to change the lenghts of the dataTypes to max size plus a lot of other stuff.

4- The best and cleanest way to compare current differences to generate a changeLog is to compare Hibernate vs Hibernate or Database vs Database. I didn't tried too much but I think you cannot easily start two hibernate sessions where the Entities should be different but have the same package and Class name as you would have to force in some way two classLoaders one pointing to an old hibernate entity versions and one pointing to a new hibernate entity versions. Plus the liquibase plugin cannot easily work with the way jHispter configures Hibernate thru SpringBoot as it is not visible, I had to create a dummy hibernate.cfg.xml to be able to use the entities. Comparing two databases is difficult and error prone as you would have to: Generate a new clean database, generate the schema thru hibernate and apply it, then compare both databases to generate the changeLog. With this last option you will encounter the same issues i had with point number 2 plus it can be difficult to automate correctly.

5- For some reason the gradle version of the liquibase plugin won't expose the diffChangeLog command so this would need to be fixed to produce a gradle version of the proposed enhancement.

6- You would need to add to Gradle/Maven at least 13 dependencies to it's classpath which are needed to run: The plugin, liquibase, Hibernate, Db drivers, (for some reason spring was needed even with spring security), joda time, the already compiled build of the entities, and the fixes needed for liquibase.

7- Lots of little issues and apparent bugs.

8- Liquibase developers say that it is not a good idea to use an automated changeLog generator, they are not very precise and are not reliable.

I haven't used a lot the Hot Reload of jHipster or the entity creator functionality but from what i see it is designed to only create simple entities and not precisely for altering the schema or complex entities with relations.

If you have another idea for implementing this enhancement it would be great to hear and would gladly help you implement it.

If you need more information about my experience feel free to ask.

Good day! Pablo

jdubois commented 9 years ago

From @Altaflux experience, this looks very difficult to achieve, which is why I'm closing this ticket.

My idea, with JHipster, is that:

@rasheedamir I don't mean I won't accept a PR from you: if you want to work on it, and have a working solution, I will gladly accept it.