Skip to content
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

support upgrading from 5.0 schemas #52

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions Bugzilla/DB/Schema.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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'}
},
Expand Down Expand Up @@ -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'}
},
Expand Down Expand Up @@ -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)'},
Expand All @@ -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'}
},
Expand All @@ -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'}
},
],
Expand All @@ -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'}
},
Expand All @@ -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'}
},
],
Expand Down Expand Up @@ -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'}
},
Expand Down Expand Up @@ -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',
Expand Down
20 changes: 15 additions & 5 deletions Bugzilla/Install/DB.pm
Original file line number Diff line number Diff line change
Expand Up @@ -484,8 +484,15 @@ sub update_table_definitions {
$dbh->bz_drop_column('groups', 'last_changed');

# 2006-08-06 [email protected] - Bug 347521
$dbh->bz_drop_related_fks('flagtypes', 'id');
$dbh->bz_alter_column('flagtypes', 'id',
{TYPE => 'SMALLSERIAL', NOTNULL => 1, PRIMARYKEY => 1});
{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});
Expand Down Expand Up @@ -809,13 +816,18 @@ sub update_table_definitions {
$dbh->bz_add_column('profiles', 'bounce_count', {TYPE => 'INT1', NOTNULL => 1, DEFAULT => 0});

# Bug 1588221 - [email protected]
# 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();


Expand Down Expand Up @@ -4227,8 +4239,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('[email protected]');
$dbh->do('UPDATE groups SET owner_user_id = ?', undef, $nobody->id);
}

sub _migrate_nicknames {
Expand Down
82 changes: 0 additions & 82 deletions extensions/BMO/Extension.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion extensions/BugmailFilter/Extension.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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'},
},
Expand Down
2 changes: 1 addition & 1 deletion extensions/FlagTypeComment/Extension.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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'}
},
Expand Down
4 changes: 2 additions & 2 deletions extensions/Review/Extension.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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',}
},
Expand All @@ -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'}
},
Expand Down
2 changes: 1 addition & 1 deletion extensions/TrackingFlags/Extension.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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',},
},
Expand Down
2 changes: 1 addition & 1 deletion extensions/Webhooks/Extension.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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',}
}
Expand Down