fix: auto migrate tries to delete non-existent unique constraint #7135
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What did this pull request do?
This change simply updates the migrator to make sure the unique constraint actually exists prior to deleting this. (Note: We cannot use
IF EXISTS
because mysql alter table syntax does not support that.)The reason for this is based on issue #7100 . With the PR #6640 the naming for unique constraints was changed. Previously the migrator was creating unique indexes with a naming prefix of
idx_
. When #6640 went it, the name changed to beuni_
. But if your previous upgrade created the constraint with a name ofidx_
the migrator would see you had a constraint and try to delete it. But it was using the updated naming pattern in this statement. So that would result in a command likeALTER TABLE "compliance_integrations" DROP CONSTRAINT "uni_compliance_integrations_clusterid"
. Since the name of the constraint isidx_compliance_integrations_clusterid
the call toDROP CONSTRAINT
fails. The point of this change is to simply make it a no-op if the constraint doesn't exist. That will prevent failure. The old constraint may linger in these cases but that is not the scope of this change. The scope of this change is to have a migrator that does not cause unnecessary failures for users.User Case Description