Skip to content

Commit

Permalink
Restore UNIQUE_CHECKS mysql variable to its original value when done …
Browse files Browse the repository at this point in the history
…with changing the database structure. This prevents potentially inserting duplicated values while manipulating data in the setup:upgrade command.
  • Loading branch information
hostep committed Feb 25, 2021
1 parent d3f202a commit a25c2c8
Showing 1 changed file with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ private function startSetupForAllConnections()
$this->resourceConnection->getConnection($resource)
->startSetup();
$this->resourceConnection->getConnection($resource)
->query('SET UNIQUE_CHECKS=0');
->query('SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0');
}
}

Expand All @@ -150,6 +150,8 @@ private function endSetupForAllConnections()
foreach ($this->sharding->getResources() as $resource) {
$this->resourceConnection->getConnection($resource)
->endSetup();
$this->resourceConnection->getConnection($resource)
->query('SET UNIQUE_CHECKS=IF(@OLD_UNIQUE_CHECKS=0, 0, 1)');
}
}

Expand Down

0 comments on commit a25c2c8

Please sign in to comment.