From c48fd6c4d71411630ccdea80ea848fe53edd37cb Mon Sep 17 00:00:00 2001 From: "mkanat%kerio.com" <> Date: Fri, 15 Apr 2005 05:20:53 +0000 Subject: Bug 290089: Move timestamp updates to happen before any other Schema updates Patch By Max Kanat-Alexander r=Tomas.Kopal, a=justdave --- Bugzilla/DB/Mysql.pm | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) (limited to 'Bugzilla/DB') diff --git a/Bugzilla/DB/Mysql.pm b/Bugzilla/DB/Mysql.pm index 1d10838e9..d80b1bbbb 100644 --- a/Bugzilla/DB/Mysql.pm +++ b/Bugzilla/DB/Mysql.pm @@ -371,6 +371,79 @@ sub bz_setup_database { } # foreach table } # if old-name indexes + # The old timestamp fields need to be adjusted here instead of in + # checksetup. Otherwise the UPDATE statements inside of bz_add_column + # will cause accidental timestamp updates. + # The code that does this was moved here from checksetup. + + # 2002-08-14 - bbaetz@student.usyd.edu.au - bug 153578 + # attachments creation time needs to be a datetime, not a timestamp + my $attach_creation = + $self->bz_get_field_def("attachments", "creation_ts"); + if ($attach_creation && $attach_creation->[1] =~ /^timestamp/) { + print "Fixing creation time on attachments...\n"; + + my $sth = $self->prepare("SELECT COUNT(attach_id) FROM attachments"); + $sth->execute(); + my ($attach_count) = $sth->fetchrow_array(); + + if ($attach_count > 1000) { + print "This may take a while...\n"; + } + my $i = 0; + + # This isn't just as simple as changing the field type, because + # the creation_ts was previously updated when an attachment was made + # obsolete from the attachment creation screen. So we have to go + # and recreate these times from the comments.. + $sth = $self->prepare("SELECT bug_id, attach_id, submitter_id " . + "FROM attachments"); + $sth->execute(); + + # Restrict this as much as possible in order to avoid false + # positives, and keep the db search time down + my $sth2 = $self->prepare("SELECT bug_when FROM longdescs + WHERE bug_id=? AND who=? + AND thetext LIKE ? + ORDER BY bug_when " . $self->sql_limit(1)); + while (my ($bug_id, $attach_id, $submitter_id) + = $sth->fetchrow_array()) + { + $sth2->execute($bug_id, $submitter_id, + "Created an attachment (id=$attach_id)%"); + my ($when) = $sth2->fetchrow_array(); + if ($when) { + $self->do("UPDATE attachments " . + "SET creation_ts='$when' " . + "WHERE attach_id=$attach_id"); + } else { + print "Warning - could not determine correct creation" + . " time for attachment $attach_id on bug $bug_id\n"; + } + ++$i; + print "Converted $i of $attach_count attachments\n" if !($i % 1000); + } + print "Done - converted $i attachments\n"; + + $self->bz_change_field_type("attachments", "creation_ts", + 'datetime NOT NULL'); + } + + # 2004-08-29 - Tomas.Kopal@altap.cz, bug 257303 + # Change logincookies.lastused type from timestamp to datetime + my $login_lastused = $self->bz_get_field_def("logincookies", "lastused"); + if ($login_lastused && $login_lastused->[1] =~ /^timestamp/) { + $self->bz_change_field_type('logincookies', 'lastused', + 'DATETIME NOT NULL'); + } + + # 2005-01-17 - Tomas.Kopal@altap.cz, bug 257315 + # Change bugs.delta_ts type from timestamp to datetime + my $bugs_deltats = $self->bz_get_field_def("bugs", "delta_ts"); + if ($bugs_deltats && $bugs_deltats->[1] =~ /^timestamp/) { + $self->bz_change_field_type('bugs', 'delta_ts', 'DATETIME NOT NULL'); + } + $self->SUPER::bz_setup_database(); } -- cgit v1.2.3-24-g4f1b