Closed dbhynds closed 2 years ago
Looking further into it, this seems to be caused by using the name options
when configuring the additional parameters to be passed to pt-online-schema-change
command. The laravel framework pulls any parameters under options
array and passes them down to PDO. If I rename the property options
to params
then the issue goes away.
For example
'connections' => [
'zero-downtime' => [
'driver' => 'pt-online-schema-change',
// This is your master write access database connection details
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
// Additional options, depending on your setup
// all options available here: https://www.percona.com/doc/percona-toolkit/LATEST/pt-online-schema-change.html
'options' => [
'--nocheck-replication-filters',
'--nocheck-unique-key-change',
'--recursion-method=none',
'--chunk-size=2000',
],
],
],
changed to
'connections' => [
'zero-downtime' => [
'driver' => 'pt-online-schema-change',
// This is your master write access database connection details
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
// Additional options, depending on your setup
// all options available here: https://www.percona.com/doc/percona-toolkit/LATEST/pt-online-schema-change.html
'params' => [
'--nocheck-replication-filters',
'--nocheck-unique-key-change',
'--recursion-method=none',
'--chunk-size=2000',
],
],
],
This would be a breaking change as anyone using this package would have to rename the config parameter. I will try and get this fixed in the next major release.
Please see the fix for this bug in #32. Thank you for raising this issue.
We ran into an error while trying to modify a column in our database. It seems that the PDO object used by pt-osc connection is incompatible with the doctrine connection. This PR changes the BaseConnection to use the
default
database connection as the doctrine connection instead of thezero-downtime
one.The root of the problem was basically that the arguments provided to the
PDO
constructor for the doctrine connection are reused from thePtOnlineSchemaChangeConnection
arguments. However, the two interfaces are not compatible. (See expected vs actual arguments below.) See: https://www.php.net/manual/en/ref.pdo-mysql.phpI'm not 100% positive this is the best way to solve this problem, but it does work. I feel like it would be better to be able to specify which DB connection to use for doctrine, instead of just assuming the default connection, but I wasn't sure the best way to go about that. I'm open to suggestions.
More details:
The migration we were running:
The exception we were getting:
The relevant clues in the from the stack trace:
Expected arguments for the
pdo
closure:Actual arguments for the
pdo
closure:The full stack trace: