Skip to content

mattmilesi/pt-osc-command-generator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pt-command-generator

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.

About

Generates pt-online-schema-change commands for MySQL, given the ALTER TABLE query

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages