5 description => "Check borrower_attribute_types FK constraint",
8 my ($dbh, $out) = @$args{qw(dbh out)};
10 if( foreign_key_exists('borrower_attribute_types', 'category_code_fk') ) {
11 $dbh->do( q|ALTER TABLE borrower_attribute_types DROP FOREIGN KEY category_code_fk| );
12 if( index_exists('borrower_attribute_types', 'category_code_fk') ) {
13 $dbh->do( q|ALTER TABLE borrower_attribute_types DROP INDEX category_code_fk| );
19 'borrower_attribute_types', 'borrower_attribute_types_ibfk_1'
24 my $sth = $dbh->prepare(
27 FROM borrower_attribute_types
28 WHERE category_code NOT IN (SELECT categorycode FROM categories);
34 my @invalid_categories;
35 while ( my $row = $sth->fetchrow_arrayref() ) {
36 push( @invalid_categories, $row->[0] );
39 if (@invalid_categories) {
40 die "The 'borrower_attribute_types' table contains "
41 . "references to invalid category codes: "
42 . join( ', ', @invalid_categories );
45 if ( !index_exists( 'borrower_attribute_types', 'category_code' ) )
48 ALTER TABLE borrower_attribute_types ADD INDEX category_code (category_code)
52 ALTER TABLE borrower_attribute_types
53 ADD CONSTRAINT borrower_attribute_types_ibfk_1 FOREIGN KEY (`category_code`) REFERENCES `categories` (`categorycode`)