Closed Bug 1021218 Opened 10 years ago Closed 10 years ago

merge-users.pl fails if both users have bug_user_last_visit entries for the same bug

Categories

(Bugzilla :: Administration, task)

task
Not set
major

Tracking

()

RESOLVED FIXED
Bugzilla 5.0

People

(Reporter: dkl, Assigned: dkl)

References

Details

(Keywords: regression)

Attachments

(1 file)

When running a user merge for bug 1021105, the following error occurred:

bugzillaadm.private.scl3# time perl -T ./contrib/merge-users.pl jbeich@tormail.org jbeich@vfemail.net
OK, old user account jbeich@tormail.org found; user ID: 447677.
OK, new user account jbeich@vfemail.net found; user ID: 508500.
.
.
.
OK, records in the 'watched' column of the 'watch' table
have been migrated to the new user account.
DBD::mysql::st execute failed: Duplicate entry '508500-1021105' for key 'bug_user_last_visit_idx' [for Statement "UPDATE bug_user_last_visit
                                           SET user_id = ?
                                         WHERE user_id = ?" with ParamValues: 0=508500, 1=447677] at ./contrib/merge-users.pl line 217

This is due to the unique index on user_id,bug_id and the way merge-users.pl updates user id values in tables that have a foreign key relationship to profiles.userid.

I suppose the solution would be 1) use a query to find any duplicates and 2) use separate queries to remove the row with the old user id and leave the other in place.

Thoughts? 
dkl
merge-users is from upstream, moving.

i suspect the right thing to do is to retain the most recent last-visit time for each bug.
Assignee: nobody → administration
Product: bugzilla.mozilla.org → Bugzilla
QA Contact: default-qa
Version: Production → unspecified
Attached patch 1021218_1.patchSplinter Review
Assignee: administration → dkl
Status: NEW → ASSIGNED
Attachment #8435884 - Flags: review?(glob)
Comment on attachment 8435884 [details] [diff] [review]
1021218_1.patch

Review of attachment 8435884 [details] [diff] [review]:
-----------------------------------------------------------------

r=glob

switch to using earlier.id on commit please.

::: contrib/merge-users.pl
@@ +148,5 @@
> +# Special care needs to be done with bug_user_last_visit table as the
> +# source user and destination user may have visited the same bug id at one time.
> +# In this case we remove the one with the oldest timestamp.
> +my $dupe_bug_entries = $dbh->selectall_arrayref("
> +    SELECT DISTINCT earlier.user_id, earlier.bug_id, earlier.last_visit_ts

it would be better to select earlier.id and delete rows by id
Attachment #8435884 - Flags: review?(glob) → review+
Flags: approval+
Target Milestone: --- → Bugzilla 5.0
To ssh://gitolite3@git.mozilla.org/bugzilla/bugzilla.git
   1f859a3..ea10fef  master -> master
Status: ASSIGNED → RESOLVED
Closed: 10 years ago
Resolution: --- → FIXED
Blocks: 1027182
Blocks: 1056087
Depends on: 489028
Keywords: regression
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: