diff options
author | Dave Lawrence <dlawrence@mozilla.com> | 2012-08-03 05:58:56 +0200 |
---|---|---|
committer | Dave Lawrence <dlawrence@mozilla.com> | 2012-08-03 05:58:56 +0200 |
commit | 23eaf30f1bb04e6698d11689de28dd1067b560e2 (patch) | |
tree | 469b7eb4c144755a3203b5cd53565bb9fa21ca51 | |
parent | 469323e21969579dcdc3a6b913c8ac9df443df70 (diff) | |
download | bugzilla-23eaf30f1bb04e6698d11689de28dd1067b560e2.tar.gz bugzilla-23eaf30f1bb04e6698d11689de28dd1067b560e2.tar.xz |
Bug 756953 - Dependencies table should have unique index so that duplicate entries are blocked
r/a=LpSolit
-rw-r--r-- | Bugzilla/DB/Schema.pm | 3 | ||||
-rw-r--r-- | Bugzilla/Install/DB.pm | 28 |
2 files changed, 30 insertions, 1 deletions
diff --git a/Bugzilla/DB/Schema.pm b/Bugzilla/DB/Schema.pm index 5a88540a9..6dd78d206 100644 --- a/Bugzilla/DB/Schema.pm +++ b/Bugzilla/DB/Schema.pm @@ -436,7 +436,8 @@ use constant ABSTRACT_SCHEMA => { DELETE => 'CASCADE'}}, ], INDEXES => [ - dependencies_blocked_idx => ['blocked'], + dependencies_blocked_idx => {FIELDS => [qw(blocked dependson)], + TYPE => 'UNIQUE'}, dependencies_dependson_idx => ['dependson'], ], }, diff --git a/Bugzilla/Install/DB.pm b/Bugzilla/Install/DB.pm index 5d21d2211..d86d6e177 100644 --- a/Bugzilla/Install/DB.pm +++ b/Bugzilla/Install/DB.pm @@ -690,6 +690,9 @@ sub update_table_definitions { # 2012-07-24 dkl@mozilla.com - Bug 776982 _fix_longdescs_primary_key(); + # 2012-08-02 dkl@mozilla.com - Bug 756953 + _fix_dependencies_dupes(); + ################################################################ # New --TABLE-- changes should go *** A B O V E *** this point # ################################################################ @@ -3726,6 +3729,31 @@ sub _fix_longdescs_primary_key { } } +sub _fix_dependencies_dupes { + my $dbh = Bugzilla->dbh; + my $blocked_idx = $dbh->bz_index_info('dependencies', 'dependencies_blocked_idx'); + if ($blocked_idx && scalar @{$blocked_idx->{'FIELDS'}} < 2) { + # Remove duplicated entries + my $dupes = $dbh->selectall_arrayref(" + SELECT blocked, dependson, COUNT(*) AS count + FROM dependencies " . + $dbh->sql_group_by('blocked, dependson') . " + HAVING COUNT(*) > 1", + { Slice => {} }); + print "Removing duplicated entries from the 'dependencies' table...\n" if @$dupes; + foreach my $dupe (@$dupes) { + $dbh->do("DELETE FROM dependencies + WHERE blocked = ? AND dependson = ?", + undef, $dupe->{blocked}, $dupe->{dependson}); + $dbh->do("INSERT INTO dependencies (blocked, dependson) VALUES (?, ?)", + undef, $dupe->{blocked}, $dupe->{dependson}); + } + $dbh->bz_drop_index('dependencies', 'dependencies_blocked_idx'); + $dbh->bz_add_index('dependencies', 'dependencies_blocked_idx', + { FIELDS => [qw(blocked dependson)], TYPE => 'UNIQUE' }); + } +} + 1; __END__ |