Repository navigation
Bug 2085398 - Make flag_activity.who NOT NULL, add a starting flag_activity row for older flags and store the cutoff #2830
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
241c2ec
5c5f944
693fdef
f8e4e92
b27aea0
29c7e1d
1ea2e80
a7f1517
55a159b
b0f4c33
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -852,9 +852,21 @@ sub update_table_definitions { | |
| # Before _migrate_flag_state_activity, which copies into this column. | ||
| _add_flag_activity_who(); | ||
|
|
||
| # Bug 2085398 - xavier.lhour@gmail.com | ||
| # After _add_flag_activity_who, which fills the rows without it. | ||
| _set_flag_activity_who_not_null(); | ||
|
|
||
| # Bug 2085398 - xavier.lhour@gmail.com | ||
| _set_flag_activity_requestee_fk_set_null(); | ||
|
|
||
| # Bug 1806896 - xavier.lhour@gmail.com | ||
| _migrate_flag_state_activity(); | ||
|
|
||
| # Bug 2085398 - xavier.lhour@gmail.com | ||
| # After _migrate_flag_state_activity, so that flags with copied rows are | ||
| # skipped. | ||
| _add_flag_activity_start_rows(); | ||
|
|
||
| # Bug 2060356 - dkl@mozilla.com | ||
| _remove_duo_recovery_codes(); | ||
|
|
||
|
|
@@ -4579,8 +4591,47 @@ sub _migrate_flag_state_activity { | |
| $dbh->bz_drop_table('flag_state_activity'); | ||
| } | ||
|
|
||
| # Nullable for now: during the rolling deploy, pods still on the previous code | ||
| # insert rows without it. Bug 2085398 makes it NOT NULL once all pods write it. | ||
| # Until 2026-07-29, flag_activity only logged review, feedback and needinfo | ||
| # flags. Other flags last changed before then have no row there, so their next | ||
| # change would show no previous value in history and bugmail. Give each of them | ||
| # a row with its current state, dated at its last change: history and bugmail | ||
| # don't show it, as it is older than the cutoff. | ||
| sub _add_flag_activity_start_rows { | ||
| my $dbh = Bugzilla->dbh; | ||
|
|
||
| # The cutoff is set at the end, so this runs once, or again if it died. | ||
| return if $dbh->selectrow_array('SELECT 1 FROM flag_activity_migration'); | ||
|
|
||
| my ($max_id) = $dbh->selectrow_array('SELECT MAX(id) FROM flags'); | ||
| $max_id //= 0; | ||
|
|
||
| my $batch_size = 10_000; | ||
| my $added = 0; | ||
| for (my $from = 0; $from < $max_id; $from += $batch_size) { | ||
| $added += $dbh->do( | ||
| 'INSERT INTO flag_activity | ||
| (flag_when, type_id, flag_id, setter_id, who, requestee_id, bug_id, | ||
| attachment_id, status) | ||
| SELECT COALESCE(modification_date, creation_date), type_id, id, | ||
| setter_id, setter_id, requestee_id, bug_id, attach_id, status | ||
| FROM flags | ||
| WHERE id > ? AND id <= ? | ||
| AND NOT EXISTS (SELECT 1 FROM flag_activity | ||
| WHERE flag_activity.flag_id = flags.id)', undef, | ||
| $from, $from + $batch_size | ||
| ); | ||
| } | ||
| print "Added a flag_activity row for $added flags.\n" if $added > 0; | ||
|
|
||
| # Flag changes up to this time are to be read from bugs_activity, later ones | ||
| # from flag_activity. | ||
| $dbh->do( | ||
| 'INSERT INTO flag_activity_migration (cutoff) VALUES (LOCALTIMESTAMP(0))'); | ||
|
dklawren marked this conversation as resolved.
Resolved
|
||
| } | ||
|
|
||
| # Added nullable: during the rolling deploy, pods still on the previous code | ||
| # inserted rows without it. _set_flag_activity_who_not_null makes it NOT NULL | ||
| # once all pods write it. | ||
| sub _add_flag_activity_who { | ||
| my $dbh = Bugzilla->dbh; | ||
|
|
||
|
|
@@ -4597,6 +4648,60 @@ sub _add_flag_activity_who { | |
| $dbh->do('UPDATE flag_activity SET who = setter_id WHERE who IS NULL'); | ||
| } | ||
|
|
||
| # Every pod writes who since bug 2088705 was deployed. | ||
| sub _set_flag_activity_who_not_null { | ||
| my $dbh = Bugzilla->dbh; | ||
| return if $dbh->bz_column_info('flag_activity', 'who')->{NOTNULL}; | ||
|
|
||
| my $mysql = $dbh->isa('Bugzilla::DB::Mysql'); | ||
|
|
||
| # MySQL can't make a column of a foreign key NOT NULL. Drop the key and add | ||
| # it back right after. | ||
| $dbh->bz_drop_fk('flag_activity', 'who'); | ||
|
dklawren marked this conversation as resolved.
Resolved
|
||
|
|
||
| # Without strict mode, which Bugzilla::DB::Mysql turns off, MySQL copies the | ||
| # whole table to make the column NOT NULL, blocking flag changes on live pods | ||
| # meanwhile. _add_flag_activity_who just filled every who, so strict mode has | ||
| # nothing to refuse. | ||
| my $sql_mode = $mysql && $dbh->selectrow_array('SELECT @@SESSION.sql_mode'); | ||
| $dbh->do('SET SESSION sql_mode = ?', | ||
| undef, join(',', grep {length} $sql_mode, 'STRICT_TRANS_TABLES')) | ||
| if $mysql; | ||
| $dbh->bz_alter_column( | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. making maybe turn strict mode on for this one alter (
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch, thanks! :) Strict mode ( Checked on MySQL 8.0.42 by forcing Fixed in b0f4c33 |
||
| 'flag_activity', | ||
| 'who', | ||
| { | ||
| TYPE => 'INT3', | ||
| NOTNULL => 1, | ||
| REFERENCES => {TABLE => 'profiles', COLUMN => 'userid'} | ||
| } | ||
| ); | ||
| $dbh->do('SET SESSION sql_mode = ?', undef, $sql_mode) if $mysql; | ||
|
|
||
| # Likewise with foreign_key_checks on to add the key. The values don't need | ||
| # the check: they were written under this key or copied from setter_id, which | ||
| # has its own. | ||
| $dbh->do('SET foreign_key_checks = 0') if $mysql; | ||
| $dbh->bz_add_fk('flag_activity', 'who', | ||
| $dbh->bz_fk_info('flag_activity', 'who')); | ||
| $dbh->do('SET foreign_key_checks = 1') if $mysql; | ||
| } | ||
|
|
||
| # The start rows name the requestees of older pending requests. Without this, | ||
| # their accounts couldn't be deleted any more. | ||
| sub _set_flag_activity_requestee_fk_set_null { | ||
| my $dbh = Bugzilla->dbh; | ||
| my $fk = $dbh->bz_fk_info('flag_activity', 'requestee_id'); | ||
| return if !$fk || defined $fk->{DELETE}; | ||
| $fk->{DELETE} = 'SET NULL'; | ||
|
|
||
| # As for who above: the values were written under this key already. | ||
| my $mysql = $dbh->isa('Bugzilla::DB::Mysql'); | ||
| $dbh->do('SET foreign_key_checks = 0') if $mysql; | ||
| $dbh->bz_alter_fk('flag_activity', 'requestee_id', $fk); | ||
| $dbh->do('SET foreign_key_checks = 1') if $mysql; | ||
| } | ||
|
|
||
| sub _remove_duo_recovery_codes { | ||
| my $dbh = Bugzilla->dbh; | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| # This Source Code Form is subject to the terms of the Mozilla Public | ||
| # License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| # file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
| # | ||
| # This Source Code Form is "Incompatible With Secondary Licenses", as | ||
| # defined by the Mozilla Public License, v. 2.0. | ||
|
|
||
| use strict; | ||
| use warnings; | ||
| use lib qw(lib ../../lib ../../local/lib/perl5); | ||
|
|
||
| use Bugzilla; | ||
|
|
||
| use Test::More "no_plan"; | ||
|
|
||
| use QA::Util; | ||
|
|
||
| my ($sel, $config) = get_selenium(); | ||
| my $dbh = Bugzilla->dbh; | ||
| my ($user_id, $flag_id); | ||
|
|
||
| # Runs even if a check below dies, so that a rerun finds a clean database. | ||
| END { | ||
| if ($flag_id) { | ||
| $dbh->do('DELETE FROM flag_activity WHERE flag_id = ?', undef, $flag_id); | ||
| $dbh->do('DELETE FROM flags WHERE id = ?', undef, $flag_id); | ||
| } | ||
| $dbh->do('DELETE FROM profiles WHERE userid = ?', undef, $user_id) if $user_id; | ||
| eval { | ||
| set_parameters($sel, | ||
| {"Administrative Policies" => {"allowuserdeletion-off" => undef}}); | ||
| logout($sel); | ||
| }; | ||
| } | ||
|
|
||
| log_in($sel, $config, 'admin'); | ||
| set_parameters($sel, | ||
| {"Administrative Policies" => {"allowuserdeletion-on" => undef}}); | ||
|
|
||
| # A user asked to set a flag, and named as requestee in the flag history, can | ||
| # be deleted: the request is cleared and the history keeps the row without | ||
| # the requestee. | ||
| my $login = 'requestee@selenium.bugzilla.org'; | ||
| $dbh->do( | ||
| "INSERT INTO profiles (login_name, realname, cryptpassword) | ||
| VALUES (?, 'Requestee', '*')", undef, $login | ||
| ); | ||
| $user_id = $dbh->bz_last_key('profiles', 'userid'); | ||
| my ($admin_id) | ||
| = $dbh->selectrow_array('SELECT userid FROM profiles WHERE login_name = ?', | ||
| undef, $config->{admin_user_login}); | ||
| my ($bug_id) = $dbh->selectrow_array('SELECT MIN(bug_id) FROM bugs'); | ||
| my ($type_id) | ||
| = $dbh->selectrow_array( | ||
| "SELECT MIN(id) FROM flagtypes WHERE target_type = 'b'"); | ||
| $dbh->do( | ||
| "INSERT INTO flags (type_id, status, bug_id, creation_date, | ||
| modification_date, setter_id, requestee_id) | ||
| VALUES (?, '?', ?, NOW(), NOW(), ?, ?)", undef, $type_id, $bug_id, $admin_id, | ||
| $user_id | ||
| ); | ||
| $flag_id = $dbh->bz_last_key('flags', 'id'); | ||
| $dbh->do( | ||
| "INSERT INTO flag_activity | ||
| (flag_when, type_id, flag_id, setter_id, who, requestee_id, bug_id, status) | ||
| VALUES (NOW(), ?, ?, ?, ?, ?, ?, '?')", undef, $type_id, $flag_id, $admin_id, | ||
| $admin_id, $user_id, $bug_id | ||
| ); | ||
| my $history_id = $dbh->bz_last_key('flag_activity', 'id'); | ||
|
|
||
| $sel->open_ok("/editusers.cgi?action=del&userid=$user_id"); | ||
| $sel->title_is("Confirm deletion of user $login"); | ||
| ok(!$sel->is_text_present('You cannot delete this user account'), | ||
| 'The requestee can be deleted'); | ||
| $sel->click_ok("delete"); | ||
| $sel->wait_for_page_to_load_ok(WAIT_TIME); | ||
| $sel->title_is("User $login deleted"); | ||
|
|
||
| is( | ||
| scalar $dbh->selectrow_array( | ||
| 'SELECT COUNT(*) FROM flag_activity WHERE id = ? AND requestee_id IS NULL', | ||
| undef, $history_id | ||
| ), | ||
| 1, | ||
| 'The flag history keeps the row without the requestee' | ||
| ); | ||
| is( | ||
| scalar $dbh->selectrow_array( | ||
| 'SELECT COUNT(*) FROM flags WHERE id = ? AND requestee_id IS NULL', | ||
| undef, $flag_id | ||
| ), | ||
| 1, | ||
| 'The request is cleared' | ||
| ); |
Uh oh!
There was an error while loading. Please reload this page.