Deprecate the Constraint interface #4839
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.
Summary
The interface attempts to unify the API for different constraint classes but does it poorly.
getColumns()
method on aForeignKeyConstraint
class doesn't make any sense (implies the only set of columns) but has to be implemented:dbal/src/Schema/ForeignKeyConstraint.php
Lines 199 to 204 in 916c90f
CHECK
,DEFAULT
,NOT NULL
, etc. that do not use a list of columns in their definition.AbstractPlatform::getCreateConstraintSQL()
method accepts aConstraint
and by its signature is supposed to be capable of creating any constraint. But it only implements handling some specific sub-classes:dbal/src/Platforms/AbstractPlatform.php
Lines 1992 to 2009 in f6f7955
Constraint
method is added, this method will have to be reworked which violates the Open-closed principle.Additionally
The current implementation of
AbstractPlatform::getDropConstraintSQL()
doesn't work on MySQL older than 8.0.19 and MariaDB (seeSchemaManagerFunctionalTestCase::testDropAndCreateUniqueConstraint()
).Proposed changes
Constraint
interface and the corresponding methods.AbstractPlatform::getDropConstraintSQL()
as@internal
and convert toprotected
in the next major release. This method generates valid SQL and could be used by the methods that drop specific constraints.AbstractPlatform
andAbstractSchemaManager
.AbstractSchemaManager::dropAndCreateUniqueConstraint()
. It's hard to think of the usefulness of such "drop-and-create" methods outside of integration testing. These methods are primarily untested, do not allow proper static analysis, and suppress all underlying exceptions thrown by the "drop" part. We can deprecate them separately.OraclePlatform::getCreatePrimaryKeySQL()
allows usingcreateIndex()
to create a primary key in the test instead ofcreateConstraint()
. This is still not the best API but at least it's consistent with the rest of the platforms.