Commit 8e5e72fc authored by Stephanie Daugherty's avatar Stephanie Daugherty Committed by Max Kanat-Alexander

Bug 637648 - Rename the "tags" table to "tag"

r=LpSolit, a=LpSolit
parent dd0e1c27
......@@ -2958,10 +2958,10 @@ sub add_tag {
my $tag_id = $user->tags->{$tag}->{id};
# If this tag doesn't exist for this user yet, create it.
if (!$tag_id) {
$dbh->do('INSERT INTO tags (user_id, name) VALUES (?, ?)',
$dbh->do('INSERT INTO tag (user_id, name) VALUES (?, ?)',
undef, ($user->id, $tag));
$tag_id = $dbh->selectrow_array('SELECT id FROM tags
$tag_id = $dbh->selectrow_array('SELECT id FROM tag
WHERE name = ? AND user_id = ?',
undef, ($tag, $user->id));
# The list has changed.
......@@ -2997,7 +2997,7 @@ sub remove_tag {
# Decrement the counter, and delete the tag if no bugs are using it anymore.
if (!--$user->tags->{$tag}->{bug_count}) {
$dbh->do('DELETE FROM tags WHERE name = ? AND user_id = ?',
$dbh->do('DELETE FROM tag WHERE name = ? AND user_id = ?',
undef, ($tag, $user->id));
# The list has changed.
......@@ -3014,7 +3014,7 @@ sub tags {
if (!exists $self->{tags}) {
$self->{tags} = $dbh->selectcol_arrayref(
'SELECT name FROM bug_tag
INNER JOIN tags ON tags.id = bug_tag.tag_id
INNER JOIN tag ON tag.id = bug_tag.tag_id
WHERE bug_id = ? AND user_id = ?',
undef, ($self->id, $user->id));
}
......
......@@ -93,6 +93,12 @@ use constant FULLTEXT_OR => '';
use constant WORD_START => '(^|[^[:alnum:]])';
use constant WORD_END => '($|[^[:alnum:]])';
# On most databases, in order to drop an index, you have to first drop
# the foreign keys that use that index. However, on some databases,
# dropping the FK immediately before dropping the index causes problems
# and doesn't need to be done anyway, so those DBs set this to 0.
use constant INDEX_DROPS_REQUIRE_FK_DROPS => 1;
#####################################################################
# Overridden Superclass Methods
#####################################################################
......@@ -947,9 +953,11 @@ sub bz_drop_index {
my $index_exists = $self->bz_index_info($table, $name);
if ($index_exists) {
# We cannot delete an index used by a FK.
foreach my $column (@{$index_exists->{FIELDS}}) {
$self->bz_drop_related_fks($table, $column);
if ($self->INDEX_DROPS_REQUIRE_FK_DROPS) {
# We cannot delete an index used by a FK.
foreach my $column (@{$index_exists->{FIELDS}}) {
$self->bz_drop_related_fks($table, $column);
}
}
$self->bz_drop_index_raw($table, $name);
$self->_bz_real_schema->delete_index($table, $name);
......
......@@ -1000,7 +1000,7 @@ use constant ABSTRACT_SCHEMA => {
],
},
tags => {
tag => {
FIELDS => [
id => {TYPE => 'MEDIUMSERIAL', NOTNULL => 1, PRIMARYKEY => 1},
name => {TYPE => 'varchar(64)', NOTNULL => 1},
......@@ -1010,7 +1010,7 @@ use constant ABSTRACT_SCHEMA => {
DELETE => 'CASCADE'}},
],
INDEXES => [
tags_user_id_idx => {FIELDS => [qw(user_id name)], TYPE => 'UNIQUE'},
tag_user_id_idx => {FIELDS => [qw(user_id name)], TYPE => 'UNIQUE'},
],
},
......@@ -1021,7 +1021,7 @@ use constant ABSTRACT_SCHEMA => {
COLUMN => 'bug_id',
DELETE => 'CASCADE'}},
tag_id => {TYPE => 'INT3', NOTNULL => 1,
REFERENCES => {TABLE => 'tags',
REFERENCES => {TABLE => 'tag',
COLUMN => 'id',
DELETE => 'CASCADE'}},
],
......
......@@ -39,6 +39,10 @@ use constant ISOLATION_LEVEL => undef;
use constant WORD_START => '(?:^|\W)';
use constant WORD_END => '(?:$|\W)';
# For some reason, dropping the related FKs causes the index to
# disappear early, which causes all sorts of problems.
use constant INDEX_DROPS_REQUIRE_FK_DROPS => 0;
####################################
# Functions Added To SQLite Itself #
####################################
......
......@@ -646,6 +646,8 @@ sub update_table_definitions {
$dbh->bz_add_column('bug_see_also', 'id',
{TYPE => 'MEDIUMSERIAL', NOTNULL => 1, PRIMARYKEY => 1});
_rename_tags_to_tag();
# 2011-01-29 LpSolit@gmail.com - Bug 616185
_migrate_user_tags();
......@@ -3485,9 +3487,9 @@ sub _migrate_user_tags {
WHERE query_type != 0');
my $sth_tags = $dbh->prepare(
'INSERT INTO tags (user_id, name) VALUES (?, ?)');
'INSERT INTO tag (user_id, name) VALUES (?, ?)');
my $sth_tag_id = $dbh->prepare(
'SELECT id FROM tags WHERE user_id = ? AND name = ?');
'SELECT id FROM tag WHERE user_id = ? AND name = ?');
my $sth_bug_tag = $dbh->prepare('INSERT INTO bug_tag (bug_id, tag_id)
VALUES (?, ?)');
my $sth_nq = $dbh->prepare('UPDATE namedqueries SET query = ?
......@@ -3586,6 +3588,20 @@ sub _migrate_disabledtext_boolean {
}
}
sub _rename_tags_to_tag {
my $dbh = Bugzilla->dbh;
if ($dbh->bz_table_info('tags')) {
# If we get here, it's because the schema created "tag" as an empty
# table while "tags" still exists. We get rid of the empty
# tag table so we can do the rename over the top of it.
$dbh->bz_drop_table('tag');
$dbh->bz_drop_index('tags', 'tags_user_id_idx');
$dbh->bz_rename_table('tags','tag');
$dbh->bz_add_index('tag', 'tag_user_id_idx',
{FIELDS => [qw(user_id name)], TYPE => 'UNIQUE'});
}
}
1;
__END__
......
......@@ -2525,8 +2525,8 @@ sub _multiselect_table {
" ON keywords.keywordid = keyworddefs.id";
}
elsif ($field eq 'tag') {
$args->{full_field} = 'tags.name';
return "bug_tag INNER JOIN tags ON bug_tag.tag_id = tags.id"
$args->{full_field} = 'tag.name';
return "bug_tag INNER JOIN tag ON bug_tag.tag_id = tag.id"
. " AND user_id = " . $self->_user->id;
}
elsif ($field eq 'bug_group') {
......
......@@ -423,8 +423,8 @@ sub tags {
# in which case there are no bugs with this tag yet.
$self->{tags} = $dbh->selectall_hashref(
'SELECT name, id, COUNT(bug_id) AS bug_count
FROM tags
LEFT JOIN bug_tag ON bug_tag.tag_id = tags.id
FROM tag
LEFT JOIN bug_tag ON bug_tag.tag_id = tag.id
WHERE user_id = ? ' . $dbh->sql_group_by('id', 'name'),
'name', undef, $self->id);
}
......
......@@ -133,7 +133,7 @@
"settings" => "Settings",
"short_desc" => "Summary",
"status_whiteboard" => "Whiteboard",
"tags.name" => "Tags",
"tag.name" => "Tags",
"target_milestone" => "Target Milestone",
"version" => "Version",
"work_time" => "Hours Worked",
......
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