line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Geoffrey::Action::Constraint::ForeignKey; |
2
|
|
|
|
|
|
|
|
3
|
7
|
|
|
7
|
|
720
|
use utf8; |
|
7
|
|
|
|
|
16
|
|
|
7
|
|
|
|
|
52
|
|
4
|
7
|
|
|
7
|
|
298
|
use 5.016; |
|
7
|
|
|
|
|
28
|
|
5
|
7
|
|
|
7
|
|
34
|
use strict; |
|
7
|
|
|
|
|
14
|
|
|
7
|
|
|
|
|
162
|
|
6
|
7
|
|
|
7
|
|
36
|
use warnings; |
|
7
|
|
|
|
|
13
|
|
|
7
|
|
|
|
|
382
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
$Geoffrey::Action::Constraint::ForeignKey::VERSION = '0.000203'; |
9
|
|
|
|
|
|
|
|
10
|
7
|
|
|
7
|
|
48
|
use parent 'Geoffrey::Role::Action'; |
|
7
|
|
|
|
|
14
|
|
|
7
|
|
|
|
|
40
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub add { |
13
|
25
|
|
|
25
|
1
|
8041
|
my ($self, $hr_params) = @_; |
14
|
25
|
|
|
|
|
570
|
require Ref::Util; |
15
|
25
|
100
|
|
|
|
1659
|
if (!Ref::Util::is_hashref($hr_params)) { |
16
|
1
|
|
|
|
|
502
|
require Geoffrey::Exception::General; |
17
|
1
|
|
|
|
|
31
|
Geoffrey::Exception::General::throw_wrong_ref(__PACKAGE__ . '::add', 'hash'); |
18
|
|
|
|
|
|
|
} |
19
|
24
|
100
|
|
|
|
81
|
if (!$self->converter->foreign_key) { |
20
|
1
|
|
|
|
|
5
|
require Geoffrey::Exception::NotSupportedException; |
21
|
1
|
|
|
|
|
4
|
Geoffrey::Exception::NotSupportedException::throw_foreignkey('add', $self->converter); |
22
|
|
|
|
|
|
|
} |
23
|
23
|
100
|
|
|
|
1188
|
if (!exists $hr_params->{table}) { |
24
|
1
|
|
|
|
|
516
|
require Geoffrey::Exception::RequiredValue; |
25
|
1
|
|
|
|
|
4
|
Geoffrey::Exception::RequiredValue::throw_table_name(); |
26
|
|
|
|
|
|
|
} |
27
|
22
|
50
|
66
|
|
|
149
|
if ( !exists $hr_params->{column} |
|
|
|
33
|
|
|
|
|
28
|
|
|
|
|
|
|
|| !exists $hr_params->{reftable} |
29
|
|
|
|
|
|
|
|| !exists $hr_params->{refcolumn}) |
30
|
|
|
|
|
|
|
{ |
31
|
3
|
|
|
|
|
11
|
require Geoffrey::Exception::RequiredValue; |
32
|
|
|
|
|
|
|
Geoffrey::Exception::RequiredValue::throw_reftable_missing($hr_params->{table}) |
33
|
3
|
100
|
|
|
|
12
|
if (!exists $hr_params->{reftable}); |
34
|
|
|
|
|
|
|
Geoffrey::Exception::RequiredValue::throw_refcolumn_missing($hr_params->{table}) |
35
|
2
|
100
|
|
|
|
7
|
if (!exists $hr_params->{refcolumn}); |
36
|
|
|
|
|
|
|
Geoffrey::Exception::RequiredValue::throw_table_column($hr_params->{table}) |
37
|
1
|
50
|
|
|
|
6
|
if (!exists $hr_params->{column}); |
38
|
|
|
|
|
|
|
} |
39
|
19
|
|
|
|
|
54
|
$hr_params->{reftable} =~ s/"//g; |
40
|
19
|
|
|
|
|
43
|
$hr_params->{table} =~ s/"//g; |
41
|
19
|
|
|
|
|
542
|
require Geoffrey::Utils; |
42
|
|
|
|
|
|
|
my $s_sql = Geoffrey::Utils::replace_spare( |
43
|
|
|
|
|
|
|
$self->converter->foreign_key->add, |
44
|
|
|
|
|
|
|
[ |
45
|
|
|
|
|
|
|
$hr_params->{column}, |
46
|
|
|
|
|
|
|
(exists $hr_params->{schema} ? $hr_params->{schema} . q/./ : q//) |
47
|
|
|
|
|
|
|
. $hr_params->{reftable}, |
48
|
|
|
|
|
|
|
$hr_params->{refcolumn}, |
49
|
19
|
50
|
|
|
|
58
|
qq~fkey_$hr_params->{table}~ . q~_~ . time |
50
|
|
|
|
|
|
|
]); |
51
|
19
|
100
|
|
|
|
71
|
return $s_sql if $self->for_table; |
52
|
2
|
|
|
|
|
15
|
return $self->do($s_sql); |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub alter { |
57
|
6
|
|
|
6
|
1
|
3306
|
my ($self, $hr_params) = @_; |
58
|
6
|
50
|
|
|
|
26
|
if (!exists $hr_params->{name}) { |
59
|
0
|
|
|
|
|
0
|
require Geoffrey::Exception::RequiredValue; |
60
|
0
|
|
|
|
|
0
|
Geoffrey::Exception::RequiredValue::throw_index_name(__PACKAGE__ . '::alter'); |
61
|
|
|
|
|
|
|
} |
62
|
6
|
100
|
|
|
|
22
|
if (!$self->converter->foreign_key) { |
63
|
1
|
|
|
|
|
7
|
require Geoffrey::Exception::NotSupportedException; |
64
|
1
|
|
|
|
|
4
|
Geoffrey::Exception::NotSupportedException::throw_foreignkey('alter', $self->converter); |
65
|
|
|
|
|
|
|
} |
66
|
5
|
|
|
|
|
18
|
return [$self->drop($hr_params), $self->add($hr_params),]; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub drop { |
70
|
10
|
|
|
10
|
1
|
3590
|
my ($self, $hr_params) = @_; |
71
|
10
|
100
|
|
|
|
33
|
if (!$self->converter->foreign_key) { |
72
|
1
|
|
|
|
|
7
|
require Geoffrey::Exception::NotSupportedException; |
73
|
1
|
|
|
|
|
4
|
Geoffrey::Exception::NotSupportedException::throw_foreignkey('drop', |
74
|
|
|
|
|
|
|
$self->converter->foreign_key); |
75
|
|
|
|
|
|
|
} |
76
|
9
|
|
|
|
|
535
|
require Geoffrey::Utils; |
77
|
|
|
|
|
|
|
my $s_sql = Geoffrey::Utils::replace_spare($self->converter->foreign_key->drop, |
78
|
9
|
|
|
|
|
32
|
[$hr_params->{table}, $hr_params->{name}]); |
79
|
2
|
50
|
|
|
|
13
|
return $s_sql if $self->for_table; |
80
|
2
|
|
|
|
|
12
|
return $self->do($s_sql); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub list_from_schema { |
84
|
4
|
|
|
4
|
1
|
3280
|
my ($self, $schema) = @_; |
85
|
4
|
|
|
|
|
19
|
my $converter = $self->converter; |
86
|
4
|
100
|
|
|
|
13
|
if (!$self->converter->foreign_key) { |
87
|
1
|
|
|
|
|
6
|
require Geoffrey::Exception::NotSupportedException; |
88
|
1
|
|
|
|
|
4
|
Geoffrey::Exception::NotSupportedException::throw_foreignkey('list', $self->converter); |
89
|
|
|
|
|
|
|
} |
90
|
3
|
|
|
|
|
15
|
return $converter->foreignkey_information( |
91
|
|
|
|
|
|
|
$self->do_arrayref($self->converter->foreign_key->list($schema))); |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
1; |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
__END__ |