The DatabaseSchema
added a new method and abstract method:
/**
* Create an exact duplicate of an existing table, including all content.
*
* @param $source
* The name of the table to be copied.
* @param $target
* The name of the new table to be created and populated with data.
*
* @throws DatabaseSchemaObjectExistsException
* If the new table specified already exists.
*/
public function cloneTable($source, $target) {
if ($this->tableExists($target)) {
throw new DatabaseSchemaObjectExistsException(t('Table @name already exists.', array('@name' => $target)));
}
$statements = $this->cloneTableSql($source, $target);
foreach ($statements as $statement) {
$this->connection->query($statement);
}
}
/**
* Generate an array of query strings suitable for cloning a table.
*
* @param $source
* The name of the table to be copied.
* @param $target
* The name of the new table to be created and populated with data.
* @return
* An array of SQL statements to clone the table, including inserting data.
*/
abstract protected function cloneTableSql($source, $target);