-
Notifications
You must be signed in to change notification settings - Fork 121
$AlterTable->dropConstraint() Throw error on MySQL,There is no support for "DROP CONSTRAINT" #36
Comments
Interested in this issue too. I guess there should be a way to do this through the MySQL |
Yes, you can see example in my MSSQL PR at https://github.com/zendframework/zend-db/pull/231/files and more specifically https://github.com/zendframework/zend-db/pull/231/files#diff-1c04a65ef544d7ab52700dcd9818209e Generally speaking:
Did not realize some syntax does not work for mysql here. Usually its the other way around. What is appropriate mysql way of doing this? |
In MySQL, My problem here is that I don't want to break the abstraction layer by using explicitly a MySQL-oriented class in my application (it should work the same on MySQL and SQLite for example). So I can't add a new method |
This is not a first time I ran into problem of constraints and foreign keys used interchangeably in syntax generation. @ezimuel Should version 3 or maybe even next 2.x consider providing separate API for constraint vs FKs? (not easiest question, because some DB engines do use them interchangeably) A horrible suggestion for now to keep abstraction layer between your MySQL and SQLite engines same, is on |
Yeah that's probably what I'll have to do, but that's an ugly workaround. In that very case, you could call $alterTable = new AlterTable();
$alterTable->dropConstraint('MY_FK', ['type' => 'foreign_key']); and then |
Your idea looks fine for temporary work around. Would vote against including something like that in library, because optional parameters create unmaintainable logical path branches that future contributors often forget to keep in mind. |
You're right.
would be more acceptable? It's still an optional parameter, but now at least it's clearly identified. Still searching for a clean way to do this, but I can't see anything with the current architecture. |
Its the same problem. There are many bugs in PostgreSQL adapter as primary example from top of my head because of inconsistency of optional parameter handling few function calls in. Only time its considered acceptable if it modifies call in some trivial non-branching way. Another potential solution maybe to use strategy pattern, where syntax is generated based on parameter type. Currently, dropConstraint() only supports string as parameter, which in itself is bad because it is inconsistent with other parts where So dropConstraint signature can be changed to take in
and |
More specifically, $constraint = new Constraint(); |
That's much better indeed. I've thought of using typed objects as parameters (and specifically Constraints subclasses) but that meant so much code rewrite that I prefered focusing on finding a quicker way without touching to the signature. Your solution is really attractive, but personally I can't imagine the whole implementation with the associated validation tests that would be necessary... |
The other problem is that replacing the current |
Currently the method /**
* @param Constraint\ConstraintInterface $constraint
* @return self Provides a fluent interface
*/
public function addConstraint(Constraint\ConstraintInterface $constraint)
{
$this->addConstraints[] = $constraint;
return $this;
}
IMHO and if I understand what you wrote correctly, using this very class for dropping is not the right way to go, but instead use |
@alextech I have an implementation based on what you suggested, with unit tests and all. I'll push a PR soon, but I doubt it could be accepted on the main branch, even though it fixes a currently broken implementation. |
PR #247 proposed. Hope it will be seriously considered. |
PR looks much nicer without that string property.
Yes, This annoyed me on several occasions. |
This repository has been closed and moved to laminas/laminas-db; a new issue has been opened at laminas/laminas-db#141. |
I'm dropping a constraint on mysql5.6, code:
And this code output :
Here is the problem, Mysql nerver support the Syntax "DROP CONSTRAINT", so it throw an error :
Note: $adapter config array is
Help ! What to do now ???
The text was updated successfully, but these errors were encountered: