Skip to content

Commit

Permalink
Avoid inconsistent incremental changelog files
Browse files Browse the repository at this point in the history
caused by using shallow copies of being modified data

Fix jhipster#25564
  • Loading branch information
OmarHawk committed Mar 21, 2024
1 parent 62f057d commit c2113ae
Show file tree
Hide file tree
Showing 3 changed files with 428 additions and 0 deletions.
314 changes: 314 additions & 0 deletions generators/liquibase/__snapshots__/incremental-liquibase.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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": "<?xml version="1.0" encoding="utf-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">
<!--
Added columns to the entity One.
-->
<changeSet id="20200102000100-1-add-columns" author="jhipster">
<addColumn tableName="one">
<column name="new_field_of_one" type="boolean"/>
</addColumn>
</changeSet>
<!-- jhipster-needle-liquibase-add-changeset - JHipster will add changesets here -->
</databaseChangeLog>
",
"stateCleared": "modified",
},
"src/main/resources/config/liquibase/changelog/20200102000100_updated_entity_migrate_One.xml": {
"contents": "<?xml version="1.0" encoding="utf-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">
<changeSet id="20200102000100-columns-faker" author="jhipster" context="faker">
<!--
Load sample data generated with Faker.js
- This data can be easily edited using a CSV editor (or even MS Excel) and
is located in the 'src/main/resources/config/liquibase/fake-data' directory
- By default this data is applied when running with the JHipster 'dev' profile.
This can be customized by adding or removing 'faker' in the 'spring.liquibase.contexts'
Spring Boot configuration key.
-->
<loadUpdateData
file="config/liquibase/fake-data/20200102000100_entity_one.csv"
separator=";"
onlyUpdate="true"
primaryKey="id"
tableName="one">
<column name="id" type="numeric"/>
<column name="new_field_of_one" type="boolean"/>
<!-- jhipster-needle-liquibase-add-loadcolumn - JHipster (and/or extensions) can add load columns here -->
</loadUpdateData>
</changeSet>
<!-- jhipster-needle-liquibase-add-changeset - JHipster will add changesets here -->
</databaseChangeLog>
",
"stateCleared": "modified",
},
"src/main/resources/config/liquibase/changelog/20200102000200_updated_entity_Another.xml": {
"contents": "<?xml version="1.0" encoding="utf-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">
<!--
Added columns to the entity Another.
-->
<changeSet id="20200102000200-1-add-columns" author="jhipster">
<addColumn tableName="another">
<column name="original_changed" type="varchar(255)"/>
</addColumn>
</changeSet>
<!--
Dropped columns to the entity Another.
-->
<changeSet id="20200102000200-1-drop-columns" author="jhipster">
<dropColumn tableName="another">
<column name="original"/>
</dropColumn>
</changeSet>
<!-- jhipster-needle-liquibase-add-changeset - JHipster will add changesets here -->
</databaseChangeLog>
",
"stateCleared": "modified",
},
"src/main/resources/config/liquibase/changelog/20200102000200_updated_entity_migrate_Another.xml": {
"contents": "<?xml version="1.0" encoding="utf-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">
<changeSet id="20200102000200-columns-faker" author="jhipster" context="faker">
<!--
Load sample data generated with Faker.js
- This data can be easily edited using a CSV editor (or even MS Excel) and
is located in the 'src/main/resources/config/liquibase/fake-data' directory
- By default this data is applied when running with the JHipster 'dev' profile.
This can be customized by adding or removing 'faker' in the 'spring.liquibase.contexts'
Spring Boot configuration key.
-->
<loadUpdateData
file="config/liquibase/fake-data/20200102000200_entity_another.csv"
separator=";"
onlyUpdate="true"
primaryKey="id"
tableName="another">
<column name="id" type="numeric"/>
<column name="original_changed" type="string"/>
<!-- jhipster-needle-liquibase-add-loadcolumn - JHipster (and/or extensions) can add load columns here -->
</loadUpdateData>
</changeSet>
<!-- jhipster-needle-liquibase-add-changeset - JHipster will add changesets here -->
</databaseChangeLog>
",
"stateCleared": "modified",
},
"src/main/resources/config/liquibase/changelog/20200102000400_updated_entity_Another.xml": {
"contents": "<?xml version="1.0" encoding="utf-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">
<!--
Added relationships to the entity Another.
-->
<changeSet id="20200102000400-1-add-relationships" author="jhipster">
<addColumn tableName="another">
<column name="one_one_id" type="bigint"/>
</addColumn>
</changeSet>
<!-- jhipster-needle-liquibase-add-changeset - JHipster will add changesets here -->
</databaseChangeLog>
",
"stateCleared": "modified",
},
"src/main/resources/config/liquibase/changelog/20200102000400_updated_entity_constraints_Another.xml": {
"contents": "<?xml version="1.0" encoding="utf-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">
<!--
Added the relationship constraints for entity Another.
-->
<changeSet id="20200102000400-relationship-foreign-keys" author="jhipster">
<addForeignKeyConstraint baseColumnNames="one_id"
baseTableName="another"
constraintName="fk_another__one_id"
referencedColumnNames="id"
referencedTableName="one"
/>
</changeSet>
</databaseChangeLog>
",
"stateCleared": "modified",
},
"src/main/resources/config/liquibase/changelog/20200102000400_updated_entity_migrate_Another.xml": {
"contents": "<?xml version="1.0" encoding="utf-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">
<changeSet id="20200102000400-columns-faker" author="jhipster" context="faker">
<!--
Load sample data generated with Faker.js
- This data can be easily edited using a CSV editor (or even MS Excel) and
is located in the 'src/main/resources/config/liquibase/fake-data' directory
- By default this data is applied when running with the JHipster 'dev' profile.
This can be customized by adding or removing 'faker' in the 'spring.liquibase.contexts'
Spring Boot configuration key.
-->
<loadUpdateData
file="config/liquibase/fake-data/20200102000400_entity_another.csv"
separator=";"
onlyUpdate="true"
primaryKey="id"
tableName="another">
<column name="id" type="numeric"/>
<column name="one" type="string"/>
<!-- jhipster-needle-liquibase-add-loadcolumn - JHipster (and/or extensions) can add load columns here -->
</loadUpdateData>
</changeSet>
<!-- jhipster-needle-liquibase-add-changeset - JHipster will add changesets here -->
</databaseChangeLog>
",
"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": "<?xml version="1.0" encoding="utf-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd">
<property name="now" value="current_timestamp" dbms="postgresql"/>
<property name="floatType" value="float4" dbms="postgresql"/>
<property name="clobType" value="clob" dbms="postgresql"/>
<property name="blobType" value="blob" dbms="postgresql"/>
<property name="uuidType" value="uuid" dbms="postgresql"/>
<property name="datetimeType" value="datetime" dbms="postgresql"/>
<include file="config/liquibase/changelog/00000000000000_initial_schema.xml" relativeToChangelogFile="false"/>
<include file="config/liquibase/changelog/20200101000100_added_entity_One.xml" relativeToChangelogFile="false"/>
<include file="config/liquibase/changelog/20200101000200_added_entity_Another.xml" relativeToChangelogFile="false"/>
<!-- jhipster-needle-liquibase-add-changelog - JHipster will add liquibase changelogs here -->
<!-- jhipster-needle-liquibase-add-constraints-changelog - JHipster will add liquibase constraints changelogs here -->
<include file="config/liquibase/changelog/20200102000100_updated_entity_One.xml" relativeToChangelogFile="false"/>
<include file="config/liquibase/changelog/20200102000100_updated_entity_migrate_One.xml" relativeToChangelogFile="false"/>
<include file="config/liquibase/changelog/20200102000200_updated_entity_Another.xml" relativeToChangelogFile="false"/>
<include file="config/liquibase/changelog/20200102000200_updated_entity_migrate_Another.xml" relativeToChangelogFile="false"/>
<include file="config/liquibase/changelog/20200102000400_updated_entity_Another.xml" relativeToChangelogFile="false"/>
<include file="config/liquibase/changelog/20200102000400_updated_entity_migrate_Another.xml" relativeToChangelogFile="false"/>
<include file="config/liquibase/changelog/20200102000400_updated_entity_constraints_Another.xml" relativeToChangelogFile="false"/>
<!-- jhipster-needle-liquibase-add-incremental-changelog - JHipster will add incremental liquibase changelogs here -->
</databaseChangeLog>
",
"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": {
Expand Down
2 changes: 2 additions & 0 deletions generators/liquibase/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ export default class LiquibaseGenerator extends BaseEntityChangesGenerator {
this.prepareChangelog({
databaseChangelog: {
...databaseChangelog,
changelogData: { ...databaseChangelog.changelogData },
fieldChangelog: true,
addedRelationships: [],
removedRelationships: [],
Expand All @@ -237,6 +238,7 @@ export default class LiquibaseGenerator extends BaseEntityChangesGenerator {
this.prepareChangelog({
databaseChangelog: {
...databaseChangelog,
changelogData: { ...databaseChangelog.changelogData },
relationshipChangelog: true,
addedFields: [],
removedFields: [],
Expand Down
Loading

0 comments on commit c2113ae

Please sign in to comment.