Files
percona-toolkit/t/pt-online-schema-change/samples/plugins/before_die_after_create.pm
Ilaria Migliozzi 8e4824813f added new hook before_die (#509)
* added new hook before_die

before die, the script calls this hook in oder to execute extra user's 
operations

* PR-509 -  added new hook before_die

- Added test cases

---------

Co-authored-by: Sveta Smirnova <sveta.smirnova@percona.com>
2023-11-06 18:22:14 +03:00

34 lines
751 B
Perl

package pt_online_schema_change_plugin;
use strict;
use warnings FATAL => 'all';
use English qw(-no_match_vars);
use constant PTDEBUG => $ENV{PTDEBUG} || 0;
sub new {
my ($class, %args) = @_;
my $self = { %args };
return bless $self, $class;
}
sub before_die {
my ($self, %args) = @_;
print "PLUGIN before_die\n";
print "Exit status: $args{exit_status}\n";
}
sub after_create_new_table {
my ($self, %args) = @_;
print "PLUGIN after_create_new_table\n";
my $dbh = $self->{aux_cxn}->dbh;
my $new_tbl = $args{new_tbl}->{name};
# Remove PRIMARY KEY, so pt-osc fails with an error and handles
# it in the _die call
$dbh->do("ALTER TABLE ${new_tbl} MODIFY COLUMN id INT NOT NULL, DROP PRIMARY KEY");
}
1;