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