Deprecate introspection of incomplete SQLite schema #6701
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.
Background
The SQL syntax allows omitting referenced column names in a foreign key constraint declaration. In this case, it's implied that the constraint references the primary key columns. Normally, databases (e.g. Postgres) present the resulting definition of the constraint in the introspection schema (i.e. the actual column names) however, SQLite reports the original SQL statement.
A foreign key constraint declaration that was declared with omitted column names is reported as not referencing any columns. And if the referenced table doesn't exist (which SQLite allows), we get a foreign key without columns.
This is a very corner case that shouldn't happen normally. However, if it does, DBAL should throw an exception instead of producing invalid results.
Problem statement
From the data model standpoint, a foreign key constraint definition without columns doesn't make sense and will be impossible to construct in 5.0.
Refactoring
Additionally, the introspection code has been refactored. The current implementation reads as "if the
to
column contains null, then introspect the referenced table PK and add its columns to the existing columns". While this is technically correct, the "add to the existing columns" case will never happen because there will be only one row representing a foreign key without columns. Instead, we introspect all keys and then fetch the PKs for the ones that don't have columns. This is easier to comprehend and easier to put the deprecation logic to.