-
Notifications
You must be signed in to change notification settings - Fork 0
/
DropFks.pm
80 lines (60 loc) · 1.48 KB
/
DropFks.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package MySQL::Util::Test::DropFks;
use Modern::Perl;
use Carp;
use Data::Dumper;
use Test::More;
use MySQL::Util;
use Smart::Args;
use lib '.', './t';
use MySQL::Util::Test::Common qw(
load_db
get_mysql_util
);
sub run {
my $self = shift;
$self->no_table;
$self->with_table;
}
sub with_table {
my $self = shift;
my $util = $self->{util};
my $aref = $util->drop_fks('depth_2a');
ok( ref $aref eq 'ARRAY');
ok( scalar @$aref == 2);
my $href = $util->get_fk_constraints('depth_2a');
ok( ( scalar keys %$href ) == 0);
$href = $util->get_fk_constraints;
ok( ( scalar keys %$href ) == 5);
ok( $util->apply_ddl($aref) );
$href = $util->get_fk_constraints('depth_2a');
ok( ( scalar keys %$href ) == 2);
$href = $util->get_fk_constraints;
ok( ( scalar keys %$href ) == 7);
}
sub no_table {
my $self = shift;
my $util = $self->{util};
my $aref = $util->drop_fks;
ok( ref $aref eq 'ARRAY');
ok( scalar @$aref == 7);
my $href = $util->get_fk_constraints;
ok( ( scalar keys %$href ) == 0);
ok( $util->apply_ddl($aref) );
$href = $util->get_fk_constraints;
ok( ( scalar keys %$href ) == 7);
}
sub new {
args
# required
my $class => 'Str',
# optional
my $util => { optional => 1, isa => 'MySQL::Util' },
my $load_db => { optional => 1, isa => 'Bool', default => 1 };
my $self = {};
if ($load_db) {
load_db();
}
$self->{util} = $util ? $util : get_mysql_util();
return bless $self, $class;
}
1;