Commit 66146a6e authored by mkanat%bugzilla.org's avatar mkanat%bugzilla.org

Bug 429804: Add Foreign Keys to Multiselect fields

Patch By Alex Eiser <aeiser@arc.nasa.gov> r=mkanat, a=mkanat
parent a6f41ad1
......@@ -674,11 +674,17 @@ sub bz_add_field_tables {
$self->_bz_add_field_table($field->name,
$self->_bz_schema->FIELD_TABLE_SCHEMA);
if ( $field->type == FIELD_TYPE_MULTI_SELECT ) {
$self->_bz_add_field_table('bug_' . $field->name,
$self->_bz_schema->MULTI_SELECT_VALUE_TABLE);
if ($field->type == FIELD_TYPE_MULTI_SELECT) {
my $ms_table = "bug_" . $field->name;
$self->_bz_add_field_table($ms_table,
$self->_bz_schema->MULTI_SELECT_VALUE_TABLE);
$self->bz_add_fk($ms_table, 'bug_id', {TABLE => 'bugs',
COLUMN => 'bug_id',
DELETE => 'CASCADE'});
$self->bz_add_fk($ms_table, 'value', {TABLE => $field->name,
COLUMN => 'value'});
}
}
sub bz_drop_field_tables {
......
......@@ -1401,6 +1401,7 @@ use constant FIELD_TABLE_SCHEMA => {
],
};
# Foreign Keys are added in Bugzilla::DB::bz_add_field_tables
use constant MULTI_SELECT_VALUE_TABLE => {
FIELDS => [
bug_id => {TYPE => 'INT3', NOTNULL => 1},
......
......@@ -526,6 +526,9 @@ sub update_table_definitions {
$dbh->bz_alter_column('series', 'query',
{ TYPE => 'MEDIUMTEXT', NOTNULL => 1 });
# Add FK to multi select field tables
_add_foreign_keys_to_multiselects();
################################################################
# New --TABLE-- changes should go *** A B O V E *** this point #
################################################################
......@@ -2993,6 +2996,25 @@ sub _check_content_length {
}
}
sub _add_foreign_keys_to_multiselects {
my $dbh = Bugzilla->dbh;
my $names = $dbh->selectcol_arrayref(
'SELECT name
FROM fielddefs
WHERE type = ' . FIELD_TYPE_MULTI_SELECT);
foreach my $name (@$names) {
$dbh->bz_add_fk("bug_$name", "bug_id", {TABLE => 'bugs',
COLUMN => 'bug_id',
DELETE => 'CASCADE',});
$dbh->bz_add_fk("bug_$name", "value", {TABLE => $name,
COLUMN => 'value',
DELETE => 'RESTRICT',});
}
}
sub _populate_bugs_fulltext {
my $dbh = Bugzilla->dbh;
my $fulltext = $dbh->selectrow_array('SELECT 1 FROM bugs_fulltext '
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment