#!/usr/bin/env php getModuleList() as $module => $filename) { $output .= " * - $module\n"; } $output .= " */\n\n"; // Get the current schema, order it by table name. $schema = drupal_get_schema(); ksort($schema); // Override the field type of the filename primary key to bypass the // InnoDB 191 character limitation. if (isset($schema['system']['primary key']) && $schema['system']['primary key'] == 'filename' && isset($schema['system']['fields']['filename']['type']) && $schema['system']['fields']['filename']['type'] == 'varchar') { $schema['system']['fields']['filename']['type'] = 'varchar_ascii'; } // Export all the tables in the schema. foreach ($schema as $table => $data) { // Remove descriptions to save time and code. unset($data['description']); foreach ($data['fields'] as &$field) { unset($field['description']); } // Dump the table structure. $output .= "db_create_table('" . $table . "', " . drupal_var_export($data) . ");\n"; // Don't output values for those tables. if (substr($table, 0, 5) == 'cache' || $table == 'sessions' || $table == 'watchdog') { $output .= "\n"; continue; } // Prepare the export of values. $result = db_query('SELECT * FROM {'. $table .'}'); $insert = ''; while ($record = db_fetch_array($result)) { // users.uid is a serial and inserting 0 into a serial can break MySQL. // So record uid + 1 instead of uid for every uid and once all records // are in place, fix them up. if ($table == 'users') { $record['uid']++; } $insert .= '->values('. drupal_var_export($record) .")\n"; } // Dump the values if there are some. if ($insert) { $output .= "db_insert('". $table . "')->fields(". drupal_var_export(array_keys($data['fields'])) .")\n"; $output .= $insert; $output .= "->execute();\n"; } // Add the statement fixing the serial in the user table. if ($table == 'users') { $output .= "db_query('UPDATE {users} SET uid = uid - 1');\n"; } $output .= "\n"; } print $output;