summaryrefslogtreecommitdiffstats
path: root/Bugzilla
diff options
context:
space:
mode:
authorStephanie Daugherty <sdaugherty@gmail.com>2011-08-29 23:29:30 +0200
committerMax Kanat-Alexander <mkanat@bugzilla.org>2011-08-29 23:29:30 +0200
commit8e5e72fccecb5ad778188d0d3a807cc5c0c0ac7c (patch)
tree0a846f335e338fcb7a38db932e3217095d9f03c9 /Bugzilla
parentdd0e1c27011f13edc0083078ebef7d061822cff7 (diff)
downloadbugzilla-8e5e72fccecb5ad778188d0d3a807cc5c0c0ac7c.tar.gz
bugzilla-8e5e72fccecb5ad778188d0d3a807cc5c0c0ac7c.tar.xz
Bug 637648 - Rename the "tags" table to "tag"
r=LpSolit, a=LpSolit
Diffstat (limited to 'Bugzilla')
-rw-r--r--Bugzilla/Bug.pm8
-rw-r--r--Bugzilla/DB.pm14
-rw-r--r--Bugzilla/DB/Schema.pm6
-rw-r--r--Bugzilla/DB/Sqlite.pm4
-rw-r--r--Bugzilla/Install/DB.pm20
-rw-r--r--Bugzilla/Search.pm4
-rw-r--r--Bugzilla/User.pm4
7 files changed, 44 insertions, 16 deletions
diff --git a/Bugzilla/Bug.pm b/Bugzilla/Bug.pm
index 73648f233..7745a9809 100644
--- a/Bugzilla/Bug.pm
+++ b/Bugzilla/Bug.pm
@@ -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));
}
diff --git a/Bugzilla/DB.pm b/Bugzilla/DB.pm
index 3c37c0dbd..ccd86d781 100644
--- a/Bugzilla/DB.pm
+++ b/Bugzilla/DB.pm
@@ -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);
diff --git a/Bugzilla/DB/Schema.pm b/Bugzilla/DB/Schema.pm
index fb62965e3..33527c367 100644
--- a/Bugzilla/DB/Schema.pm
+++ b/Bugzilla/DB/Schema.pm
@@ -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'}},
],
diff --git a/Bugzilla/DB/Sqlite.pm b/Bugzilla/DB/Sqlite.pm
index e40a264f0..fab1e3c87 100644
--- a/Bugzilla/DB/Sqlite.pm
+++ b/Bugzilla/DB/Sqlite.pm
@@ -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 #
####################################
diff --git a/Bugzilla/Install/DB.pm b/Bugzilla/Install/DB.pm
index af276882c..5ce3c7a4e 100644
--- a/Bugzilla/Install/DB.pm
+++ b/Bugzilla/Install/DB.pm
@@ -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__
diff --git a/Bugzilla/Search.pm b/Bugzilla/Search.pm
index a5c3e032d..d47e0ae99 100644
--- a/Bugzilla/Search.pm
+++ b/Bugzilla/Search.pm
@@ -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') {
diff --git a/Bugzilla/User.pm b/Bugzilla/User.pm
index 3a3edcb5b..ea186a0fd 100644
--- a/Bugzilla/User.pm
+++ b/Bugzilla/User.pm
@@ -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);
}