Why does the 'name' key in {sequences} have the table prefix prepended?
The CivicSpace folks are fixing a minor issue with their installer. Part of the problem is a quirk in the way that Drupal's database-neutral code handles sequence numbers. For the node table, for example, node_save calls the following code: $node->nid = db_next_id <http://drupaldocs.org/api/4.6/function/db_next_id>('{node}_nid'); So if you have a table prefix of "myprefix_", the actual key in the {sequence} table (where db_next_id() is saving away the last value of the sequence number is going to "myprefix_node_nid", rather than "node_nid". Why is this? This is one of the few places I know of that the table prefix gets pushed into the database. Having had to change the table prefix for a client before, I've been bitten by this a couple of times myself. Is there any reason why we could *not* do this? Rob Thorne Torenware Networks
Is there any reason why we could *not* do this?
When you share tables across drupal sites, you must share the sequences table and thus the ids need to be unique. if this pains you or others, I encourage you to submit a patch which gets rid of drupal sequences in favor of native DB sequences. -moshe
I've no problem with the database-neutral code per se. But a point to consider: remember that unless you patch Drupal quite a bit, if you change the table prefix, the key (with the prefixed key name) is going to end up in another table anyway. Think it through. The shared sites need to have separate table prefixes. Suppose you have prefix "a_" and prefix "b_". If you prefix the key names, then you have a row with a_node.name="a_node_id" in a table "a_node", and a row with b_node.name = 'b_node_id' in a table "b_node". How is this better than having a row with a_node.name="node_id" in a table "a_node", and a row with b_node.name = 'node_id' in a table "b_node". Both examples should work equally well. But the latter is easier to manage in installers or for transferring data. Rob Moshe Weitzman wrote:
Is there any reason why we could *not* do this?
When you share tables across drupal sites, you must share the sequences table and thus the ids need to be unique.
if this pains you or others, I encourage you to submit a patch which gets rid of drupal sequences in favor of native DB sequences.
-moshe
participants (2)
-
Moshe Weitzman -
Rob Thorne