Any thoughts on this? I think it would be cool to change the names of the taxonomy-specific database tables so they all begin with taxonomy, for example taxonomy_vocabulary, taxonomy_term_hierarchy.

After a while we get to know our way around the quirks of the Drupal database structure, but changes like this would be nice for developers new to the project.

Is it possible to change database table names during an upgrade or are we better off stuck with them as legacy choices?

CommentFileSizeAuthor
#5 225562.patch54.97 KBjody lynn
#2 taxonomy_rename.patch1.04 KBjody lynn

Comments

catch’s picture

Category: feature » bug

This is a bug. I'll roll the patch if no-one else does.

jody lynn’s picture

Category: bug » feature
Status: Active » Needs work
StatusFileSize
new1.04 KB

There are many places where the table names will have to be changed in core (and it will be a little more manual than just a find and replace), so let's agree on the new table names first of all.

I propose:
term_data -> taxonomy_term
term_hierarchy -> taxonomy_hierarchy
term_node -> taxonomy_node
term_relation -> taxonomy_relation
term_synonym -> taxonomy_synonym
vocabulary -> taxonomy_vocabulary
vocabulary_node_types -> taxonomy_vocabulary_types

The attached patch is an update function only just as a start.

catch’s picture

Category: feature » task

I'd almost be tempted to go the whole hog and make it taxonomy_term_data taxonomy_term_hierarchy etc., but those are annoyingly long table names...

Crell’s picture

Component: database system » taxonomy.module

Refiling this over to the taxonomy component as this really has nothing to do with the database API itself. I approve of nicer table names, however. :-)

jody lynn’s picture

Status: Needs work » Needs review
StatusFileSize
new54.97 KB

New patch prepends all taxonomy tables with taxonomy_ as per comment 3.

This patch replaces all instances of the table names and has an update function.

There already was an update in taxonomy.install for D7 to change vocabulary_node_types to vocabulary_node_type, so I changed that one to taxonomy_vocabulary_node_type.

dami’s picture

Patch applies and looks good on fresh install.
Shall a upgrade path provided in system.install?

dries’s picture

I think this is a good move -- just to keep the table namespace consistent and clear. :)

catch’s picture

The upgrade path is already in taxonomy.install so that's covered, and that's the right place for it. Everything else looks fine to me on a quick visual review, and the bot is happy. Do we need to test the d6 update path manually? Don't have time to do that now but will try to have a proper look later if no-one beats me to it.

jody lynn’s picture

Status: Needs review » Reviewed & tested by the community

I tested the D6 update manually and then ran applicable simpletests (blogapi, forum, node, taxonomy) on the updated site. Everything was fine.

dries’s picture

Status: Reviewed & tested by the community » Needs work

Committed to CVS HEAD. Please update the upgrade instructions in the handbook, and mark 'fixed' once complete. Thanks!

dries’s picture

Mmm, I rolled back this patch. I think there might still be something wrong.

catch’s picture

Dries, I just ran all relevant tests (about to start a complete test run edit: that passed too), and it seemed fine. Anything specific go wrong?

catch’s picture

Status: Needs work » Needs review

Back to CNR for the test bot.

dries’s picture

Going to ?q=admin/content/taxonomy, for example, results in a database error:

PDOException: SELECT v.*, n.type FROM {taxonomy_vocabulary} v LEFT JOIN {taxonomy_vocabulary_node_type} n ON v.vid = n.vid ORDER BY v.weight, v.name - Array ( ) SQLSTATE[42S02]: Base table or view not found: 1146 Table 'drupal_cvs.taxonomy_vocabulary' doesn't exist in taxonomy_get_vocabularies() (line 463 of /Users/dries/Sites/drupal-cvs/modules/taxonomy/taxonomy.module).

Inserting a vocabulary also gives me an error:

PDOException: INSERT INTO {taxonomy_vocabulary} (name, description, help, relations, hierarchy, multiple, required, tags, module, weight) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6, :db_insert_placeholder_7, :db_insert_placeholder_8, :db_insert_placeholder_9) - Array ( [:db_insert_placeholder_0] => test [:db_insert_placeholder_1] => test [:db_insert_placeholder_2] => [:db_insert_placeholder_3] => 1 [:db_insert_placeholder_4] => 0 [:db_insert_placeholder_5] => 0 [:db_insert_placeholder_6] => 0 [:db_insert_placeholder_7] => 0 [:db_insert_placeholder_8] => taxonomy [:db_insert_placeholder_9] => 0 ) SQLSTATE[42S02]: Base table or view not found: 1146 Table 'drupal_cvs.taxonomy_vocabulary' doesn't exist in drupal_write_record() (line 3806 of /Users/dries/Sites/drupal-cvs/includes/common.inc).

I ran update.php. I didn't do a clean install so it looks like the upgrade path is broken?

damien tournoud’s picture

@Dries: we don't do 7 -> 7 upgrades for now. The patch just modified an existing upgrade function, so the behavior you are seeing is expected.

jody lynn’s picture

I think your problem is likely that the taxonomy update function is a revision of the recently committed update to switch vocabulary_node_types to singular. If updating from HEAD you have to select the update manually. Should we increment the update function number to avoid this?

damien tournoud’s picture

@Jody Lynn: we don't support 7 to 7 updates. Changes like this are bound to break existing installations.

dries’s picture

Status: Needs review » Fixed

Alright, it works with a clean install! Committed to CVS HEAD. Thanks.

jody lynn’s picture

Status: Fixed » Needs work

Marking CNW until I finish the documentation (as per comment 10)

jody lynn’s picture

Status: Needs work » Fixed

Module update documentation added: http://drupal.org/node/224333#taxonomy_tables

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.