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

MySQL: Fix primary key alteration when adding new columns #2696

Merged
merged 1 commit into from
Apr 26, 2017

Conversation

drieschel
Copy link

Trying to get a column in a table which is not added yet, will result in throwing a SchemaException. Also altering not yet added columns does not make sense.

@drieschel
Copy link
Author

A feedback from someone of the doctrine/dbal team would be great.

@@ -708,6 +709,10 @@ private function getPreAlterTableAlterPrimaryKeySQL(TableDiff $diff, Index $inde

// Dropping primary keys requires to unset autoincrement attribute on the particular column first.
foreach ($index->getColumns() as $columnName) {
if(isset($diff->addedColumns[$columnName]) && $diff->addedColumns[$columnName] instanceof Column) {
continue;
}
Copy link
Member

Choose a reason for hiding this comment

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

I think using the following check is more convenient and safer concerning the following getColumn() call:

if (! $diff->fromTable->hasColumn($columnName)) {
    continue;
}

@drieschel
Copy link
Author

drieschel commented Apr 14, 2017

@deeky666 Done :)

PS: The fix could also be added to branch 2.5.

@drieschel drieschel force-pushed the pk_add_column_mysql branch from 55557d0 to 3717c49 Compare April 14, 2017 11:44
@@ -708,6 +708,10 @@ private function getPreAlterTableAlterPrimaryKeySQL(TableDiff $diff, Index $inde

// Dropping primary keys requires to unset autoincrement attribute on the particular column first.
foreach ($index->getColumns() as $columnName) {
if(!$diff->fromTable->hasColumn($columnName)) {
Copy link
Member

Choose a reason for hiding this comment

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

sorry to nitpick but we use the following code style if (! $diff can you please adjust that? afterwards I'll merge.

@drieschel drieschel force-pushed the pk_add_column_mysql branch from 3717c49 to fb018c0 Compare April 14, 2017 19:28
@drieschel drieschel force-pushed the pk_add_column_mysql branch from fb018c0 to fa2a12e Compare April 14, 2017 21:58
@deeky666 deeky666 added this to the 2.5.13 milestone Apr 26, 2017
@deeky666 deeky666 merged commit fbed76e into doctrine:master Apr 26, 2017
@deeky666
Copy link
Member

@drieschel thanks! Backported to 2.5 via c41cc5a

@drieschel drieschel deleted the pk_add_column_mysql branch April 26, 2017 19:32
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants