Commit 2541a7dc authored by Dave Lawrence's avatar Dave Lawrence

Bug 824346 - The flaginclusions and flagexclusions DB tables have no UNIQUE index

r/a=LpSolit
parent 11a0cd74
...@@ -640,8 +640,8 @@ use constant ABSTRACT_SCHEMA => { ...@@ -640,8 +640,8 @@ use constant ABSTRACT_SCHEMA => {
DELETE => 'CASCADE'}}, DELETE => 'CASCADE'}},
], ],
INDEXES => [ INDEXES => [
flaginclusions_type_id_idx => flaginclusions_type_id_idx => { FIELDS => [qw(type_id product_id component_id)],
[qw(type_id product_id component_id)], TYPE => 'UNIQUE' },
], ],
}, },
...@@ -661,8 +661,8 @@ use constant ABSTRACT_SCHEMA => { ...@@ -661,8 +661,8 @@ use constant ABSTRACT_SCHEMA => {
DELETE => 'CASCADE'}}, DELETE => 'CASCADE'}},
], ],
INDEXES => [ INDEXES => [
flagexclusions_type_id_idx => flagexclusions_type_id_idx => { FIELDS => [qw(type_id product_id component_id)],
[qw(type_id product_id component_id)], TYPE => 'UNIQUE' },
], ],
}, },
......
...@@ -708,6 +708,9 @@ sub update_table_definitions { ...@@ -708,6 +708,9 @@ sub update_table_definitions {
# 2013-01-02 LpSolit@gmail.com - Bug 824361 # 2013-01-02 LpSolit@gmail.com - Bug 824361
_fix_longdescs_indexes(); _fix_longdescs_indexes();
# 2013-02-04 dkl@mozilla.com - Bug 824346
_fix_flagclusions_indexes();
################################################################ ################################################################
# New --TABLE-- changes should go *** A B O V E *** this point # # New --TABLE-- changes should go *** A B O V E *** this point #
################################################################ ################################################################
...@@ -3825,6 +3828,35 @@ sub _add_password_salt_separator { ...@@ -3825,6 +3828,35 @@ sub _add_password_salt_separator {
$dbh->bz_commit_transaction(); $dbh->bz_commit_transaction();
} }
sub _fix_flagclusions_indexes {
my $dbh = Bugzilla->dbh;
foreach my $table ('flaginclusions', 'flagexclusions') {
my $index = $table . '_type_id_idx';
my $idx_info = $dbh->bz_index_info($table, $index);
if ($idx_info && $idx_info->{'TYPE'} ne 'UNIQUE') {
# Remove duplicated entries
my $dupes = $dbh->selectall_arrayref("
SELECT type_id, product_id, component_id, COUNT(*) AS count
FROM $table " .
$dbh->sql_group_by('type_id, product_id, component_id') . "
HAVING COUNT(*) > 1",
{ Slice => {} });
say "Removing duplicated entries from the '$table' table..." if @$dupes;
foreach my $dupe (@$dupes) {
$dbh->do("DELETE FROM $table
WHERE type_id = ? AND product_id = ? AND component_id = ?",
undef, $dupe->{type_id}, $dupe->{product_id}, $dupe->{component_id});
$dbh->do("INSERT INTO $table (type_id, product_id, component_id) VALUES (?, ?, ?)",
undef, $dupe->{type_id}, $dupe->{product_id}, $dupe->{component_id});
}
$dbh->bz_drop_index($table, $index);
$dbh->bz_add_index($table, $index,
{ FIELDS => [qw(type_id product_id component_id)],
TYPE => 'UNIQUE' });
}
}
}
1; 1;
__END__ __END__
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment