-
Notifications
You must be signed in to change notification settings - Fork 122
Fix AlterTable::dropConstraint() by allowing the use of decorator #247
base: develop
Are you sure you want to change the base?
Conversation
…oken implementation under MySQL)
src/Sql/Ddl/AlterTable.php
Outdated
@@ -74,7 +75,7 @@ class AlterTable extends AbstractSql implements SqlInterface | |||
], | |||
self::DROP_CONSTRAINTS => [ | |||
"%1\$s" => [ | |||
[1 => "DROP CONSTRAINT %1\$s,\n", 'combinedby' => ""], | |||
[2 => "DROP %1\$s %2\$s,\n", 'combinedby' => ""], |
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.
Do not modify generic syntax from abstract classes other adapters inherit from for engine specific fixes. Fixing one engine breaks assumptions of others within this library or others making custom adapters.
src/Sql/Ddl/AlterTable.php
Outdated
$sqls[] = $adapterPlatform->quoteIdentifier($constraint); | ||
$sqls[] = [ | ||
'CONSTRAINT', | ||
$adapterPlatform->quoteIdentifier($constraint->getName()) |
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.
Until this #233 goes through that fixes bugs in quoteIdentifier vs quoteIdentifierChain this will break PostgreSQL and MSSQL. If lucky and that PR gets merged prior to this, then its fine.
foreach ($this->dropConstraints as $constraint) { | ||
$sqls[] = [ | ||
$constraint->getType(), | ||
$adapterPlatform->quoteIdentifier($constraint->getName()) |
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.
As above
doc/book/sql-ddl.md
Outdated
use \Zend\Db\Metadata\Object\ConstraintObject; | ||
|
||
$fkConstraint = new ConstraintObject('my_fk', null); | ||
$fkConstraint->setType('FOREIGN KEY'); |
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.
Disagree. If you want your constraint to represent foreign key, then use ForeignKey class that already does this.
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.
Sure, I can do that. But as I said on issue #36, I thought it was better because it describes an existing constraint (metadata) that can be retrieved by analyzing the database, hence programatically.
Also, \Zend\Db\Sql\Ddl\Constraint\ForeignKey
requires a lot of arguments, which are useless for dropping.
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.
Oh I just noticed how ConstraintObject lets you do that... Why such duality... :( I guess at the moment both would work, but to go forward initiative to migrate to PHP 7.1 and all related type inconsistency fixes as discussed on development channel, this lose handling needs to go away. Imagine others who will not notice this duplication of functionality in ConstraintObject and ForeignKey.
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.
I see... In that case metadata analyzer is broken not assigning foreign key constraint to ForeignKey constraint object. I should not be penalized for wanting to use given by the framework ForeignKey object to describe foreign key constraint. I suppose that means both need to be handled by the Decorator at this point since that's what the library gives us. Or clean creation of ConstraintObject to create ForeignKey, which would be further reaching change.
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.
Or clean creation of ConstraintObject to create ForeignKey, which would be further reaching change.
\Zend\Db\Metadata\Source\AbstractSource::getConstraint()
seems to be doing its job when analyzing the table and assigns the type of constraints correctly.
But yeah, when you dig that down you realize there are some nasty inconsistencies to take care of ahead of that bug.
Anyway, I'll take your remarks into account and I'll make some changes, hopefully for the best. But I'm not going to rewrite half of the framework either.
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.
Was about to suggest to let dropConstraint
method take in AbstractConstraint
so you have access to best of both ConstraintObject
and ForeignKey
, but what do you know, ConstraintObject
does not inherit from AbstractConstraint
or ConstraintInterface
as name would imply!
Just cannot win here without
rewrite half of the framework either.
But that's too much to ask for at this time ...
Great job on moving specifications to decorators. Those are tough to do.
For version 3, which according to discussions all new versions want to target PHP 7.1 strict type system, it would be needed to rewrite to tighten up the types allowed per method to weed out those
nasty inconsistencies to take care of ahead of that bug.
I would have fun doing it, but a little discouraging based on rate of PR reviews.
…rface and \Zend\Db\Metadata\Object\ConstraintObject when dropping a constraint (thanks @alextech)
…raint # Conflicts: # test/Sql/Ddl/AlterTableTest.php # test/Sql/Platform/Mysql/Ddl/AlterTableDecoratorTest.php
Fixed errors after merge with master. Ready for integration in 3.0.0 if everything's ok for you. |
I've updated my branch with the latest revision from develop. Unfortunately it shows a failure with code coverage which is in fact invalid. The file @alextech Have you ever had this issue? |
@nanawel I too have this issue. (dont want to put in PR ID here to confuse the issue tracker relevancy, search "coverage" in open PRs where I point it out). Was passing then suddenly dropped. There was an effort to upgrade travis config files across all of ZF repositories to make it more strict and after it there was more failings here in unexpected commits. I think I see why mine failed (though its a bit stretched) where I formatted my error output and so travis wants me to tests the full formatting logic, which is just a printf() XD .... According to the report there is unexercised "processDropConstraints" function. Line was added there but none of your tests seem to cover it. Even if the whole file has coverage by previous commits, that does not mean this particular commit is covered, therefore travis thinks it is new untested BC break (which makes sense). That is, travis checks that this set of commits is fully covering all of changes. Do your new tests execute that line 234 or only old ones? |
There are actually 2 tests related to |
Hi, still looking forward to seeing this in the upcoming 3.0.0. Thanks! |
Hi, |
@alexdenvir — Can you please provide an update on this? I have a CMS and I am using Zend-DB. Right now I am not able to use the drop constraint functionality. I can use this code directly in my fork repo, but before that, I want to know the reason behind not letting this PR merged. Update on this PR will be very helpful. So can you please provide it ASAP? |
Sorry, but no. Maybe try pinging @alextech instead? |
I am just a contributor level :-) |
Same here, although never to zend-db specifically. I saw you had left a review and assumed @BJGajjar meant to ping you instead. My bad |
I see it's marked as BC Break so planned for v3 release. I guess it will be much easier to get it in without BC Break (if possible?) |
@alextech @nanawel @alexdenvir @BJGajjar What do you think? |
Yeah. Sorry for the inconvenience.
Agree we can do that way also. It seems like there is some issue with this PR. I tried to use this code in my fork repo and use the
For your reference; |
@BJGajjar would you be able to provide PR based on that with changes I've described above, fixes of the issue you found, and tests to cover changes, please? |
@nanawel @webimpress @BJGajjar @alextech @alexdenvir
As suggested by @webimpress, I think we can provide BC(accept both - string and ConstraintInterface) by below change :
Please share your thoughts on it. |
This repository has been moved to laminas/laminas-db. If you feel that this patch is still relevant, please re-open against that repository, and reference this issue. To re-open, we suggest the following workflow:
|
This repository has been closed and moved to laminas/laminas-db; a new issue has been opened at laminas/laminas-db#72. |
Fixes a broken implementation under MySQL:
DROP CONSTRAINT
is not supported, you have to useDROP [FOREIGN KEY | INDEX | KEY]
instead.See issue #36
Warning: introduces a potential breaking change (string parameter is now a typed object).