function Schema::renameTable

Rename a table.

Parameters

$table: The table to be renamed.

$new_name: The new name for the table.

Overrides Schema::renameTable

File

core/modules/mysql/src/Driver/Database/mysql/Schema.php, line 379

Class

Schema
MySQL implementation of \Drupal\Core\Database\Schema.

Namespace

Drupal\mysql\Driver\Database\mysql

Code

public function renameTable($table, $new_name) {
  if (!$this->tableExists($table)) {
    throw new SchemaObjectDoesNotExistException("Cannot rename '{$table}' to '{$new_name}': table '{$table}' doesn't exist.");
  }
  if ($this->tableExists($new_name)) {
    throw new SchemaObjectExistsException("Cannot rename '{$table}' to '{$new_name}': table '{$new_name}' already exists.");
  }
  $info = $this->getPrefixInfo($new_name);
  $this->connection
    ->query('ALTER TABLE {' . $table . '} RENAME TO `' . $info['table'] . '`');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.