@@ -, +, @@ adding the uniq constraint --- installer/data/mysql/atomicupdate/bug_21674.perl | 13 +++++++++++++ 1 file changed, 13 insertions(+) --- a/installer/data/mysql/atomicupdate/bug_21674.perl +++ a/installer/data/mysql/atomicupdate/bug_21674.perl @@ -1,6 +1,19 @@ $DBversion = 'XXX'; # will be replaced by the RM if( CheckVersion( $DBversion ) ) { if( !index_exists( 'library_groups', 'library_groups_uniq_2' ) ) { + my $library_groups = $dbh->selectall_arrayref(q|SELECT id, parent_id, branchcode FROM library_groups|, { Slice => {} }); + my %existing_groups; + for my $g ( @$library_groups ) { + + next unless $g->{parent_id}; + + unless ( exists $existing_groups{$g->{parent_id}}{$g->{branchcode}} ) { + $existing_groups{$g->{parent_id}}{$g->{branchcode}} = 1; + next; + } + + $dbh->do(q|DELETE FROM library_groups WHERE id=?|, undef, $g->{id}); + } $dbh->do(q| ALTER TABLE library_groups ADD UNIQUE KEY library_groups_uniq_2 (parent_id, branchcode) --