Lines 8-69
return {
Link Here
|
8 |
my ( $dbh, $out ) = @$args{qw(dbh out)}; |
8 |
my ( $dbh, $out ) = @$args{qw(dbh out)}; |
9 |
|
9 |
|
10 |
# Drop related tables constraints |
10 |
# Drop related tables constraints |
11 |
if ( foreign_key_exists( 'pseudonymized_borrower_attributes', 'anonymized_borrower_attributes_ibfk_2' ) ) { |
11 |
if ( TableExists('pseudonymized_borrower_attributes') ) { |
12 |
$dbh->do( |
12 |
if ( foreign_key_exists( 'pseudonymized_borrower_attributes', 'anonymized_borrower_attributes_ibfk_2' ) ) { |
13 |
q{ALTER TABLE pseudonymized_borrower_attributes DROP FOREIGN KEY anonymized_borrower_attributes_ibfk_2} |
13 |
$dbh->do( |
14 |
); |
14 |
q{ALTER TABLE pseudonymized_borrower_attributes DROP FOREIGN KEY anonymized_borrower_attributes_ibfk_2} |
|
|
15 |
); |
16 |
} |
15 |
} |
17 |
} |
16 |
if ( foreign_key_exists( 'borrower_attribute_types_branches', 'borrower_attribute_types_branches_ibfk_1' ) ) { |
18 |
|
17 |
$dbh->do( |
19 |
if ( TableExists('borrower_attribute_types_branches') ) { |
18 |
q{ALTER TABLE borrower_attribute_types_branches DROP FOREIGN KEY borrower_attribute_types_branches_ibfk_1} |
20 |
if ( foreign_key_exists( 'borrower_attribute_types_branches', 'borrower_attribute_types_branches_ibfk_1' ) ) |
19 |
); |
21 |
{ |
|
|
22 |
$dbh->do( |
23 |
q{ALTER TABLE borrower_attribute_types_branches DROP FOREIGN KEY borrower_attribute_types_branches_ibfk_1} |
24 |
); |
25 |
} |
20 |
} |
26 |
} |
21 |
if ( foreign_key_exists( 'borrower_attributes', 'borrower_attributes_ibfk_2' ) ) { |
27 |
|
22 |
$dbh->do(q{ALTER TABLE borrower_attributes DROP FOREIGN KEY borrower_attributes_ibfk_2}); |
28 |
if ( TableExists('borrower_attributes') ) { |
|
|
29 |
if ( foreign_key_exists( 'borrower_attributes', 'borrower_attributes_ibfk_2' ) ) { |
30 |
$dbh->do(q{ALTER TABLE borrower_attributes DROP FOREIGN KEY borrower_attributes_ibfk_2}); |
31 |
} |
23 |
} |
32 |
} |
24 |
|
33 |
|
25 |
# Update the column we want |
34 |
# Update the column we want |
26 |
unless ( foreign_key_exists( 'pseudonymized_borrower_attributes', 'anonymized_borrower_attributes_ibfk_2' ) |
35 |
my $fkcheck1 = 0; |
27 |
|| foreign_key_exists( 'borrower_attribute_types_branches', 'borrower_attribute_types_branches_ibfk_1' ) |
36 |
if ( TableExists('pseudonymized_borrower_attributes') ) { |
28 |
|| foreign_key_exists( 'borrower_attributes', 'borrower_attributes_ibfk_2' ) ) |
37 |
$fkcheck1 = |
29 |
{ |
38 |
foreign_key_exists( 'pseudonymized_borrower_attributes', 'anonymized_borrower_attributes_ibfk_2' ); |
|
|
39 |
} |
40 |
|
41 |
my $fkcheck2 = 0; |
42 |
if ( TableExists('borrower_attribute_types_branches') ) { |
43 |
$fkcheck2 = |
44 |
foreign_key_exists( 'borrower_attribute_types_branches', 'borrower_attribute_types_branches_ibfk_1' ); |
45 |
} |
46 |
|
47 |
my $fkcheck3 = 0; |
48 |
if ( TableExists('borrower_attributes') ) { |
49 |
$fkcheck3 = foreign_key_exists( 'borrower_attributes', 'borrower_attributes_ibfk_2' ); |
50 |
} |
51 |
|
52 |
unless ( $fkcheck1 || $fkcheck2 || $fkcheck3 ) { |
30 |
$dbh->do( |
53 |
$dbh->do( |
31 |
q{ALTER TABLE borrower_attribute_types MODIFY COLUMN code VARCHAR(64) NOT NULL COMMENT 'unique key used to identify each custom field'} |
54 |
q{ALTER TABLE borrower_attribute_types MODIFY COLUMN code VARCHAR(64) NOT NULL COMMENT 'unique key used to identify each custom field'} |
32 |
); |
55 |
); |
33 |
} |
56 |
} |
34 |
|
57 |
|
35 |
# Update the related tables |
58 |
# Update the related tables |
36 |
unless ( foreign_key_exists( 'pseudonymized_borrower_attributes', 'anonymized_borrower_attributes_ibfk_2' ) ) { |
59 |
if ( TableExists('pseudonymized_borrower_attributes') ) { |
37 |
$dbh->do( |
60 |
unless ( |
38 |
q{ALTER TABLE pseudonymized_borrower_attributes MODIFY COLUMN code VARCHAR(64) NOT NULL COMMENT 'foreign key from the borrower_attribute_types table, defines which custom field this value was entered for'} |
61 |
foreign_key_exists( 'pseudonymized_borrower_attributes', 'anonymized_borrower_attributes_ibfk_2' ) ) |
39 |
); |
62 |
{ |
|
|
63 |
$dbh->do( |
64 |
q{ALTER TABLE pseudonymized_borrower_attributes MODIFY COLUMN code VARCHAR(64) NOT NULL COMMENT 'foreign key from the borrower_attribute_types table, defines which custom field this value was entered for'} |
65 |
); |
66 |
} |
40 |
} |
67 |
} |
41 |
unless ( foreign_key_exists( 'borrower_attribute_types_branches', 'borrower_attribute_types_branches_ibfk_1' ) ) |
68 |
|
42 |
{ |
69 |
if ( TableExists('borrower_attribute_types_branches') ) { |
43 |
$dbh->do(q{ALTER TABLE borrower_attribute_types_branches MODIFY COLUMN bat_code VARCHAR(64) DEFAULT NULL}); |
70 |
unless ( |
|
|
71 |
foreign_key_exists( 'borrower_attribute_types_branches', 'borrower_attribute_types_branches_ibfk_1' ) ) |
72 |
{ |
73 |
$dbh->do( |
74 |
q{ALTER TABLE borrower_attribute_types_branches MODIFY COLUMN bat_code VARCHAR(64) DEFAULT NULL}); |
75 |
} |
44 |
} |
76 |
} |
45 |
unless ( foreign_key_exists( 'borrower_attributes', 'borrower_attributes_ibfk_2' ) ) { |
77 |
|
46 |
$dbh->do( |
78 |
if ( TableExists('borrower_attributes') ) { |
47 |
q{ALTER TABLE borrower_attributes MODIFY COLUMN code VARCHAR(64) NOT NULL COMMENT 'foreign key from the borrower_attribute_types table, defines which custom field this value was entered for'} |
79 |
unless ( foreign_key_exists( 'borrower_attributes', 'borrower_attributes_ibfk_2' ) ) { |
48 |
); |
80 |
$dbh->do( |
|
|
81 |
q{ALTER TABLE borrower_attributes MODIFY COLUMN code VARCHAR(64) NOT NULL COMMENT 'foreign key from the borrower_attribute_types table, defines which custom field this value was entered for'} |
82 |
); |
83 |
} |
49 |
} |
84 |
} |
50 |
|
85 |
|
51 |
# Restore related tables constraints |
86 |
# Restore related tables constraints |
52 |
unless ( foreign_key_exists( 'pseudonymized_borrower_attributes', 'anonymized_borrower_attributes_ibfk_2' ) ) { |
87 |
if ( TableExists('pseudonymized_borrower_attributes') ) { |
53 |
$dbh->do( |
88 |
unless ( |
54 |
q{ALTER TABLE pseudonymized_borrower_attributes ADD CONSTRAINT anonymized_borrower_attributes_ibfk_2 FOREIGN KEY (code) REFERENCES borrower_attribute_types(code) ON DELETE CASCADE ON UPDATE CASCADE} |
89 |
foreign_key_exists( 'pseudonymized_borrower_attributes', 'anonymized_borrower_attributes_ibfk_2' ) ) |
55 |
); |
90 |
{ |
|
|
91 |
$dbh->do( |
92 |
q{ALTER TABLE pseudonymized_borrower_attributes ADD CONSTRAINT anonymized_borrower_attributes_ibfk_2 FOREIGN KEY (code) REFERENCES borrower_attribute_types(code) ON DELETE CASCADE ON UPDATE CASCADE} |
93 |
); |
94 |
} |
56 |
} |
95 |
} |
57 |
unless ( foreign_key_exists( 'borrower_attribute_types_branches', 'borrower_attribute_types_branches_ibfk_1' ) ) |
96 |
if ( TableExists('borrower_attribute_types_branches') ) { |
58 |
{ |
97 |
unless ( |
59 |
$dbh->do( |
98 |
foreign_key_exists( 'borrower_attribute_types_branches', 'borrower_attribute_types_branches_ibfk_1' ) ) |
60 |
q{ALTER TABLE borrower_attribute_types_branches ADD CONSTRAINT borrower_attribute_types_branches_ibfk_1 FOREIGN KEY (bat_code) REFERENCES borrower_attribute_types(code) ON DELETE CASCADE} |
99 |
{ |
61 |
); |
100 |
$dbh->do( |
|
|
101 |
q{ALTER TABLE borrower_attribute_types_branches ADD CONSTRAINT borrower_attribute_types_branches_ibfk_1 FOREIGN KEY (bat_code) REFERENCES borrower_attribute_types(code) ON DELETE CASCADE} |
102 |
); |
103 |
} |
62 |
} |
104 |
} |
63 |
unless ( foreign_key_exists( 'borrower_attributes', 'borrower_attributes_ibfk_2' ) ) { |
105 |
|
64 |
$dbh->do( |
106 |
if ( TableExists('borrower_attributes') ) { |
65 |
q{ALTER TABLE borrower_attributes ADD CONSTRAINT borrower_attributes_ibfk_2 FOREIGN KEY (code) REFERENCES borrower_attribute_types(code) ON DELETE CASCADE ON UPDATE CASCADE} |
107 |
unless ( foreign_key_exists( 'borrower_attributes', 'borrower_attributes_ibfk_2' ) ) { |
66 |
); |
108 |
$dbh->do( |
|
|
109 |
q{ALTER TABLE borrower_attributes ADD CONSTRAINT borrower_attributes_ibfk_2 FOREIGN KEY (code) REFERENCES borrower_attribute_types(code) ON DELETE CASCADE ON UPDATE CASCADE} |
110 |
); |
111 |
} |
67 |
} |
112 |
} |
68 |
|
113 |
|
69 |
# HTML customizations |
114 |
# HTML customizations |
70 |
- |
|
|