-
Notifications
You must be signed in to change notification settings - Fork 7.4k
MigrationModel duplicate entry #39994
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
Conversation
...tions/jpa/updater/liquibase/custom/JpaUpdate26_2_5_RemoveDuplicateMigrationModelVersion.java
Outdated
Show resolved
Hide resolved
I disagree with this approach as we want to do an insert, as the insert and the unique constraint prevent doing a migration twice. Doing a migration twice on a realm might lead to wrong results as a developer would have never thought of that situation. |
...tions/jpa/updater/liquibase/custom/JpaUpdate26_2_5_RemoveDuplicateMigrationModelVersion.java
Outdated
Show resolved
Hide resolved
...tions/jpa/updater/liquibase/custom/JpaUpdate26_2_5_RemoveDuplicateMigrationModelVersion.java
Outdated
Show resolved
Hide resolved
@ahus1 Thanks for the review! 🌴 I've updated the approach based on your comments and I'll test it and fix the test cases later. |
Closes keycloak#39866 Signed-off-by: Martin Bartoš <mabartos@redhat.com> Co-authored-by: Alexander Schwartz <alexander.schwartz@gmx.net>
@mabartos - I reviewed this changed locally and tested some variations:
I've pushed a commit that fixed it for me when testing it locally. Please let me know if you agree with these changes. |
Signed-off-by: Martin Bartoš <mabartos@redhat.com>
@ahus1 Thanks for the review and the additional testing!
+1
Yes, that is true and your changes kinda resolve this issue. However, as IDs of MigrationModel entity (as PKs) are not auto-incremented and referenced as the resource tags, they are randomly generated and cannot be compared based on time of creation. It can lead to a situation in which a more recent record in a table is deleted even it was added later than the one before for the same version. I've slightly edited the SQL script to consider first the update time and then if those are equal choosing some random one. WDYT?
+1 Tried the same testing approach and it should work as expected. |
...tions/jpa/updater/liquibase/custom/JpaUpdate26_2_6_RemoveDuplicateMigrationModelVersion.java
Outdated
Show resolved
Hide resolved
@ahus1 Just an info that I've added another commit to prevent some confusion: 071c5db Described in: #39994 (comment) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new SQL is a bit more complicated than I hoped for. I verified it, and also did some manual tests with multiple duplicate entries, and it worked as expected.
Thank you for this change - approving!
@ahus1 Yes, me too, but at least we have it semantically correct. I tried to simplify things for reviews as much as possible. Thanks! |
Closes: #39866
I've reproduced the issue before:

After these changes, everything should be good:

Testing approach
mabartos/keycloak:26.3.0
mabartos/keycloak/26.3.0
Used Testing Deployment
We might probably even update the MigrationModelAdapter to only update fields instead of trying to create a new record.