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.54k stars 4.02k forks source link

drop relationship column not working for id columns not named "id" #20536

Closed OmarHawk closed 1 year ago

OmarHawk commented 1 year ago
Overview of the issue

When generating a liquibase changelog dropping a foreign key relationship, the changelog generated does not consider id columns not named 'id':

https://github.com/jhipster/generator-jhipster/blob/4e52f15041beee04ffce42ff3be3f542661ada8b/generators/liquibase-changelogs/templates/src/main/resources/config/liquibase/changelog/updated_entity.xml.ejs#L148

When applying such a changelog, that fails, leading to a not starting application: 2022-12-07T09:33:49.571+01:00 ERROR 23536 --- [ restartedMain] o.s.boot.SpringApplication : Application run failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'liquibase' defined in class path resource [de/mt/dataview/config/LiquibaseConfiguration.class]: Invocation of init method failed; nested exception is liquibase.exception.LiquibaseException: liquibase.exception.MigrationFailedException: Migration failed for changeset config/liquibase/changelog/20221207073604_updated_entity_StreamError.xml::20221207073604-1-drop-relationships::jhipster:
     Reason: liquibase.exception.DatabaseException: Can't DROP 'stream_data_id'; check that column/key exists [Failed SQL: (1091) ALTER TABLE fx.stream_error DROP COLUMN stream_data_id]
Motivation for or Use Case

Applying changelog fails and changelog must be modified manually.

Reproduce the error
Related issues
Suggest a Fix

https://github.com/jhipster/generator-jhipster/blob/4e52f15041beee04ffce42ff3be3f542661ada8b/generators/liquibase-changelogs/templates/src/main/resources/config/liquibase/changelog/updated_entity.xml.ejs#L148 must be adjusted

JHipster Version(s)

7.9.3

JHipster configuration
Entity configuration(s) entityName.json files generated in the .jhipster directory
Browsers and Operating System
DanielFran commented 1 year ago

Adding a bug bounty

OmarHawk commented 1 year ago

I've also adjusted adding a new relationship in my PR so that is following the same approach when initially generating the entity with all its relationships.