From: Moritz Bunkus Date: Tue, 4 Jan 2011 10:23:34 +0000 (+0100) Subject: Upgradescript, das die Eindeutigkeit von acc_trans.acc_trans_id sicherstellt X-Git-Tag: release-2.6.2beta1~5 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=7f224f6e7d50a0e3d9e644f15b05c0804d348a66;p=kivitendo-erp.git Upgradescript, das die Eindeutigkeit von acc_trans.acc_trans_id sicherstellt Wird aufgrund von Bugs benötigt, bevor acc_trans.acc_trans_id zum Primärschlüssel gemacht werden kann. --- diff --git a/sql/Pg-upgrade2/acc_trans_id_uniqueness.pl b/sql/Pg-upgrade2/acc_trans_id_uniqueness.pl new file mode 100644 index 000000000..9c0c4595a --- /dev/null +++ b/sql/Pg-upgrade2/acc_trans_id_uniqueness.pl @@ -0,0 +1,72 @@ +# @tag: acc_trans_id_uniqueness +# @description: Sorgt dafür, dass acc_trans.acc_trans_id eindeutig ist +# @depends: release_2_6_1 +# @charset: utf-8 + +use utf8; +use strict; +use Data::Dumper; + +die "This script cannot be run from the command line." unless $::form; + +sub mydberror { + my ($msg) = @_; + die $dbup_locale->text("Database update error:") . "
$msg
" . $DBI::errstr; +} + +sub do_query { + my ($query, $may_fail) = @_; + + return if $dbh->do($query); + + mydberror($query) unless ($may_fail); + $dbh->rollback(); + $dbh->begin_work(); +} + +sub do_update { + my $query = < 1 + ) + ORDER BY trans_id, itime, mtime NULLS FIRST +SQL + + my @entries = selectall_hashref_query($form, $dbh, $query); + + return 1 unless @entries; + + $query = <{trans_id} }) { + $entries_by_trans_id{ $entry->{trans_id} } = []; + } else { + my $mtime = $entry->{mtime} ? "= '$entry->{mtime}'" : 'IS NULL'; + $query = <{acc_trans_id}) + AND (trans_id = $entry->{trans_id}) + AND (itime = '$entry->{itime}') + AND (mtime $mtime) +SQL + + do_query($query, 0); + } + } + + return 1; +} + +return do_update(); diff --git a/sql/Pg-upgrade2/schema_normalization_3.sql b/sql/Pg-upgrade2/schema_normalization_3.sql index 528fc8f1b..dd8b3303a 100644 --- a/sql/Pg-upgrade2/schema_normalization_3.sql +++ b/sql/Pg-upgrade2/schema_normalization_3.sql @@ -1,6 +1,6 @@ -- @tag: schema_normalization_3 -- @description: Datenbankschema Normalisierungen Teil 3 --- @depends: schema_normalization_2 +-- @depends: schema_normalization_2 acc_trans_id_uniqueness ALTER TABLE acc_trans DROP COLUMN id; ALTER TABLE acc_trans ADD PRIMARY KEY (acc_trans_id);