line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Geoffrey::Action::Constraint::ForeignKey; |
2
|
|
|
|
|
|
|
|
3
|
7
|
|
|
7
|
|
746
|
use utf8; |
|
7
|
|
|
|
|
15
|
|
|
7
|
|
|
|
|
50
|
|
4
|
7
|
|
|
7
|
|
278
|
use 5.016; |
|
7
|
|
|
|
|
24
|
|
5
|
7
|
|
|
7
|
|
36
|
use strict; |
|
7
|
|
|
|
|
13
|
|
|
7
|
|
|
|
|
174
|
|
6
|
7
|
|
|
7
|
|
36
|
use warnings; |
|
7
|
|
|
|
|
14
|
|
|
7
|
|
|
|
|
364
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
$Geoffrey::Action::Constraint::ForeignKey::VERSION = '0.000205'; |
9
|
|
|
|
|
|
|
|
10
|
7
|
|
|
7
|
|
52
|
use parent 'Geoffrey::Role::Action'; |
|
7
|
|
|
|
|
13
|
|
|
7
|
|
|
|
|
35
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub add { |
13
|
25
|
|
|
25
|
1
|
7998
|
my ($self, $hr_params) = @_; |
14
|
25
|
|
|
|
|
595
|
require Ref::Util; |
15
|
25
|
100
|
|
|
|
2776
|
if (!Ref::Util::is_hashref($hr_params)) { |
16
|
1
|
|
|
|
|
474
|
require Geoffrey::Exception::General; |
17
|
1
|
|
|
|
|
33
|
Geoffrey::Exception::General::throw_wrong_ref(__PACKAGE__ . '::add', 'hash'); |
18
|
|
|
|
|
|
|
} |
19
|
24
|
100
|
|
|
|
78
|
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
|
|
|
|
65
|
if (!exists $hr_params->{table}) { |
24
|
1
|
|
|
|
|
508
|
require Geoffrey::Exception::RequiredValue; |
25
|
1
|
|
|
|
|
4
|
Geoffrey::Exception::RequiredValue::throw_table_name(); |
26
|
|
|
|
|
|
|
} |
27
|
22
|
50
|
66
|
|
|
118
|
if ( !exists $hr_params->{column} |
|
|
|
33
|
|
|
|
|
28
|
|
|
|
|
|
|
|| !exists $hr_params->{reftable} |
29
|
|
|
|
|
|
|
|| !exists $hr_params->{refcolumn}) |
30
|
|
|
|
|
|
|
{ |
31
|
3
|
|
|
|
|
13
|
require Geoffrey::Exception::RequiredValue; |
32
|
|
|
|
|
|
|
Geoffrey::Exception::RequiredValue::throw_reftable_missing($hr_params->{table}) |
33
|
3
|
100
|
|
|
|
10
|
if (!exists $hr_params->{reftable}); |
34
|
|
|
|
|
|
|
Geoffrey::Exception::RequiredValue::throw_refcolumn_missing($hr_params->{table}) |
35
|
2
|
100
|
|
|
|
8
|
if (!exists $hr_params->{refcolumn}); |
36
|
|
|
|
|
|
|
Geoffrey::Exception::RequiredValue::throw_table_column($hr_params->{table}) |
37
|
1
|
50
|
|
|
|
5
|
if (!exists $hr_params->{column}); |
38
|
|
|
|
|
|
|
} |
39
|
19
|
|
|
|
|
56
|
$hr_params->{reftable} =~ s/"//g; |
40
|
19
|
|
|
|
|
38
|
$hr_params->{table} =~ s/"//g; |
41
|
19
|
|
|
|
|
525
|
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
|
|
|
|
54
|
qq~fkey_$hr_params->{table}~ . q~_~ . time |
50
|
|
|
|
|
|
|
]); |
51
|
19
|
100
|
|
|
|
67
|
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
|
3263
|
my ($self, $hr_params) = @_; |
58
|
6
|
50
|
|
|
|
21
|
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
|
|
|
|
54
|
if (!$self->converter->foreign_key) { |
63
|
1
|
|
|
|
|
7
|
require Geoffrey::Exception::NotSupportedException; |
64
|
1
|
|
|
|
|
3
|
Geoffrey::Exception::NotSupportedException::throw_foreignkey('alter', $self->converter); |
65
|
|
|
|
|
|
|
} |
66
|
5
|
|
|
|
|
21
|
return [$self->drop($hr_params), $self->add($hr_params),]; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub drop { |
70
|
10
|
|
|
10
|
1
|
3898
|
my ($self, $hr_params) = @_; |
71
|
10
|
100
|
|
|
|
51
|
if (!$self->converter->foreign_key) { |
72
|
1
|
|
|
|
|
6
|
require Geoffrey::Exception::NotSupportedException; |
73
|
1
|
|
|
|
|
4
|
Geoffrey::Exception::NotSupportedException::throw_foreignkey('drop', |
74
|
|
|
|
|
|
|
$self->converter->foreign_key); |
75
|
|
|
|
|
|
|
} |
76
|
9
|
|
|
|
|
537
|
require Geoffrey::Utils; |
77
|
|
|
|
|
|
|
my $s_sql = Geoffrey::Utils::replace_spare($self->converter->foreign_key->drop, |
78
|
9
|
|
|
|
|
30
|
[$hr_params->{table}, $hr_params->{name}]); |
79
|
2
|
50
|
|
|
|
12
|
return $s_sql if $self->for_table; |
80
|
2
|
|
|
|
|
13
|
return $self->do($s_sql); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub list_from_schema { |
84
|
4
|
|
|
4
|
1
|
3288
|
my ($self, $schema) = @_; |
85
|
4
|
|
|
|
|
17
|
my $converter = $self->converter; |
86
|
4
|
100
|
|
|
|
12
|
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
|
|
|
|
|
11
|
return $converter->foreignkey_information( |
91
|
|
|
|
|
|
|
$self->do_arrayref($self->converter->foreign_key->list($schema))); |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
1; |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
__END__ |