Issue #2522120 by jhedstrom: DbDumpCommand should add collation information to the generated script

8.0.x
Nathaniel Catchpole 2015-07-06 13:35:28 +01:00
parent b04d55edfe
commit 90b4ae4c4a
1 changed files with 19 additions and 1 deletions

View File

@ -220,6 +220,9 @@ class DbDumpCommand extends Command {
// Set primary key, unique keys, and indexes.
$this->getTableIndexes($table, $definition);
// Set table collation.
$this->getTableCollation($table, $definition);
return $definition;
}
@ -235,7 +238,6 @@ class DbDumpCommand extends Command {
// Note, this query doesn't support ordering, so that is worked around
// below by keying the array on Seq_in_index.
$query = $this->connection->query("SHOW INDEX FROM {" . $table . "}");
$indexes = [];
while (($row = $query->fetchAssoc()) !== FALSE) {
$index_name = $row['Key_name'];
$column = $row['Column_name'];
@ -259,6 +261,22 @@ class DbDumpCommand extends Command {
}
}
/**
* Set the table collation.
*
* @param string $table
* The table to find indexes for.
* @param array &$definition
* The schema definition to modify.
*/
protected function getTableCollation($table, &$definition) {
$query = $this->connection->query("SHOW TABLE STATUS LIKE '{" . $table . "}'");
$data = $query->fetchAssoc();
// Set `mysql_character_set`. This will be ignored by other backends.
$definition['mysql_character_set'] = str_replace('_general_ci', '', $data['Collation']);
}
/**
* Gets all data from a given table.
*