]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 637648 - Rename the "tags" table to "tag"
authorStephanie Daugherty <sdaugherty@gmail.com>
Mon, 29 Aug 2011 21:30:15 +0000 (14:30 -0700)
committerMax Kanat-Alexander <mkanat@bugzilla.org>
Mon, 29 Aug 2011 21:30:15 +0000 (14:30 -0700)
r=LpSolit, a=LpSolit

Bugzilla/Bug.pm
Bugzilla/DB.pm
Bugzilla/DB/Schema.pm
Bugzilla/DB/Sqlite.pm
Bugzilla/Install/DB.pm
Bugzilla/Search.pm
Bugzilla/User.pm
template/en/default/global/field-descs.none.tmpl

index 6fdab364554ad2b781323280459ee1ed773911da..8beecdcd2d5a12411aa412362b2fd5b1970072b7 100644 (file)
@@ -2918,10 +2918,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.
@@ -2957,7 +2957,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.
@@ -2974,7 +2974,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));
     }
index 8d1cf32a0b01ac39a1dce24a3ad94c346e32b4d7..a537d61312fbdbcaf19ac3765d046b0ed3c35a8c 100644 (file)
@@ -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);
index fb62965e3da0a911d7c390e71bd7a3a49adaaf81..33527c367b9420674f9551053281338a4abfc4cf 100644 (file)
@@ -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'}},
         ],
index e40a264f0a2566c9a1d3f412d3af2c15c48059e2..fab1e3c87a08d82012c36f625da8ddceb828bc5c 100644 (file)
@@ -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 #
 ####################################
index af276882c279cf6e714620ace9f785b59905c352..5ce3c7a4ecc4dd525ba343dd02d95d37f264b70e 100644 (file)
@@ -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__
index a5c3e032da2d292c308a7732af400ae5cdd2e372..d47e0ae99d5e3c0183f1fa603c85d348291363da 100644 (file)
@@ -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') {
index 3a3edcb5ba063ae67062fe33f41ef79ce42a623b..ea186a0fdca7f99fe649471b22bfca88b894f209 100644 (file)
@@ -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);
     }
index 130ad82c6ef10a9b89f7f93fc60121513b0cfa3b..21f41c86c3bc750fa10b17f771182d2a6c58a183 100644 (file)
      "settings"                => "Settings",
      "short_desc"              => "Summary",
      "status_whiteboard"       => "Whiteboard",
-     "tags.name"               => "Tags",
+     "tag.name"                => "Tags",
      "target_milestone"        => "Target Milestone",
      "version"                 => "Version",
      "work_time"               => "Hours Worked",