-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
schemadiff: validate and apply foreign key indexes #12026
Merged
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
5acb9f3
more testing for getViewDependentTableNames()
shlomi-noach 9e6e31c
getForeignKeyParentTableNames
shlomi-noach 9224d01
schema normalization: sort tables by fk reference order
shlomi-noach 03139da
minor test addition
shlomi-noach 5079877
ForeignKeyDependencyUnresolvedError
shlomi-noach 29bac39
InvalidReferencedColumnInForeignKeyConstraintError, MismatchingForeig…
shlomi-noach 87e00ee
validate or autogenerate index on local table based on foreign key co…
shlomi-noach fb5b19d
validate referenced table key
shlomi-noach fc78e0b
ColumnKeyOption consts become public
shlomi-noach fc5d4b6
adding DuplicateKeyNameError
shlomi-noach e09acc2
normalize PRIMARY KEY definition: a 'id int primary key' column defin…
shlomi-noach 8631527
Merge branch 'main' into schema-diff-normalize-primary-key
shlomi-noach b0a8c6f
further unit test adaptations
shlomi-noach d9cd695
Merge branch 'main' into schemadiff-fk-keys
shlomi-noach 0f8c986
merge main, resolve conflict
shlomi-noach 6eded6c
adapting tests: adding required local index over foreign key columns
shlomi-noach c0a3df4
implicitly add key over foreign key columns if no appropriate key exists
shlomi-noach 211f85d
normalize CREATE TABLE statement to include missing foreign key indexes
shlomi-noach 76a4834
rename error: ForeignKeyColumnCountMismatchError
shlomi-noach fd46324
rename MismatchingForeignKeyColumnTypeError to ForeignKeyColumnTypeMi…
shlomi-noach 9daec2b
changes per review
shlomi-noach 6a3548d
merge main, resolve conflict
shlomi-noach 3fe002c
add a few tests that validate an implicit index isn't added if not ne…
shlomi-noach d175211
case insensitive column comparison in indexCoversColumnsInOrder and i…
shlomi-noach 16e1ed3
MissingForeignKeyIndexError is not needed bcause, compatible with MyS…
shlomi-noach File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
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.
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.
Hmm, I'm not sure why these are 3 different error types when they seem all pretty similar? Would it be simpler to model this as one?
The first two seem to be the case of there's an FK constraint to the table itself, but in that case I think it's ok if
Table
andReferencedTable
contain the same value?Not sure about the 3rd one, but that seems to not have a constraint name and not sure when that happens? Don't we always have to generate a constraint name anyway if it's missing and would it be fine if that name was set then on the same error?
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.
Good catch on the 1st error,
MissingForeignKeyIndexError
: I've just removed it. It can never fire because, compatible with MySQL's behavior, we always add an index if one is needed, either in aCREATE TABLE
statement or in aALTER TABLE ... ADD ... FOREIGN KEY
statement.2nd error,
MissingForeignKeyReferencedIndexError
, is when the parent table does not have an index covering the referenced columns. Here, MySQL does not add anything implicitly, because that's on a different table. The error is compatible with MySQL.3rd error,
IndexNeededByForeignKeyError
is for when you attempt toALTER TABLE ... DROP KEY
and when that leaves a foreign key without an index covering its local columns. Compatible with MySQL, that's an error.