Repository navigation
Correct unique constraints for UserConsent entity - #14793
Conversation
|
Adding unique indexes will be failed for Keycloak instances with already duplicate entries.
What Keycloak team believe that we should do? |
|
What would happen during a migration if duplicate keys are present? Keycloak would fail to start? |
That's why I am asking Keycloak team for the way to solve possible duplicate entries problem:
I believe the second is the ideal. |
|
@hmlnarik I've requested your review for this - the current constraint is not enough to prevent duplicate consents (see associated issue). The problem is that reworking the constraint as proposed here will cause migration failures for those who already have duplicate records in their DBs, so some previous action must be taken to eliminate duplicates before attempting to change the constraints. |
@sguilhen @hmlnarik any review progress for this bug? |
fa9f3e7 to
6aa8dfd
Compare
c276969 to
767a8fc
Compare
Unreported flaky test detectedIf the flaky tests below are affected by the changes, please review and update the changes accordingly. Otherwise, a maintainer should report the flaky tests prior to merging the PR. org.keycloak.testsuite.ui.account2.ReferrerTest#badClientUriTestKeycloak CI - Account Console IT (chrome) |
c6c8b19 to
0c34504
Compare
|
I have rebased in current main. Moreover based on our discussion in github issue, during migration Keycloak will delete newer consent for duplicate consents. |
There was a problem hiding this comment.
Hi @cgeorgilakis. I've added a couple of points I think are worth revisiting. In addition, we need to ensure this change also works for Microsoft SQL Server.
I've also requested a review from @vramik to see if I'm not missing anything.
There was a problem hiding this comment.
I am personally not in favor to remove this check, and the reason is that we have similar checks in many other providers. If we decide to go down this route of relying solely on the DB constraints it would call for a broader change in all the providers.
There was a problem hiding this comment.
I am personally not in favor to remove this check, and the reason is that we have similar checks in many other providers. If we decide to go down this route of relying solely on the DB constraints it would call for a broader change in all the providers.
I do not like double checks for the same thing. If you think that it is not a performance problem, I will add it back.
There was a problem hiding this comment.
In Keycloak we have avoided the explicit SQL statements in the changesets, and instead we use custom changes like the one in this PR - for consistency I would use the same approach here.
There was a problem hiding this comment.
In Keycloak we have avoided the explicit SQL statements in the changesets, and instead we use custom changes like the one in this PR - for consistency I would use the same approach here.
Ok, I will check it and will make appropriate changes if possible.
There was a problem hiding this comment.
I have migrate SQL statements to Java class extends CustomKeycloakTask.
ac5e1ce to
f7e0df1
Compare
Unreported flaky test detectedIf the flaky tests below are affected by the changes, please review and update the changes accordingly. Otherwise, a maintainer should report the flaky tests prior to merging the PR. org.keycloak.testsuite.ui.account2.ApplicationsTest#navigationTestKeycloak CI - Account Console IT (chrome) org.keycloak.testsuite.webauthn.account.WebAuthnSigningInTest#createWebAuthnSameUserLabelKeycloak CI - WebAuthn IT (chrome) |
Microsoft SQL Server seems to work as Oracle database supporting NULL values in unique constraints. |
Unreported flaky test detectedIf the flaky tests below are affected by the changes, please review and update the changes accordingly. Otherwise, a maintainer should report the flaky tests prior to merging the PR. org.keycloak.testsuite.oauth.RefreshTokenTest#refreshTokenWithDifferentIssuerKeycloak CI - Store IT (mariadb) |
0b57a33 to
9495380
Compare
There was a problem hiding this comment.
@cgeorgilakis thank you for preparing the PR.
@sguilhen I went through it and the code seems good to me. I didn't test the solution locally with different databases.
I've spotted only a minor thing. New classes JpaUpdate25* don't contain copyright message.
8ce8809 to
3146d4b
Compare
I have added them. |
|
@cgeorgilakis one final comment that might simplify the whole thing a little bit for your consideration. Instead of two separate custom changes, you can combine them in a single change and use the protected void generateStatementsImpl() throws CustomChangeException {
if (super.database instanceof MariaDBDatabase || super.database instanceof PostgresDatabase) {
generateStatementsPGMariaDB();
} else if (super.database instanceof MySQLDatabase) {
generateStatementsMySQL();
}
}
protected void generateStatementsPGMariaDB() throws CustomChangeException {
// PG / MariaDB statements go here
}
protected void generateStatementsMySQL() throws CustomChangeException {
// MySQL statements go here
}Then the changeset can be adjusted to no longer have pre conditions that check the DB type, and instead simply call the custom change and then adjusts the index (drop current and add the two new indexes). WDYT? |
The problem with this is that no changes are needed for Microsoft SQL Server and Oracle. So, add/ drop unique Constraint need to be in JpaUpdate25_0_0_ConsentConstraints . Is this change needed? |
Good point. Lets leave it as is then. @ahus1 The PR looks good to me, @vramik also reviewed. If you could take one final look/merge it would be great. |
|
Unfortunately there are now conflicts for the JPA changelog, please resolve them. Something I worry about a bit: when creating the SQL statements, I am not sure if they contain a schema name, which might be used for MySQL databases. Please double-check. If you think we are fine, I'm ok to go ahead and merge. |
|
@ahus1 thank you for looking into it. As far as I'm aware there is schema correctly handled within which is called from Does that address your concern? |
|
@vramik - thank you, yes, this resolves it for me. |
Closes keycloak#13045 Signed-off-by: cgeorgilakis-grnet <cgeorgilakis@admin.grnet.gr>
3146d4b to
c662402
Compare
@ahus1 I have resolved them (have rebased PR). |
Closes #13045
As we see in the following code (class
JpaUserProvider, methodaddConsent) :Unique constraint in a database is not working if one - or more - field is null. So we propose to delete old one and create two appropriate unique constraints.
I also propose to delete the check in the method
addConsentof classJpaUserProvider. This check must be done in database, no need for twice check.