X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=sql%2FPg-upgrade2%2Fadd_more_constraints_fibu_projekt_xplace.pl;h=187eea4042c70e364966f2a33b5395bc3b281fcd;hb=97a6f6d623a9810e1d324f44a5f8bcd12294f5d3;hp=c9c720b0c609ab17b526e4001c9a8df9420b4c3b;hpb=4602be1fb9b8e38e36a86c40fce59db74c62949e;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 c9c720b0c..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,50 +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 utf8; 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"; } @@ -53,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;