Line 0
Link Here
|
|
|
1 |
$DBversion = 'XXX'; # will be replaced by the RM |
2 |
if( CheckVersion( $DBversion ) ) { |
3 |
my $count_missing_budget = $dbh->selectrow_arrayref(q| |
4 |
SELECT COUNT(*) FROM aqbudgets ab WHERE NOT EXISTS |
5 |
(SELECT * FROM aqbudgetperiods abp WHERE abp.budget_period_id = ab.budget_period_id) |
6 |
|
7 |
|); |
8 |
|
9 |
if ( !foreign_key_exists( 'aqbudgets', 'aqbudgetperiods_ibfk_1' ) && $count_missing_budget->[0] == 0 ) { |
10 |
$dbh->do(q| |
11 |
ALTER TABLE aqbudgets ADD CONSTRAINT `aqbudgetperiods_ibfk_1` FOREIGN KEY (`budget_period_id`) REFERENCES `aqbudgetperiods` (`budget_period_id`) ON UPDATE CASCADE ON DELETE CASCADE |
12 |
|); |
13 |
NewVersion( $DBversion, 18050, "Add FK constraint on aqbudgets.budget_period_id"); |
14 |
} elsif ( $count_missing_budget->[0] > 0 ) { |
15 |
NewVersion( $DBversion, 18050, "FK constraint on aqbudgets.budget_period_id couldn't be added. There are $count_missing_budget->[0] funds in your database that are not linked to a valid budget."); |
16 |
} else { |
17 |
NewVersion( $DBversion, 18050, "FK constraint on aqbudgets.budget already exists"); |
18 |
} |
19 |
|
20 |
} |