Hello,

I'm trying to export the database schema for a non-default application that we have. I have added the database to settings.php, and when I go to content->schema->settings, I can select the database from the dropdown, but when I go to the inspect tab, it only shows the following with no structure:

This page shows the live database schema as it currently exists on this system. Known tables are grouped by the module that defines them; unknown tables are all grouped together.
To implement hook_schema() for a module that has existing tables, copy the schema structure for those tables directly into the module's hook_schema() and return $schema.

without any database schema.

I also find that the compare tab shows "Missing(75)" and "Extra(0)" so it does not seem to be querying the database.

Any ideas on how I can resolve this issue?

Drupal:7.22
MySQL:Ver 14.14 Distrib 5.5.29, for debian-linux-gnu (x86_64) using readline 6.2
PHP:PHP 5.3.10-1ubuntu3.6 with Suhosin-Patch (cli) (built: Mar 11 2013 14:31:48)

Comments

sjs205’s picture

Status: Active » Fixed

I managed to get around this problem using the following steps:

  1. Backup default database;
  2. Backup the structure of the non-default database;
  3. Import the structure of the non-default database to the default database;
  4. Change the schema database to the default and then go to the inspect page and get the schema data;
  5. Once complete, restore the default database;

A bit of a hack, but it worked for me.

:)

heine’s picture

Status: Fixed » Active

If you believe this to be a bug, then your workaround did not fix it.

FWIW, I cannot reproduce this. However, when either a default key is missing for the alternate db array or the database name is misspelled (ie db doesn't exist), I see similar behaviour as the OP; only missing, no extra tables.

I'd expect an error message instead.

dave reid’s picture

Title: Unable to "Inspect" non-default MySQL database » Schema engines should use the actual connection given to perform inspection, not use db_query()
Priority: Normal » Major

This is actually correct. The code inside the actual schema engines runs db_query(), which by nature only runs on the default Drupal database. So if you are trying to inspect a MySQL table not on the same server, or a different database type (PostgreSQL from MySQL in Drupal), things fail miserably.

dave reid’s picture

Status: Active » Needs review
StatusFileSize
new3.81 KB

Please test the following patch. This fixes major bugs I had trying to inspect a PosgreSQL table from a MySQL Drupal install.

dave reid’s picture

I don't think this will full resolve things. The major problem is that schema_dbobject() will always return the engine class of the Drupal install, and not actually the engine of the connection that you want to inspect. This is a major, major bug.

dave reid’s picture

StatusFileSize
new6.69 KB

Ok I think this should do it. This adds an optional parameter to schema_dbobject() for the connection to use. This ensures that the proper database connection object is passed into the class. This means that the first parameter of the inspect() method is no longer used and is deprecated. This is good, because it ensures that the schema classes actually use the passed in connection object.

dave reid’s picture

StatusFileSize
new6.82 KB

Corrected patch. Has been tested with all admin screens.

dave reid’s picture

StatusFileSize
new8.32 KB

Managed to make this fully backwards-compatible. This should be ready to go.

dave reid’s picture

StatusFileSize
new8.38 KB

One last attempt to simplify schema_dbobject() and it's uses.

dave reid’s picture

Status: Needs review » Fixed

Committed #9 to 7.x-1.x
http://drupalcode.org/project/schema.git/commit/9b2856b

For the original report: keep in mind the 'Inspect' tab can only compare the selected database with your current, installed version of Drupal's hook_schema() implementations(). I just tested this with a connection set to my old Drupal 6 database and the Inspect tab does show what I would expect how the tables are different between Drupal 6 and 7.

Status: Fixed » Closed (fixed)

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