Line 0
Link Here
|
0 |
- |
1 |
use Modern::Perl; |
|
|
2 |
|
3 |
return { |
4 |
bug_number => "36755", |
5 |
description => "Increase length of 'code' column in borrower_attribute_types", |
6 |
up => sub { |
7 |
my ($args) = @_; |
8 |
my ( $dbh, $out ) = @$args{qw(dbh out)}; |
9 |
|
10 |
# Drop related tables constraints |
11 |
if ( foreign_key_exists( 'pseudonymized_borrower_attributes', 'anonymized_borrower_attributes_ibfk_2' ) ) { |
12 |
$dbh->do( |
13 |
q{ALTER TABLE pseudonymized_borrower_attributes DROP FOREIGN KEY anonymized_borrower_attributes_ibfk_2} |
14 |
); |
15 |
} |
16 |
if ( foreign_key_exists( 'borrower_attribute_types_branches', 'borrower_attribute_types_branches_ibfk_1' ) ) { |
17 |
$dbh->do( |
18 |
q{ALTER TABLE borrower_attribute_types_branches DROP FOREIGN KEY borrower_attribute_types_branches_ibfk_1} |
19 |
); |
20 |
} |
21 |
if ( foreign_key_exists( 'borrower_attributes', 'borrower_attributes_ibfk_2' ) ) { |
22 |
$dbh->do(q{ALTER TABLE borrower_attributes DROP FOREIGN KEY borrower_attributes_ibfk_2}); |
23 |
} |
24 |
|
25 |
# Update the column we want |
26 |
unless ( foreign_key_exists( 'pseudonymized_borrower_attributes', 'anonymized_borrower_attributes_ibfk_2' ) |
27 |
|| foreign_key_exists( 'borrower_attribute_types_branches', 'borrower_attribute_types_branches_ibfk_1' ) |
28 |
|| foreign_key_exists( 'borrower_attributes', 'borrower_attributes_ibfk_2' ) ) |
29 |
{ |
30 |
$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'} |
32 |
); |
33 |
} |
34 |
|
35 |
# Update the related tables |
36 |
unless ( foreign_key_exists( 'pseudonymized_borrower_attributes', 'anonymized_borrower_attributes_ibfk_2' ) ) { |
37 |
$dbh->do( |
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'} |
39 |
); |
40 |
} |
41 |
unless ( foreign_key_exists( 'borrower_attribute_types_branches', 'borrower_attribute_types_branches_ibfk_1' ) ) |
42 |
{ |
43 |
$dbh->do(q{ALTER TABLE borrower_attribute_types_branches MODIFY COLUMN bat_code VARCHAR(64) DEFAULT NULL}); |
44 |
} |
45 |
unless ( foreign_key_exists( 'borrower_attributes', 'borrower_attributes_ibfk_2' ) ) { |
46 |
$dbh->do( |
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'} |
48 |
); |
49 |
} |
50 |
|
51 |
# Restore related tables constraints |
52 |
unless ( foreign_key_exists( 'pseudonymized_borrower_attributes', 'anonymized_borrower_attributes_ibfk_2' ) ) { |
53 |
$dbh->do( |
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} |
55 |
); |
56 |
} |
57 |
unless ( foreign_key_exists( 'borrower_attribute_types_branches', 'borrower_attribute_types_branches_ibfk_1' ) ) |
58 |
{ |
59 |
$dbh->do( |
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} |
61 |
); |
62 |
} |
63 |
unless ( foreign_key_exists( 'borrower_attributes', 'borrower_attributes_ibfk_2' ) ) { |
64 |
$dbh->do( |
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} |
66 |
); |
67 |
} |
68 |
|
69 |
# HTML customizations |
70 |
say $out "Increased borrower_attribute_types.code column length from 10 to 64"; |
71 |
}, |
72 |
}; |