Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid inconsistent incremental changelog files #25585

Merged
merged 1 commit into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
12 changes: 11 additions & 1 deletion generators/liquibase/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,21 @@ export default class LiquibaseGenerator extends BaseEntityChangesGenerator {

for (const databaseChangelog of changes) {
if (databaseChangelog.newEntity) {
this.databaseChangelogs.push(this.prepareChangelog({ databaseChangelog, application }));
this.databaseChangelogs.push(
this.prepareChangelog({
databaseChangelog: {
...databaseChangelog,
changelogData: { ...databaseChangelog.changelogData },
},
application,
}),
);
} else if (databaseChangelog.addedFields.length > 0 || databaseChangelog.removedFields.length > 0) {
this.databaseChangelogs.push(
this.prepareChangelog({
databaseChangelog: {
...databaseChangelog,
changelogData: { ...databaseChangelog.changelogData },
fieldChangelog: true,
addedRelationships: [],
removedRelationships: [],
Expand All @@ -237,6 +246,7 @@ export default class LiquibaseGenerator extends BaseEntityChangesGenerator {
this.prepareChangelog({
databaseChangelog: {
...databaseChangelog,
changelogData: { ...databaseChangelog.changelogData },
relationshipChangelog: true,
addedFields: [],
removedFields: [],
Expand Down
Loading
Loading