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
9 die("This script cannot be run from the command line.") unless ($main::form);
13 die($dbup_locale->text("Database update error:") .
14 "<br>$msg<br>" . $DBI::errstr);
18 my ($query, $may_fail) = @_;
20 if (!$dbh->do($query)) {
21 mydberror($query) unless ($may_fail);
30 # die project_id in der acc_trans ist auch zwingend fremdschlüssel in project
31 push @queries, "ALTER TABLE acc_trans ADD FOREIGN KEY (project_id) REFERENCES project(id)";
33 my $query = qq|select count(*) from acc_trans where chart_id is NULL|;
34 my $sth_all_groups = prepare_execute_query($form, $dbh, $query);
35 while (my $hash_ref = $sth_all_groups->fetchrow_hashref()) { # Schleife
36 if ($hash_ref->{count} eq 0){
37 # Falls wir keine alte buggy Installation haben, ist es super die
38 # Gewissheit zu haben, dass kein acc_trans-Eintrag ohne chart_id vorhanden ist
39 push @queries, "ALTER TABLE acc_trans ALTER COLUMN chart_id SET NOT NULL";
42 $sth_all_groups->finish();
43 my $query = qq|select count(*) from acc_trans where trans_id is NULL|;
44 my $sth_all_groups = prepare_execute_query($form, $dbh, $query);
45 while (my $hash_ref = $sth_all_groups->fetchrow_hashref()) { # Schleife
46 if ($hash_ref->{count} eq 0){
47 # Falls wir keine alte buggy Installation haben, ist es super die
48 # Gewissheit zu haben, dass kein acc_trans-Eintrag ohne trans_id vorhanden ist
49 push @queries, "ALTER TABLE acc_trans ALTER COLUMN trans_id SET NOT NULL";
52 $sth_all_groups->finish();
54 # if in doubt use brute force ;-) jb
55 foreach my $query (@queries){
56 my $sth = prepare_query($form, $dbh, $query);
57 do_statement($form,$sth,$query);