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

diffChangeLog constantly creating and dropping indicies/primary keys since Spring Boot 3/Liquibase 4.19 #456

Closed
Lukas0610 opened this issue Jan 21, 2023 · 7 comments · Fixed by #679

Comments

@Lukas0610
Copy link

Since upgrading to Spring Boot 3 (and thus to Liquibase 4.19), running diffChangeLog using hibernate:spring:* as a reference, Liquibase generates changelogs first dropping a constraint and then re-creates it with the same columns right after the drop-statement:

<changeSet author="root (generated)" id="1674298858677-83">
    <dropUniqueConstraint constraintName="UC_ACCOUNTSTRIPE_CUSTOMER_ID_COL" tableName="account"/>
</changeSet>
<changeSet author="root (generated)" id="1674298858677-84">
    <addUniqueConstraint columnNames="stripe_customer_id" constraintName="UC_ACCOUNTSTRIPE_CUSTOMER_ID_COL" tableName="account"/>
</changeSet>

A similar thing happens to Envers audit-tables, just with the primary key in that case:

<changeSet author="root (generated)" id="1674298858677-81">
    <dropPrimaryKey tableName="$audit_stop_groups"/>
</changeSet>
<changeSet author="root (generated)" id="1674298858677-82">
    <addPrimaryKey columnNames="stop_id, groups_id, revision" constraintName="$audit_stop_groupsPK" tableName="$audit_stop_groups"/>
</changeSet>

When executing either of these combined change-set, on the next run of diffChangeLog, the same changesets are generated again.

Another thing is that for the same Envers audit-tables, first an createIndex-changeset is being created. After executing these and running diffChangeLog again, a dropIndex-changesets for the just created indices are being created.

<changeSet author="root (generated)" id="1674298858677-183">
    <createIndex indexName="IX_$audit_stop_groupsPK" tableName="$audit_stop_groups" unique="true">
        <column name="stop_id"/>
        <column name="groups_id"/>
        <column name="revision"/>
    </createIndex>
</changeSet>

From what I can see, these changesets are only created for ManyToMany-relations and ElementCollection-annotated lists.

@grigala
Copy link

grigala commented Jan 23, 2023

I have a similar issue while still using Spring Boot 2.7.8, after upgrading from liquibase-hibernate5:4.10.0 to anything newer, including the latest 4.19.0.

My changelog instead of being empty as of v4.10.0 now contains changes like this:

 <changeSet author="george (generated)" id="1674498709369-1">
        <dropUniqueConstraint constraintName="UC_APPLICATION_PRINCIPALID_COL" tableName="...">
    </changeSet>
    <changeSet author="george (generated)" id="1674498709369-2">
        <addUniqueConstraint columnNames="id" constraintName="UC_APPLICATION_PRINCIPALID_COL" tableName="..."/>
    </changeSet>
...

While investigating I've looked at diff of v4.10.0 vs v4.11.0 there are only three files changes using these two commits:

And there's hibernate-core update from 5.6.1.Final to 5.6.9.Final

Any ideas @nvoxland?

@fleboulch
Copy link
Contributor

Related to #436

@amazing4u
Copy link

amazing4u commented Apr 14, 2023

This problem is fixed with version 4.21.0

//Update: Only the problem with "alter table" was fixed. the problem with primary keys / indices still exists in 4.21.0

@fleboulch
Copy link
Contributor

Thanks a lot !

@grigala
Copy link

grigala commented Apr 24, 2023

This problem is fixed with version 4.21.0

It wasn't in my case 🤷‍♂️ I still get dropUniqueConstraint, addUniqueConstraint list of changes.

  • org.liquibase:liquibase-core:4.21.1
  • org.liquibase.ext:liquibase-hibernate5:4.21.1
 <changeSet author="george (generated)" id="1674498709369-1">
        <dropUniqueConstraint constraintName="UC_APPLICATION_PRINCIPALID_COL" tableName="...">
    </changeSet>
    <changeSet author="george (generated)" id="1674498709369-2">
        <addUniqueConstraint columnNames="id" constraintName="UC_APPLICATION_PRINCIPALID_COL" tableName="..."/>
    </changeSet>
...

@amazing4u
Copy link

This problem is fixed with version 4.21.0

It wasn't in my case 🤷‍♂️ I still get dropUniqueConstraint, addUniqueConstraint list of changes.

  • org.liquibase:liquibase-core:4.21.1
  • org.liquibase.ext:liquibase-hibernate5:4.21.1
 <changeSet author="george (generated)" id="1674498709369-1">
        <dropUniqueConstraint constraintName="UC_APPLICATION_PRINCIPALID_COL" tableName="...">
    </changeSet>
    <changeSet author="george (generated)" id="1674498709369-2">
        <addUniqueConstraint columnNames="id" constraintName="UC_APPLICATION_PRINCIPALID_COL" tableName="..."/>
    </changeSet>
...

You are right. Sorry. I mixed it up with another bug. The problem you described was fixed today:
#479
#480

Hopefully it will be released soon

@grigala
Copy link

grigala commented Apr 25, 2023

You are right. Sorry. I mixed it up with another bug. The problem you described was fixed today: #479 #480

Hopefully it will be released soon

Thanks for the hints. Yeah, I certainly hope so.

They have also introduced a breaking change somewhere along the line with CommandScope and DiffChangelogCommandStep. Namely, executing diffChangelog command scope and watching for results isn't working the same way it used to.

CommandResults results = new CommandScope("diffChangelog").addArgumentValue(DiffChangelogCommandStep.CHANGELOG_FILE_ARG, outputFile)
                                                          .addArgumentValue(DiffChangelogCommandStep.URL_ARG, URL)
                                                          .addArgumentValue(DiffChangelogCommandStep.USERNAME_ARG, USERNAME)
                                                          .addArgumentValue(DiffChangelogCommandStep.PASSWORD_ARG, PASSWORD)
                                                          .addArgumentValue(DiffChangelogCommandStep.REFERENCE_URL_ARG, REFERENCE_URL)
                                                          .addArgumentValue(DiffChangelogCommandStep.EXCLUDE_OBJECTS_ARG, EXCLUDED_OBJECTS)
                                                          .execute();

This will not work any more as they've removed a lot of static variables from the DiffChangelogCommandStep class, so now I'm guessing you have to do this to achieve the same result?

CommandResults results = new CommandScope(DiffChangelogCommandStep.COMMAND_NAME)
                .addArgumentValue(DiffChangelogCommandStep.CHANGELOG_FILE_ARG, outputFile)
                .addArgumentValue(PreCompareCommandStep.EXCLUDE_OBJECTS_ARG, EXCLUDED_OBJECTS)
                .addArgumentValue(GenerateChangelogCommandStep.REFERENCE_URL_ARG, REFERENCE_URL)
                .addArgumentValue(DbUrlConnectionCommandStep.URL_ARG, URL)
                .addArgumentValue(DbUrlConnectionCommandStep.USERNAME_ARG, USERNAME)
                .addArgumentValue(DbUrlConnectionCommandStep.PASSWORD_ARG,  PASSWORD)
                .execute();

Notice usages of DbUrlConnectionCommandStep, DbUrlConnectionCommandStep and PreCompareCommandStep.

The changes have been made here(6be41a8) but I have no idea what was the reason to refactor it or what's the new way of doing the same as I couldn't find any documentation related to it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants