Fix Mismatching constraint names in old migration #16891
Merged
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.
Prerequisites
Fixes #16267
Description
Due to older versions of Umbraco not always having had explicit constraint names, some older databases have "system-named constraints" resulting in constraint names not matching up what what we expect in later versions.
This PR takes that behavior into account to change a prior migration that relied on the constraint name being a fixed value. By utilizing the know table name, column name and constraint type (default, which only exists ones per column) we can identify the constraint without relying on it's name.
Testing
Since it is not straight forward to get a DB in a state where it used system-named constraints, I have asked the community to test out this PR on their DB's
I have also tested on the following scenarios to cover as many meaningful permutations as possible.
SQL used to rename the constraint to a bogus one
EXEC sp_rename N'DF_umbracoContentVersion_versionDate', N'DF_umbra#125498', N'OBJECT';