diff --git a/generators/liquibase/__snapshots__/incremental-liquibase.spec.ts.snap b/generators/liquibase/__snapshots__/incremental-liquibase.spec.ts.snap
index 9e458113b723..cc5b819d1cfd 100644
--- a/generators/liquibase/__snapshots__/incremental-liquibase.spec.ts.snap
+++ b/generators/liquibase/__snapshots__/incremental-liquibase.spec.ts.snap
@@ -1421,6 +1421,320 @@ exports[`generator - app - --incremental-changelog when modifying an existing re
}
`;
+exports[`generator - app - --incremental-changelog when modifying fields and relationships at the same time in different entities should match snapshot 1`] = `
+{
+ "src/main/resources/config/liquibase/changelog/20200102000100_updated_entity_One.xml": {
+ "contents": "
+
+
+
+
+
+
+
+
+
+
+
+
+",
+ "stateCleared": "modified",
+ },
+ "src/main/resources/config/liquibase/changelog/20200102000100_updated_entity_migrate_One.xml": {
+ "contents": "
+
+
+
+
+
+
+
+
+
+
+
+
+
+",
+ "stateCleared": "modified",
+ },
+ "src/main/resources/config/liquibase/changelog/20200102000200_updated_entity_Another.xml": {
+ "contents": "
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+",
+ "stateCleared": "modified",
+ },
+ "src/main/resources/config/liquibase/changelog/20200102000200_updated_entity_migrate_Another.xml": {
+ "contents": "
+
+
+
+
+
+
+
+
+
+
+
+
+
+",
+ "stateCleared": "modified",
+ },
+ "src/main/resources/config/liquibase/changelog/20200102000400_updated_entity_Another.xml": {
+ "contents": "
+
+
+
+
+
+
+
+
+
+
+
+
+
+",
+ "stateCleared": "modified",
+ },
+ "src/main/resources/config/liquibase/changelog/20200102000400_updated_entity_constraints_Another.xml": {
+ "contents": "
+
+
+
+
+
+
+
+
+",
+ "stateCleared": "modified",
+ },
+ "src/main/resources/config/liquibase/changelog/20200102000400_updated_entity_migrate_Another.xml": {
+ "contents": "
+
+
+
+
+
+
+
+
+
+
+
+
+
+",
+ "stateCleared": "modified",
+ },
+ "src/main/resources/config/liquibase/data/authority.csv": {
+ "contents": "name
+ROLE_ADMIN
+ROLE_USER
+",
+ "stateCleared": "modified",
+ },
+ "src/main/resources/config/liquibase/data/user.csv": {
+ "contents": "id;login;password_hash;first_name;last_name;email;image_url;activated;lang_key;created_by;last_modified_by
+1;admin;$2a$10$gSAhZrxMllrbgj/kkK9UceBPpChGWJA7SYIb1Mqo.n5aNLq1/oRrC;Administrator;Administrator;admin@localhost;;true;en;system;system
+2;user;$2a$10$VEjxo0jq2YG9Rbk2HmX9S.k1uZBGYUHdUcid3g/vfiEl7lwWgOH/K;User;User;user@localhost;;true;en;system;system
+",
+ "stateCleared": "modified",
+ },
+ "src/main/resources/config/liquibase/data/user_authority.csv": {
+ "contents": "user_id;authority_name
+1;ROLE_ADMIN
+1;ROLE_USER
+2;ROLE_USER
+",
+ "stateCleared": "modified",
+ },
+ "src/main/resources/config/liquibase/fake-data/20200102000100_entity_one.csv": {
+ "contents": "one_id;new_field_of_one
+1;
+2;
+3;
+4;
+5;
+6;
+7;
+8;
+9;
+10;
+",
+ "stateCleared": "modified",
+ },
+ "src/main/resources/config/liquibase/fake-data/20200102000200_entity_another.csv": {
+ "contents": "another_id;original_changed
+1;
+2;
+3;
+4;
+5;
+6;
+7;
+8;
+9;
+10;
+",
+ "stateCleared": "modified",
+ },
+ "src/main/resources/config/liquibase/fake-data/20200102000400_entity_another.csv": {
+ "contents": "another_id
+1
+2
+3
+4
+5
+6
+7
+8
+9
+10
+",
+ "stateCleared": "modified",
+ },
+ "src/main/resources/config/liquibase/master.xml": {
+ "contents": "
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+",
+ "stateCleared": "modified",
+ },
+}
+`;
+
exports[`generator - app - --incremental-changelog when removing a field with constraints should match snapshot 1`] = `
{
"src/main/resources/config/liquibase/changelog/20200102000100_updated_entity_Customer.xml": {
diff --git a/generators/liquibase/generator.ts b/generators/liquibase/generator.ts
index 61baf423bcc4..eadb910c2119 100644
--- a/generators/liquibase/generator.ts
+++ b/generators/liquibase/generator.ts
@@ -217,6 +217,7 @@ export default class LiquibaseGenerator extends BaseEntityChangesGenerator {
this.prepareChangelog({
databaseChangelog: {
...databaseChangelog,
+ changelogData: { ...databaseChangelog.changelogData },
fieldChangelog: true,
addedRelationships: [],
removedRelationships: [],
@@ -237,6 +238,7 @@ export default class LiquibaseGenerator extends BaseEntityChangesGenerator {
this.prepareChangelog({
databaseChangelog: {
...databaseChangelog,
+ changelogData: { ...databaseChangelog.changelogData },
relationshipChangelog: true,
addedFields: [],
removedFields: [],
diff --git a/generators/liquibase/incremental-liquibase.spec.ts b/generators/liquibase/incremental-liquibase.spec.ts
index 4693e8d1d331..639f4308fe4f 100644
--- a/generators/liquibase/incremental-liquibase.spec.ts
+++ b/generators/liquibase/incremental-liquibase.spec.ts
@@ -33,6 +33,22 @@ entity Another {
original String
}`;
+const jdlApplicationWithChangedEntitiesAndRelationship = `
+${jdlApplication}
+entity One {
+ @Id oneId Long
+ original String
+ newFieldOfOne Boolean
+}
+entity Another {
+ @Id anotherId Long
+ originalChanged String
+}
+relationship ManyToOne {
+ Another to One,
+}
+`;
+
const jdlApplicationWithRelationshipToUser = `
${jdlApplicationWithEntities}
relationship ManyToOne {
@@ -1135,6 +1151,102 @@ entity Customer {
});
});
+ describe('when modifying fields and relationships at the same time in different entities', () => {
+ let runResult;
+ before(async () => {
+ const baseName = 'JhipsterApp';
+ const initialState = createImporterFromContent(jdlApplicationWithEntities, {
+ ...options,
+ creationTimestampConfig: options.creationTimestamp,
+ }).import();
+ const applicationWithEntities = initialState.exportedApplicationsWithEntities[baseName];
+ expect(applicationWithEntities).toBeTruthy();
+ expect(applicationWithEntities.entities.length).toBe(2);
+ runResult = await helpers
+ .create(generatorPath)
+ .withJHipsterConfig(config)
+ .withOptions({ ...options, applicationWithEntities })
+ .run();
+
+ const state = createImporterFromContent(jdlApplicationWithChangedEntitiesAndRelationship, {
+ ...options,
+ }).import();
+ runResult = await runResult
+ .create(generatorPath)
+ .withOptions({
+ ...options,
+ applicationWithEntities: state.exportedApplicationsWithEntities[baseName],
+ creationTimestamp: '2020-01-02',
+ })
+ .run();
+ });
+
+ after(() => runResult.cleanup());
+
+ it('should create application', () => {
+ runResult.assertFile(['.yo-rc.json']);
+ });
+ it('should create entity config file', () => {
+ runResult.assertFile([join('.jhipster', 'One.json'), join('.jhipster', 'Another.json')]);
+ });
+ it('should create entity initial changelog', () => {
+ runResult.assertFile([
+ `${SERVER_MAIN_RES_DIR}config/liquibase/changelog/20200101000100_added_entity_One.xml`,
+ `${SERVER_MAIN_RES_DIR}config/liquibase/changelog/20200101000200_added_entity_Another.xml`,
+ ]);
+ });
+ it('should create entity initial fake data', () => {
+ runResult.assertFile([`${SERVER_MAIN_RES_DIR}config/liquibase/fake-data/20200101000100_entity_one.csv`]);
+ });
+ it('should create entity update changelog with addColumn', () => {
+ runResult.assertFile([`${SERVER_MAIN_RES_DIR}config/liquibase/changelog/20200102000100_updated_entity_One.xml`]);
+ runResult.assertFileContent(
+ `${SERVER_MAIN_RES_DIR}config/liquibase/changelog/20200102000100_updated_entity_One.xml`,
+ 'addColumn tableName="one"',
+ );
+ runResult.assertFileContent(
+ `${SERVER_MAIN_RES_DIR}config/liquibase/changelog/20200102000100_updated_entity_One.xml`,
+ 'column name="new_field_of_one" type="boolean"',
+ );
+ runResult.assertNoFileContent(`${SERVER_MAIN_RES_DIR}config/liquibase/changelog/20200102000100_updated_entity_One.xml`, 'dropColumn');
+ });
+ it('should create entity update changelog with addColumn and dropColumn on Another', () => {
+ runResult.assertFile([`${SERVER_MAIN_RES_DIR}config/liquibase/changelog/20200102000200_updated_entity_Another.xml`]);
+ runResult.assertFileContent(
+ `${SERVER_MAIN_RES_DIR}config/liquibase/changelog/20200102000200_updated_entity_Another.xml`,
+ 'addColumn tableName="another"',
+ );
+ runResult.assertFileContent(
+ `${SERVER_MAIN_RES_DIR}config/liquibase/changelog/20200102000200_updated_entity_Another.xml`,
+ 'column name="original_changed" type="varchar(255)"',
+ );
+ runResult.assertFileContent(
+ `${SERVER_MAIN_RES_DIR}config/liquibase/changelog/20200102000200_updated_entity_Another.xml`,
+ 'dropColumn tableName="another"',
+ );
+ runResult.assertFileContent(
+ `${SERVER_MAIN_RES_DIR}config/liquibase/changelog/20200102000200_updated_entity_Another.xml`,
+ 'column name="original"',
+ );
+ });
+ it('should create the entity relationship field', () => {
+ runResult.assertFile([`${SERVER_MAIN_RES_DIR}config/liquibase/changelog/20200102000400_updated_entity_Another.xml`]);
+ runResult.assertFileContent(
+ `${SERVER_MAIN_RES_DIR}config/liquibase/changelog/20200102000400_updated_entity_Another.xml`,
+ 'addColumn tableName="another"',
+ );
+ runResult.assertFileContent(
+ `${SERVER_MAIN_RES_DIR}config/liquibase/changelog/20200102000400_updated_entity_Another.xml`,
+ 'column name="one_one_id" type="bigint"',
+ );
+ });
+ it('should create the entity constraint update changelog', () => {
+ runResult.assertFile([`${SERVER_MAIN_RES_DIR}config/liquibase/changelog/20200102000400_updated_entity_constraints_Another.xml`]);
+ });
+ it('should match snapshot', () => {
+ expect(runResult.getSnapshot('**/src/main/resources/config/liquibase/**')).toMatchSnapshot();
+ });
+ });
describe('entities with/without byte fields should create fake data', () => {
[
{