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

Fix removing autoincrement column from a primary key #786

Merged
merged 4 commits into from
Feb 10, 2015

Conversation

andig
Copy link
Contributor

@andig andig commented Jan 26, 2015

#430 is only a partial fix for DBAL-464. This adds treating autoincrement columns that get removed when altering a primary key.

@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-1132

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

@@ -654,6 +654,24 @@ protected function getPreAlterTableIndexForeignKeySQL(TableDiff $diff)
}
}

// handle columns that are removed from changed indexes
foreach ($diff->changedIndexes as $chgKey => $chgIndex) {
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 block be moved to a private method?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changedIndexes should imho be handled on the same level as removedIndexes

Copy link
Member

Choose a reason for hiding this comment

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

@andig it's just a question of readability

@Ocramius
Copy link
Member

@deeky666 I think this change is fine.

$column = $diff->fromTable->getColumn($columnName);

if ($column->getAutoincrement() === true && in_array($columnName, $chgIndex->getColumns()) === false) {
$column->setAutoincrement(false);
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure if it's a good idea mutating the "from" table here as this piece of information might be needed later on by other parts of the table alteration (even if it was not the case at the moment). I'd better go a safe way here. So my suggestion is to either set it to true again after the SQL generation part or clone the column.
@Ocramius thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

@andig I know that it is also done for removedIndexes and it might be causing the same issues there. So it was done wrong before and should not be done wrong again ;)

@deeky666
Copy link
Member

Besides my nitpicking it is looking good!

foreach ($diff->fromTable->getIndex($chgIndex->getName())->getColumns() as $columnName) {
$column = $diff->fromTable->getColumn($columnName);

if ($column->getAutoincrement() === true && in_array($columnName, $chgIndex->getColumns()) === false) {
Copy link
Member

Choose a reason for hiding this comment

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

You could add Index::hasColumn() but that is not absolutely required. I could also live with in_array() here ;)

@andig
Copy link
Contributor Author

andig commented Jan 27, 2015

Besides my nitpicking it is looking good!

No problem at all. If you're fine with the changes I'm happy to provide a squashed commit.

@andig
Copy link
Contributor Author

andig commented Jan 27, 2015

btw, do you want a reference to DBAL-1132, too?

@andig
Copy link
Contributor Author

andig commented Feb 1, 2015

as this seems pretty complete- any chance to get it committed?

@deeky666 deeky666 merged commit 6177ba4 into doctrine:master Feb 10, 2015
deeky666 added a commit that referenced this pull request Feb 10, 2015
Fix removing autoincrement column from a primary key
@deeky666
Copy link
Member

Thanks @andig ! Merged manually (extracted a private method in the platform and fixed some minor glitches).
Also backported to 2.5 and 2.4.

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