Skip to content
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

[DBAL-1062] Fix renaming indexes used by foreign key constraints #756

Merged
merged 1 commit into from
Dec 26, 2014

Conversation

deeky666
Copy link
Member

Platforms that do not support a SQL syntax for natively renaming indexes need to drop and recreate indexes to perform a rename.
Platforms like MySQL < 5.7 deny dropping indexes used by foreign key constraints. In this case foreign key constraints have to be dropped before dropping indexes and have to be recreated after the particular index(es) have been recreated.
This is a major issue right now for people trying to upgrade to DBAL 2.5.

@doctrinebot
Copy link

Hello,

thank you for creating this pull request. I have automatically opened an issue
on our Jira Bug Tracker for you. See the issue link:

http://www.doctrine-project.org/jira/browse/DBAL-1092

We use Jira to track the state of pull requests and the versions they got
included in.

@@ -2080,6 +2078,28 @@ protected function getPostAlterTableIndexForeignKeySQL(TableDiff $diff)
);
}

if (! $this->supportsForeignKeyConstraints()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this new block be moved to a new private method? getForeignKeyConstraintChangesSql() maybe?

@Ocramius
Copy link
Member

Looking really good to me! Nitpicking to be fixed, but then mergeable

@deeky666 deeky666 force-pushed the DBAL-1062 branch 2 times, most recently from e647fbd to dbec00f Compare December 26, 2014 14:49
@deeky666
Copy link
Member Author

@Ocramius reworked the PR as I recognized this is only an issue for MySQL < 5.7. All other platforms' foreign key constraints do not require an index to be present. This is something related to InnoDB only. Less code now, less abstraction necessary.

Ocramius added a commit that referenced this pull request Dec 26, 2014
[DBAL-1062] Fix renaming indexes used by foreign key constraints
@Ocramius Ocramius merged commit e206016 into doctrine:master Dec 26, 2014
@Ocramius
Copy link
Member

Backported into 2.5.x at 2e4ed5f

@dbpolito
Copy link

Sadly this didn't worked for me, i'm upgrading from dbal 2.3.x at mysql 5.6 and all my indexes are still being recreated.

Is there any way to make it work? =(

@Ocramius
Copy link
Member

@dbpolito from 2.3? Could you try upgrading to 2.4 first, and see if the bug is there?

@dbpolito
Copy link

@Ocramius Upgrading to 2.4 went fine, and already fixed the issue i was having first, which make it work with php 5.6, for some reason i didn't receive the notifications from doctrine/orm#1154 (comment) , would made my life easier.

But after upgrading to 2.4, if do upgrade to 2.5 this issue still happens...

@deeky666
Copy link
Member Author

@dbpolito this patch does not necessarily prevent index recreation, it just makes it work if foreign keys are involved. The expected behaviour is that it possibly recreates some indexes on upgrade but only ONCE! Please see the discussion in DBAL-1062.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants