Reputation: 505
I'm currently building a new application which runs on an existing database - which is already in production. This new app is built in Laravel 4 and has a few migrations to make schema changes that are required.
Requirements are to use Percona Toolkits pt-online-schema-change
to issue schema changes, however I cannot find anywhere how to use this from within a migration - just the standard CLI interface. I need some way to tie together the schema change within the migration and pt-online-schema-change
.
I don't want to loose all the benefits that come with writing migrations or using the Laravel schema builder. I was hoping there is a simple way I'm not seeing to use Percona Toolkit within them. I have thought of using exec()
but I'd prefer to avoid this if possible.
When "Googling" periodically over the past few weeks, I could not find anything which resembles using Percona Toolkit within a migration. Surely this is a problem that has been solved already?
If my approach is flawed, please tell me! :)
Upvotes: 1
Views: 1015
Reputation: 87769
You probably will be able to execute it like this in your migrations:
public function up()
{
exec('pt-online-schema-change --alter "ADD COLUMN c1 INT" D=sakila,t=actor', $output, $return);
if ( ! $return) {
throw \Exception('Error migrating '.__FILE__);
}
}
Upvotes: 4