1 # @tag: add_more_constraints_fibu_projekt_xplace3
2 # @description: Falls der Datenbestand es unproblematisch hergibt, ein paar 'schärfere' Constraints für die acc_trans gesetzt. Keine acc_trans-Eintrag ohne trans_id oder chart_id. Ferner project_id in acc_trans als Fremdschlüssel für project definiert.
3 # @depends: release_2_6_0 fix_acc_trans_ap_taxkey_bug
8 die("This script cannot be run from the command line.") unless ($main::form);
12 die($dbup_locale->text("Database update error:") .
13 "<br>$msg<br>" . $DBI::errstr);
17 my ($query, $may_fail) = @_;
19 if (!$dbh->do($query)) {
20 mydberror($query) unless ($may_fail);
29 # die project_id in der acc_trans ist auch zwingend fremdschlüssel in project
30 push @queries, "ALTER TABLE acc_trans ADD FOREIGN KEY (project_id) REFERENCES project(id)";
32 my $query = qq|select count(*) from acc_trans where chart_id is NULL|;
33 my $sth_all_groups = prepare_execute_query($form, $dbh, $query);
34 while (my $hash_ref = $sth_all_groups->fetchrow_hashref()) { # Schleife
35 if ($hash_ref->{count} eq 0){
36 # Falls wir keine alte buggy Installation haben, ist es super die
37 # Gewissheit zu haben, dass kein acc_trans-Eintrag ohne chart_id vorhanden ist
38 push @queries, "ALTER TABLE acc_trans ALTER COLUMN chart_id SET NOT NULL";
41 $sth_all_groups->finish();
42 my $query = qq|select count(*) from acc_trans where trans_id is NULL|;
43 my $sth_all_groups = prepare_execute_query($form, $dbh, $query);
44 while (my $hash_ref = $sth_all_groups->fetchrow_hashref()) { # Schleife
45 if ($hash_ref->{count} eq 0){
46 # Falls wir keine alte buggy Installation haben, ist es super die
47 # Gewissheit zu haben, dass kein acc_trans-Eintrag ohne trans_id vorhanden ist
48 push @queries, "ALTER TABLE acc_trans ALTER COLUMN trans_id SET NOT NULL";
51 $sth_all_groups->finish();
53 # if in doubt use brute force ;-) jb
54 foreach my $query (@queries){
55 my $sth = prepare_query($form, $dbh, $query);
56 do_statement($form,$sth,$query);