mattmilesi / pt-osc-command-generator
Generates pt-online-schema-change commands for MySQL, given the ALTER TABLE query
0.3.1
2025-03-11 18:58 UTC
Requires
- php: >=7.4
- phpmyadmin/sql-parser: ^5.9
Requires (Dev)
- fattureincloud/php-code-standard: ^1.1
- friendsofphp/php-cs-fixer: ^3.48
- phpunit/phpunit: ^9.6
README
Generates pt-online-schema-change commands for MySQL, given the ALTER TABLE query.
⚠️ This is an experimental version. Please, do not use it in production.
Installation
composer require mattmilesi/pt-osc-command-generator
Usage
$query = "ALTER TABLE customers ADD COLUMN middle_name VARCHAR(255) NOT NULL AFTER first_name;"; $parser = new \PtOscCommandGenerator\StatementParser($query); $command = $parser->getCommands()[0] ->setDsnOption(\PtOscCommandGenerator\DsnOption::HOST, '<host>') ->setDsnOption(\PtOscCommandGenerator\DsnOption::DATABASE, '<database>') ->setDsnOption(\PtOscCommandGenerator\DsnOption::USER, '<user>') ->setDsnOption(\PtOscCommandGenerator\DsnOption::PASSWORD, '<password>') ->setExecuteMode(); $cliCommand = (string)$command; # getCommands returns an array of Command, each one representing a command to be executed # $cliCommand: pt-online-schema-change --execute --alter "ADD COLUMN middle_name VARCHAR(255) NOT NULL AFTER first_name" h=<host>,D=<database>,t=customers,u=<user>,p=<password>
License
This project is licensed under the Apache License 2.0.
However, it includes the phpmyadmin/sql-parser
library, which is used under GPL 3.0 to ensure compatibility.
See GPL-3.0.txt for details.