[development] sequences and table prefixing

Moshe Weitzman weitzman at tejasa.com
Thu Jan 19 13:41:08 UTC 2006


I've come across this with multi-sites as well. i always share sequences 
table as you suggest.

I haven't tried it, but I'm sure you could alter $db_prefix on a per request 
basis. Just make your settings.php put in the right value for sequences 
depending on the domain of the request.

$db_prefix = array(...)
switch (conf_init()) {
   case '5th_site.com':
     db_prefix['sequences'] = foo.sequences;
     break;
   default:
     db_prefix['sequences'] = shared.sequences;
}

If you have lots of settings.php files (i.e. lots of sites), I usually do an 
include(../settings_globals.inc) and put my common settings stuff there. 
That way, I don't repeat the same code for each site. make sense?

Having said that, I'd really like to see us do away with sequences and just 
use native identity/auto-increment/serial fields instead.

-moshe

Robert Douglass wrote:
> If I want to share tables between databases (user, spam, whatever), I 
> usually have to consider issues with the primary key sequences. The 
> solution that comes to mind is to share the sequences table as well. It 
> is nice that Drupal offers this flexibility.
> 
> Is there a way that one can specify "use db1.sequences for node_id 
> sequences, db2.sequences for user_id sequences, and db3.sequences for 
> spam_id sequences"? I don't think so, but this might be a feature we 
> should consider implementing.
> 
> Why? Because the current system only allows a database to join a shared 
> pool of something (take spam for now) at the beginning of its lifetime. 
> If I had 5 sites sharing spam tables, and wanted to integrate an 
> existing site, I'd be out of luck if I had to rely on a shared, running 
> sequid for the spam tables.
> 
> I think it would be very useful if one could specify a sequences array 
> like the $db_prefix array:
> 
> $db_sequences = array(
>   'node_id' => 'default',
>   'spam_id' => 'db_spam.',
> );
> 
> This would result in all sequences being taken from the default sequence 
> table except for the (purely illustrational) 'spam_id' sequence, which 
> would be taken from the db_spam.sequences table.
> 
> Is there a way to do this currently in Drupal that I've overlooked? 
> Would people be in support of this functionality if a patch appeared?
> 
> cheers,
> 
> Robert



More information about the development mailing list