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

This package is auto-updated.

Last update: 2025-05-11 19:22:08 UTC


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.