X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=sql%2FPg-upgrade2%2Fadd_more_constraints_fibu_projekt_xplace.pl;h=187eea4042c70e364966f2a33b5395bc3b281fcd;hb=53593baa211863fbf66540cf1bcc36c8fb37257f;hp=dd3705caa817e5dac59ec0fe1b61cb31b1676308;hpb=31f58869614150bf0423d83120deac1b21b1411e;p=kivitendo-erp.git diff --git a/sql/Pg-upgrade2/add_more_constraints_fibu_projekt_xplace.pl b/sql/Pg-upgrade2/add_more_constraints_fibu_projekt_xplace.pl index dd3705caa..187eea404 100644 --- a/sql/Pg-upgrade2/add_more_constraints_fibu_projekt_xplace.pl +++ b/sql/Pg-upgrade2/add_more_constraints_fibu_projekt_xplace.pl @@ -1,49 +1,38 @@ # @tag: add_more_constraints_fibu_projekt_xplace3 # @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. # @depends: release_2_6_0 fix_acc_trans_ap_taxkey_bug -# @charset: utf-8 +package SL::DBUpgrade2::add_more_constraints_fibu_projekt_xplace3; use strict; -use Data::Dumper; -die("This script cannot be run from the command line.") unless ($main::form); +use utf8; -sub mydberror { - my ($msg) = @_; - die($dbup_locale->text("Database update error:") . - "
$msg
" . $DBI::errstr); -} +use parent qw(SL::DBUpgrade2::Base); -sub do_query { - my ($query, $may_fail) = @_; +use SL::DBUtils; - if (!$dbh->do($query)) { - mydberror($query) unless ($may_fail); - $dbh->rollback(); - $dbh->begin_work(); - } -} +sub run { + my ($self) = @_; -sub do_update { my @queries; - # die project_id in der acc_trans ist auch zwingend fremdschlüssel in project + # die project_id in der acc_trans ist auch zwingend fremdschlüssel in project push @queries, "ALTER TABLE acc_trans ADD FOREIGN KEY (project_id) REFERENCES project(id)"; my $query = qq|select count(*) from acc_trans where chart_id is NULL|; - my $sth_all_groups = prepare_execute_query($form, $dbh, $query); + my $sth_all_groups = prepare_execute_query($::form, $self->dbh, $query); while (my $hash_ref = $sth_all_groups->fetchrow_hashref()) { # Schleife if ($hash_ref->{count} eq 0){ - # Falls wir keine alte buggy Installation haben, ist es super die + # Falls wir keine alte buggy Installation haben, ist es super die # Gewissheit zu haben, dass kein acc_trans-Eintrag ohne chart_id vorhanden ist push @queries, "ALTER TABLE acc_trans ALTER COLUMN chart_id SET NOT NULL"; } } $sth_all_groups->finish(); - my $query = qq|select count(*) from acc_trans where trans_id is NULL|; - my $sth_all_groups = prepare_execute_query($form, $dbh, $query); + $query = qq|select count(*) from acc_trans where trans_id is NULL|; + $sth_all_groups = prepare_execute_query($::form, $self->dbh, $query); while (my $hash_ref = $sth_all_groups->fetchrow_hashref()) { # Schleife if ($hash_ref->{count} eq 0){ - # Falls wir keine alte buggy Installation haben, ist es super die + # Falls wir keine alte buggy Installation haben, ist es super die # Gewissheit zu haben, dass kein acc_trans-Eintrag ohne trans_id vorhanden ist push @queries, "ALTER TABLE acc_trans ALTER COLUMN trans_id SET NOT NULL"; } @@ -52,13 +41,11 @@ sub do_update { # if in doubt use brute force ;-) jb foreach my $query (@queries){ - my $sth = prepare_query($form, $dbh, $query); - do_statement($form,$sth,$query); + my $sth = prepare_query($::form, $self->dbh, $query); + do_statement($::form,$sth,$query); $sth->finish(); } - $dbh ->commit(); return 1; } -return do_update(); - +1;