From 23a2f3bccb136b47a8ece9f0ec318ab6ae1ac1ac Mon Sep 17 00:00:00 2001 From: Dylan Hardison Date: Sun, 6 Sep 2020 17:03:37 -0400 Subject: [PATCH 1/6] first step in being able to upgrade from 5.0 to 6.0 --- Bugzilla/DB/Schema.pm | 6 +++--- Bugzilla/Install/DB.pm | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Bugzilla/DB/Schema.pm b/Bugzilla/DB/Schema.pm index bc14d18f4b..dd2529c0e7 100644 --- a/Bugzilla/DB/Schema.pm +++ b/Bugzilla/DB/Schema.pm @@ -694,7 +694,7 @@ use constant ABSTRACT_SCHEMA => { # "flagtypes" defines the types of flags that can be set. flagtypes => { FIELDS => [ - id => {TYPE => 'SMALLSERIAL', NOTNULL => 1, PRIMARYKEY => 1}, + id => {TYPE => 'MEDIUMSERIAL', NOTNULL => 1, PRIMARYKEY => 1}, name => {TYPE => 'varchar(50)', NOTNULL => 1}, description => {TYPE => 'MEDIUMTEXT', NOTNULL => 1}, cc_list => {TYPE => 'varchar(200)'}, @@ -721,7 +721,7 @@ use constant ABSTRACT_SCHEMA => { flaginclusions => { FIELDS => [ type_id => { - TYPE => 'INT2', + TYPE => 'INT3', NOTNULL => 1, REFERENCES => {TABLE => 'flagtypes', COLUMN => 'id', DELETE => 'CASCADE'} }, @@ -743,7 +743,7 @@ use constant ABSTRACT_SCHEMA => { flagexclusions => { FIELDS => [ type_id => { - TYPE => 'INT2', + TYPE => 'INT3', NOTNULL => 1, REFERENCES => {TABLE => 'flagtypes', COLUMN => 'id', DELETE => 'CASCADE'} }, diff --git a/Bugzilla/Install/DB.pm b/Bugzilla/Install/DB.pm index b2155d057e..34ffb94c38 100644 --- a/Bugzilla/Install/DB.pm +++ b/Bugzilla/Install/DB.pm @@ -485,7 +485,7 @@ sub update_table_definitions { # 2006-08-06 LpSolit@gmail.com - Bug 347521 $dbh->bz_alter_column('flagtypes', 'id', - {TYPE => 'SMALLSERIAL', NOTNULL => 1, PRIMARYKEY => 1}); + {TYPE => 'MEDIUMSERIAL', NOTNULL => 1, PRIMARYKEY => 1}); $dbh->bz_alter_column('keyworddefs', 'id', {TYPE => 'SMALLSERIAL', NOTNULL => 1, PRIMARYKEY => 1}); From 2a6004ff3de8dd937ec863b63e5dfdb995c97ad5 Mon Sep 17 00:00:00 2001 From: Dylan Hardison Date: Sun, 6 Sep 2020 17:40:14 -0400 Subject: [PATCH 2/6] try migrating nicknames before owners --- Bugzilla/Install/DB.pm | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/Bugzilla/Install/DB.pm b/Bugzilla/Install/DB.pm index 34ffb94c38..7e1fba0ba2 100644 --- a/Bugzilla/Install/DB.pm +++ b/Bugzilla/Install/DB.pm @@ -762,6 +762,14 @@ sub update_table_definitions { # 2019-05-08 imadueme@mozilla.com - Bug 1550145 $dbh->bz_add_column('profiles', 'forget_after_date', {TYPE => 'DATETIME'}); + $dbh->bz_add_column('profiles', 'nickname', + {TYPE => 'varchar(255)', NOTNULL => 1, DEFAULT => "''"}); + $dbh->bz_add_index('profiles', 'profiles_nickname_idx', [qw(nickname)]); + + $dbh->bz_add_index('profiles', 'profiles_realname_ft_idx', + {TYPE => 'FULLTEXT', FIELDS => ['realname']}); + _migrate_nicknames(); + _migrate_group_owners(); $dbh->bz_add_column('groups', 'idle_member_removal', @@ -772,13 +780,6 @@ sub update_table_definitions { # 2016-09-01 dkl@mozilla.com - Bug 1268317 $dbh->bz_add_column('components', 'triage_owner_id', {TYPE => 'INT3'}); - $dbh->bz_add_column('profiles', 'nickname', - {TYPE => 'varchar(255)', NOTNULL => 1, DEFAULT => "''"}); - $dbh->bz_add_index('profiles', 'profiles_nickname_idx', [qw(nickname)]); - - $dbh->bz_add_index('profiles', 'profiles_realname_ft_idx', - {TYPE => 'FULLTEXT', FIELDS => ['realname']}); - _migrate_nicknames(); # Bug 1354589 - dkl@mozilla.com _populate_oauth2_scopes(); From 6daf816b220566bc980e024c6fd969cb048720f1 Mon Sep 17 00:00:00 2001 From: Dylan Hardison Date: Sun, 6 Sep 2020 17:55:02 -0400 Subject: [PATCH 3/6] drop all the fks before changing attachment id type --- Bugzilla/Install/DB.pm | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/Bugzilla/Install/DB.pm b/Bugzilla/Install/DB.pm index 7e1fba0ba2..ff276cab85 100644 --- a/Bugzilla/Install/DB.pm +++ b/Bugzilla/Install/DB.pm @@ -762,14 +762,6 @@ sub update_table_definitions { # 2019-05-08 imadueme@mozilla.com - Bug 1550145 $dbh->bz_add_column('profiles', 'forget_after_date', {TYPE => 'DATETIME'}); - $dbh->bz_add_column('profiles', 'nickname', - {TYPE => 'varchar(255)', NOTNULL => 1, DEFAULT => "''"}); - $dbh->bz_add_index('profiles', 'profiles_nickname_idx', [qw(nickname)]); - - $dbh->bz_add_index('profiles', 'profiles_realname_ft_idx', - {TYPE => 'FULLTEXT', FIELDS => ['realname']}); - _migrate_nicknames(); - _migrate_group_owners(); $dbh->bz_add_column('groups', 'idle_member_removal', @@ -780,6 +772,13 @@ sub update_table_definitions { # 2016-09-01 dkl@mozilla.com - Bug 1268317 $dbh->bz_add_column('components', 'triage_owner_id', {TYPE => 'INT3'}); + $dbh->bz_add_column('profiles', 'nickname', + {TYPE => 'varchar(255)', NOTNULL => 1, DEFAULT => "''"}); + $dbh->bz_add_index('profiles', 'profiles_nickname_idx', [qw(nickname)]); + + $dbh->bz_add_index('profiles', 'profiles_realname_ft_idx', + {TYPE => 'FULLTEXT', FIELDS => ['realname']}); + _migrate_nicknames(); # Bug 1354589 - dkl@mozilla.com _populate_oauth2_scopes(); @@ -810,13 +809,18 @@ sub update_table_definitions { $dbh->bz_add_column('profiles', 'bounce_count', {TYPE => 'INT1', NOTNULL => 1, DEFAULT => 0}); # Bug 1588221 - dkl@mozilla.com + # TODO: skip droping fks if attach_id did not change types. + $dbh->bz_drop_fk('bugs_activity', 'attach_id'); $dbh->bz_alter_column('bugs_activity', 'attach_id', {TYPE => 'INT5'}); + $dbh->bz_drop_fk('flags', 'attach_id'); + $dbh->bz_alter_column('flags', 'attach_id', {TYPE => 'INT5'}); + $dbh->bz_drop_fk('user_request_log', 'attach_id'); + $dbh->bz_alter_column('user_request_log', 'attach_id', {TYPE => 'INT5', NOTNULL => 0}); + $dbh->bz_drop_fk('attach_data', 'id'); $dbh->bz_alter_column('attachments', 'attach_id', {TYPE => 'BIGSERIAL', NOTNULL => 1, PRIMARYKEY => 1}); $dbh->bz_alter_column('attach_data', 'id', {TYPE => 'INT5', NOTNULL => 1, PRIMARYKEY => 1}); - $dbh->bz_alter_column('flags', 'attach_id', {TYPE => 'INT5'}); - $dbh->bz_alter_column('user_request_log', 'attach_id', {TYPE => 'INT5', NOTNULL => 0}); _populate_attachment_storage_class(); @@ -4228,8 +4232,6 @@ sub _migrate_group_owners { my $dbh = Bugzilla->dbh; return if $dbh->bz_column_info('groups', 'owner_user_id'); $dbh->bz_add_column('groups', 'owner_user_id', {TYPE => 'INT3'}); - my $nobody = Bugzilla::User->check('nobody@mozilla.org'); - $dbh->do('UPDATE groups SET owner_user_id = ?', undef, $nobody->id); } sub _migrate_nicknames { From d6b05b4bef9d2743df1a474904bd36f2d141c010 Mon Sep 17 00:00:00 2001 From: Dylan Hardison Date: Sun, 6 Sep 2020 17:59:11 -0400 Subject: [PATCH 4/6] we do not need the default security group settings from bmo --- extensions/BMO/Extension.pm | 82 ------------------------------------- 1 file changed, 82 deletions(-) diff --git a/extensions/BMO/Extension.pm b/extensions/BMO/Extension.pm index c46438f99d..d343ecaf9e 100644 --- a/extensions/BMO/Extension.pm +++ b/extensions/BMO/Extension.pm @@ -1473,88 +1473,6 @@ sub install_update_db { REFERENCES => {TABLE => 'groups', COLUMN => 'id', DELETE => 'SET NULL',}, } ); - - # if there are no groups, then we're creating a database from scratch - # and there's nothing to migrate - my ($group_count) = $dbh->selectrow_array("SELECT COUNT(*) FROM groups"); - if ($group_count) { - - # Migrate old product_sec_group mappings from the time this change was made - my %product_sec_groups = ( - "addons.mozilla.org" => 'client-services-security', - "Air Mozilla" => 'mozilla-employee-confidential', - "Android Background Services" => 'cloud-services-security', - "Audio/Visual Infrastructure" => 'mozilla-employee-confidential', - "AUS" => 'client-services-security', - "Bugzilla" => 'bugzilla-security', - "bugzilla.mozilla.org" => 'bugzilla-security', - "Cloud Services" => 'cloud-services-security', - "Community Tools" => 'websites-security', - "Data & BI Services Team" => 'metrics-private', - "Developer Documentation" => 'websites-security', - "Developer Ecosystem" => 'client-services-security', - "Finance" => 'finance', - "Firefox Friends" => 'mozilla-employee-confidential', - "Firefox Health Report" => 'cloud-services-security', - "Infrastructure & Operations" => 'mozilla-employee-confidential', - "Input" => 'websites-security', - "Intellego" => 'intellego-team', - "Internet Public Policy" => 'mozilla-employee-confidential', - "L20n" => 'l20n-security', - "Legal" => 'legal', - "Marketing" => 'marketing-private', - "Mozilla Communities" => 'mozilla-communities-security', - "Mozilla Corporation" => 'mozilla-employee-confidential', - "Mozilla Developer Network" => 'websites-security', - "Mozilla Foundation" => 'mozilla-employee-confidential', - "Mozilla Foundation Operations" => 'mozilla-foundation-operations', - "Mozilla Grants" => 'grants', - "mozillaignite" => 'websites-security', - "Mozilla Messaging" => 'mozilla-messaging-confidential', - "Mozilla Metrics" => 'metrics-private', - "mozilla.org" => 'mozilla-employee-confidential', - "Mozilla PR" => 'pr-private', - "Mozilla QA" => 'mozilla-employee-confidential', - "Mozilla Reps" => 'mozilla-reps', - "Popcorn" => 'websites-security', - "Privacy" => 'privacy', - "quality.mozilla.org" => 'websites-security', - "Recruiting" => 'hr', - "Release Engineering" => 'mozilla-employee-confidential', - "Snippets" => 'websites-security', - "Socorro" => 'client-services-security', - "support.mozillamessaging.com" => 'websites-security', - "support.mozilla.org" => 'websites-security', - "Talkback" => 'talkback-private', - "Tamarin" => 'tamarin-security', - "Taskcluster" => 'taskcluster-security', - "Testopia" => 'bugzilla-security', - "Tree Management" => 'mozilla-employee-confidential', - "Web Apps" => 'client-services-security', - "Webmaker" => 'websites-security', - "Websites" => 'websites-security', - "Webtools" => 'webtools-security', - "www.mozilla.org" => 'websites-security', - ); - - # 1. Set all to core-security by default - my $core_sec_group = Bugzilla::Group->new({name => 'core-security'}); - $dbh->do("UPDATE products SET security_group_id = ?", - undef, $core_sec_group->id); - - # 2. Update the ones that have explicit security groups - foreach my $prod_name (keys %product_sec_groups) { - my $group_name = $product_sec_groups{$prod_name}; - next if $group_name eq 'core-security'; # already done - my $group = Bugzilla::Group->new({name => $group_name, cache => 1}); - if (!$group) { - warn "Security group $group_name not found. Using core-security instead.\n"; - next; - } - $dbh->do("UPDATE products SET security_group_id = ? WHERE name = ?", - undef, $group->id, $prod_name); - } - } } # Add pronouns for Firefox/Thunderbird Status/Tracking Flags such as From f0bdc2cdfdb47400f8d69b653266c82b41f900a6 Mon Sep 17 00:00:00 2001 From: Dylan Hardison Date: Sun, 6 Sep 2020 21:55:11 -0400 Subject: [PATCH 5/6] fix component id type everywhere --- Bugzilla/DB/Schema.pm | 10 +++++----- extensions/BugmailFilter/Extension.pm | 2 +- extensions/FlagTypeComment/Extension.pm | 2 +- extensions/Review/Extension.pm | 4 ++-- extensions/TrackingFlags/Extension.pm | 2 +- extensions/Webhooks/Extension.pm | 2 +- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Bugzilla/DB/Schema.pm b/Bugzilla/DB/Schema.pm index dd2529c0e7..e1c1629d61 100644 --- a/Bugzilla/DB/Schema.pm +++ b/Bugzilla/DB/Schema.pm @@ -266,7 +266,7 @@ use constant ABSTRACT_SCHEMA => { }, version => {TYPE => 'varchar(64)', NOTNULL => 1}, component_id => { - TYPE => 'INT2', + TYPE => 'INT3', NOTNULL => 1, REFERENCES => {TABLE => 'components', COLUMN => 'id'} }, @@ -730,7 +730,7 @@ use constant ABSTRACT_SCHEMA => { REFERENCES => {TABLE => 'products', COLUMN => 'id', DELETE => 'CASCADE'} }, component_id => { - TYPE => 'INT2', + TYPE => 'INT3', REFERENCES => {TABLE => 'components', COLUMN => 'id', DELETE => 'CASCADE'} }, ], @@ -752,7 +752,7 @@ use constant ABSTRACT_SCHEMA => { REFERENCES => {TABLE => 'products', COLUMN => 'id', DELETE => 'CASCADE'} }, component_id => { - TYPE => 'INT2', + TYPE => 'INT3', REFERENCES => {TABLE => 'components', COLUMN => 'id', DELETE => 'CASCADE'} }, ], @@ -1162,7 +1162,7 @@ use constant ABSTRACT_SCHEMA => { REFERENCES => {TABLE => 'profiles', COLUMN => 'userid', DELETE => 'CASCADE'} }, component_id => { - TYPE => 'INT2', + TYPE => 'INT3', NOTNULL => 1, REFERENCES => {TABLE => 'components', COLUMN => 'id', DELETE => 'CASCADE'} }, @@ -1447,7 +1447,7 @@ use constant ABSTRACT_SCHEMA => { components => { FIELDS => [ - id => {TYPE => 'SMALLSERIAL', NOTNULL => 1, PRIMARYKEY => 1}, + id => {TYPE => 'MEDIUMSERIAL', NOTNULL => 1, PRIMARYKEY => 1}, name => {TYPE => 'varchar(64)', NOTNULL => 1}, product_id => { TYPE => 'INT2', diff --git a/extensions/BugmailFilter/Extension.pm b/extensions/BugmailFilter/Extension.pm index a05953336a..b0f7b1c981 100644 --- a/extensions/BugmailFilter/Extension.pm +++ b/extensions/BugmailFilter/Extension.pm @@ -441,7 +441,7 @@ sub db_schema_abstract_schema { REFERENCES => {TABLE => 'products', COLUMN => 'id', DELETE => 'CASCADE'}, }, component_id => { - TYPE => 'INT2', + TYPE => 'INT3', NOTNULL => 0, REFERENCES => {TABLE => 'components', COLUMN => 'id', DELETE => 'CASCADE'}, }, diff --git a/extensions/FlagTypeComment/Extension.pm b/extensions/FlagTypeComment/Extension.pm index e5892fcbe9..c065001af1 100644 --- a/extensions/FlagTypeComment/Extension.pm +++ b/extensions/FlagTypeComment/Extension.pm @@ -42,7 +42,7 @@ sub db_schema_abstract_schema { $args->{'schema'}->{'flagtype_comments'} = { FIELDS => [ type_id => { - TYPE => 'SMALLINT(6)', + TYPE => 'INT3', NOTNULL => 1, REFERENCES => {TABLE => 'flagtypes', COLUMN => 'id', DELETE => 'CASCADE'} }, diff --git a/extensions/Review/Extension.pm b/extensions/Review/Extension.pm index fa4900ff2a..a338b76c84 100644 --- a/extensions/Review/Extension.pm +++ b/extensions/Review/Extension.pm @@ -837,7 +837,7 @@ sub db_schema_abstract_schema { }, display_name => {TYPE => 'VARCHAR(64)',}, component_id => { - TYPE => 'INT2', + TYPE => 'INT3', NOTNULL => 1, REFERENCES => {TABLE => 'components', COLUMN => 'id', DELETE => 'CASCADE',} }, @@ -856,7 +856,7 @@ sub db_schema_abstract_schema { flag_when => {TYPE => 'DATETIME', NOTNULL => 1,}, type_id => { - TYPE => 'INT2', + TYPE => 'INT3', NOTNULL => 1, REFERENCES => {TABLE => 'flagtypes', COLUMN => 'id', DELETE => 'CASCADE'} }, diff --git a/extensions/TrackingFlags/Extension.pm b/extensions/TrackingFlags/Extension.pm index 297f986fd4..19f0d37afe 100644 --- a/extensions/TrackingFlags/Extension.pm +++ b/extensions/TrackingFlags/Extension.pm @@ -261,7 +261,7 @@ sub db_schema_abstract_schema { REFERENCES => {TABLE => 'products', COLUMN => 'id', DELETE => 'CASCADE',}, }, component_id => { - TYPE => 'INT2', + TYPE => 'INT3', NOTNULL => 0, REFERENCES => {TABLE => 'components', COLUMN => 'id', DELETE => 'CASCADE',}, }, diff --git a/extensions/Webhooks/Extension.pm b/extensions/Webhooks/Extension.pm index 1a02ea9bfe..151a3f0a93 100644 --- a/extensions/Webhooks/Extension.pm +++ b/extensions/Webhooks/Extension.pm @@ -48,7 +48,7 @@ sub db_schema_abstract_schema { REFERENCES => {TABLE => 'products', COLUMN => 'id', DELETE => 'CASCADE',} }, component_id => { - TYPE => 'INT2', + TYPE => 'INT3', NOTNULL => 0, REFERENCES => {TABLE => 'components', COLUMN => 'id', DELETE => 'CASCADE',} } From 04d3db0ce2a75dc03dcbbc5e018f4f4d15359ecf Mon Sep 17 00:00:00 2001 From: Vladimir Panteleev Date: Wed, 14 Oct 2020 16:37:31 +0000 Subject: [PATCH 6/6] Further 5.0->6.0 schema upgrade fixes (#70) --- Bugzilla/DB/Schema.pm | 2 +- Bugzilla/Install/DB.pm | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Bugzilla/DB/Schema.pm b/Bugzilla/DB/Schema.pm index e1c1629d61..4268796c42 100644 --- a/Bugzilla/DB/Schema.pm +++ b/Bugzilla/DB/Schema.pm @@ -658,7 +658,7 @@ use constant ABSTRACT_SCHEMA => { FIELDS => [ id => {TYPE => 'MEDIUMSERIAL', NOTNULL => 1, PRIMARYKEY => 1}, type_id => { - TYPE => 'INT2', + TYPE => 'INT3', NOTNULL => 1, REFERENCES => {TABLE => 'flagtypes', COLUMN => 'id', DELETE => 'CASCADE'} }, diff --git a/Bugzilla/Install/DB.pm b/Bugzilla/Install/DB.pm index ff276cab85..32be6b9194 100644 --- a/Bugzilla/Install/DB.pm +++ b/Bugzilla/Install/DB.pm @@ -484,8 +484,15 @@ sub update_table_definitions { $dbh->bz_drop_column('groups', 'last_changed'); # 2006-08-06 LpSolit@gmail.com - Bug 347521 + $dbh->bz_drop_related_fks('flagtypes', 'id'); $dbh->bz_alter_column('flagtypes', 'id', {TYPE => 'MEDIUMSERIAL', NOTNULL => 1, PRIMARYKEY => 1}); + $dbh->bz_alter_column('flags', 'type_id', + {TYPE => 'INT3', NOTNULL => 1}); + $dbh->bz_alter_column('flaginclusions', 'type_id', + {TYPE => 'INT3', NOTNULL => 1}); + $dbh->bz_alter_column('flagexclusions', 'type_id', + {TYPE => 'INT3', NOTNULL => 1}); $dbh->bz_alter_column('keyworddefs', 'id', {TYPE => 'SMALLSERIAL', NOTNULL => 1, PRIMARYKEY => 1});