I have drupal running on a site with 2 databases, Drupal, and a secondary database where our legacy data is stored. I've created several tables in this separate legacy database using drupal modules and the schema_install hook. I would like to use schema module to analyze my second database.

usually I call
db_set_active('external-db');
to switch to the second database. Is it possible to add in some code so I can use this module on external databases that use drupal's schema?

Comments

moshe weitzman’s picture

Status: Active » Fixed

db_set_active('external-db');
schema_invoke('inspect');

markDrupal’s picture

Status: Fixed » Active

Where would I put that code?

I think it would be better if that code were in this module (I.E. Submit that code as a patch to be committed) so I could use this module's web front end to analyze my secondary database.

I still think it is a valid feature request to support more than one database connection.
All the database connections are saved to $db_url variable in the settings.php file. We could use that variable to add a new select box form element to the web front end. That would give the user a way to select between the default database or use a secondary database connection

  global $db_url;
  $form["database-connections"] = array(
    '#type' => 'select',
    '#options' => $db_url,
    '#default_value' => 'default',
  );
 

Then switch to the database in the form submit call

  db_set_active($form_state['values']['database-connections']);
  .
  .
  .
  db_set_active('default');
markDrupal’s picture

Status: Active » Needs review
StatusFileSize
new1.71 KB

I worked out a patch and tested it with my multi database setup. This allows schema module to work with more than just the default database connection.
You have to set up your secondary database connection in your settings.php file for this to work.

markDrupal’s picture

Title: Support for multiple databases » Add Support for multiple databases
Category: feature » task
mikeryan’s picture

Status: Needs review » Fixed

Committed, thanks!

Status: Fixed » Closed (fixed)

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