From 470c0d5434952f147749492befca3f486bcb0534 Mon Sep 17 00:00:00 2001 From: Rene Krenn Date: Fri, 31 Jul 2020 14:35:04 +0200 Subject: [PATCH] TT#88001 support backup of tables with additional unique constraints Change-Id: I5a11bcc2b5bd6e2e6cd36cabd8d8beb2cc935632 (cherry picked from commit afa707dffd7b559e86b1e3df5b946f81c27044f6) --- lib/NGCP/Cleanup.pm | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/NGCP/Cleanup.pm b/lib/NGCP/Cleanup.pm index c5bfeb2..67ec5d9 100644 --- a/lib/NGCP/Cleanup.pm +++ b/lib/NGCP/Cleanup.pm @@ -477,15 +477,19 @@ sub delete_loop { my $fieldinfo = $sth->fetchall_hashref('Field'); $sth->finish; my @keycols = (); + my @upsertcols = (); foreach my $fieldname (keys %$fieldinfo) { if (uc($fieldinfo->{$fieldname}->{'Key'}) eq 'PRI') { push @keycols,$fieldname; + } else { + push @upsertcols,$fieldname; } } die "No primary key columns for table $table" unless @keycols; my $primary_key_cols = join(",",@keycols); + my $upsert_cols = join(",", map { $_ . '=VALUES(' . $_ . ')'; } @upsertcols); $dbh->do("create table if not exists $mtable like $table"); @@ -517,6 +521,7 @@ INSERT INTO $mtable SELECT s.* FROM $table AS s INNER JOIN $temp_table AS t USING ($primary_key_cols) +ON DUPLICATE KEY UPDATE $upsert_cols SQL or die "Failed to insert into monthly table $mtable: " . $DBI::errstr; $dbh->do(<