summaryrefslogtreecommitdiffstats
path: root/contrib
diff options
context:
space:
mode:
authorMax Kanat-Alexander <mkanat@bugzilla.org>2010-03-16 06:43:16 +0100
committerMax Kanat-Alexander <mkanat@bugzilla.org>2010-03-16 06:43:16 +0100
commita41f75ddfe91e2da353caa2fcf6afba7b5ee2ca6 (patch)
tree63d8a7b1b9ad80591c70aec86e1e6817f0893ad1 /contrib
parent0ee52e9d7d307d6ceed73a53de1a64589bb79f62 (diff)
downloadbugzilla-a41f75ddfe91e2da353caa2fcf6afba7b5ee2ca6.tar.gz
bugzilla-a41f75ddfe91e2da353caa2fcf6afba7b5ee2ca6.tar.xz
Bug 545770: Make contrib/merge-users.pl figure out what columns to merge
by tracing FKs instead of having a fixed list. r=LpSolit, a=LpSolit
Diffstat (limited to 'contrib')
-rwxr-xr-xcontrib/merge-users.pl37
1 files changed, 18 insertions, 19 deletions
diff --git a/contrib/merge-users.pl b/contrib/merge-users.pl
index 6c1ed1377..ee6ec8628 100755
--- a/contrib/merge-users.pl
+++ b/contrib/merge-users.pl
@@ -121,20 +121,13 @@ if ($old_id == $new_id) {
# where fooN is the column to update, and barN1, barN2, ... are
# the columns to take into account to avoid duplicated entries.
# Note that the barNM columns are optional.
-my $changes = {
- # Tables affecting bugs.
- bugs => ['assigned_to', 'reporter', 'qa_contact'],
- bugs_activity => ['who'],
- attachments => ['submitter_id'],
- flags => ['setter_id', 'requestee_id'],
+#
+# We set the tables that require custom stuff (multiple columns to check)
+# here, but the simple stuff is all handled below by bz_get_related_fks.
+my %changes = (
cc => ['who bug_id'],
- longdescs => ['who'],
# Tables affecting global behavior / other users.
- components => ['initialowner', 'initialqacontact'],
component_cc => ['user_id component_id'],
- quips => ['userid'],
- series => ['creator'],
- whine_events => ['owner_userid'],
watch => ['watcher watched', 'watched watcher'],
# Tables affecting the user directly.
namedqueries => ['userid name'],
@@ -142,17 +135,23 @@ my $changes = {
user_group_map => ['user_id group_id isbless grant_type'],
email_setting => ['user_id relationship event'],
profile_setting => ['user_id setting_name'],
- profiles_activity => ['userid', 'who'], # Should activity be migrated?
# Only do it if mailto_type = 0, i.e is pointing to a user account!
# This requires to be done separately due to this condition.
whine_schedules => [], # ['mailto'],
+);
+
+my $userid_fks = $dbh->bz_get_related_fks('profiles', 'userid');
+foreach my $item (@$userid_fks) {
+ my ($table, $column) = @$item;
+ $changes{$table} ||= [];
+ push(@{ $changes{$table} }, $column);
+}
- # Delete all old records for these tables; no migration.
- logincookies => [], # ['userid'],
- tokens => [], # ['userid'],
- profiles => [], # ['userid'],
-};
+# Delete all old records for these tables; no migration.
+foreach my $table (qw(logincookies tokens profiles)) {
+ $changes{$table} = [];
+}
# Start the transaction
$dbh->bz_start_transaction();
@@ -162,8 +161,8 @@ $dbh->do('DELETE FROM logincookies WHERE userid = ?', undef, $old_id);
$dbh->do('DELETE FROM tokens WHERE userid = ?', undef, $old_id);
# Migrate records from old user to new user.
-foreach my $table (keys(%$changes)) {
- foreach my $column_list (@{$changes->{$table}}) {
+foreach my $table (keys %changes) {
+ foreach my $column_list (@{ $changes{$table} }) {
# Get all columns to consider. There is always at least
# one column given: the one to update.
my @columns = split(/[\s]+/, $column_list);