You are here

function drush_schema_compare in Schema 7

Same name and namespace in other branches
  1. 8 schema.drush.inc \drush_schema_compare()

Implements drush_COMMANDFILE_COMMANDNAME().

File

./schema.drush.inc, line 98
Schema drush commands.

Code

function drush_schema_compare($type) {

  // Get the defined database schema.
  $schema = schema_get_schema();

  // Compare it with the actual database schema.
  $comparison = schema_compare_schemas($schema);

  // Change the user-friendly type ID to the machine-readable one.
  switch ($type) {
    case 'match':
      $type = 'same';
      break;
    case 'mismatch':
      $type = 'different';
      break;
    default:

      // Type ID is the same; it doesn't need to be changed.
      break;
  }

  // Different classes of tables must be handled differently.
  if (isset($comparison[$type])) {
    switch ($type) {

      // These table types have modules associated with them.
      // Display the module name in front.
      case 'same':
      case 'different':
      case 'missing':
        foreach ($comparison[$type] as $module => $tables) {
          foreach ($tables as $table => $data) {
            drush_print($module . ": " . $table);
          }
        }
        break;

      // These table types have no modules associated with them.
      // Display the table names only.
      case 'extra':
        foreach ($comparison[$type] as $table) {
          drush_print($table);
        }
        break;
    }
  }
}