summaryrefslogtreecommitdiffstats
path: root/lib/private/Repair
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2015-07-30 10:57:16 +0200
committerMorris Jobke <hey@morrisjobke.de>2017-03-21 16:42:12 -0600
commit713f684a8b543050c6107e65dcf65a0e1566914c (patch)
treef47d453233417dc7cbe03b318d91ed0995afa64f /lib/private/Repair
parentd2b1b0224437e521094dd251bc84bc93d1e338b1 (diff)
downloadnextcloud-server-713f684a8b543050c6107e65dcf65a0e1566914c.tar.gz
nextcloud-server-713f684a8b543050c6107e65dcf65a0e1566914c.zip
Adding tests for 4 byte unicode characters
* success on SQLite and Postgres * failure on MySQL due to the limited charset that only supports up to 3 bytes Add config option to update charset of mysql to utf8mb4 * fully optional * requires additional options set in the database only disable unicode test on mysql Fixing ctor call Adding docker based unit test execution for mysql utf8mb4 Add mysqlmb4 test configuration to Jenkinsfile fix collation on utf8mb4 Properly setup charset and collation in the doctrine connection Allow files containing 4-byte chars in case the database supports it During setup of a mysql database we try to detect if charset 'utf8mb4' can be used Fix mysql settings Add console command to migrate the charset Set ROW_FORMAT before setting collation to mb4 Also select tables with wrong collation Faster MySQL docker Signed-off-by: Morris Jobke <hey@morrisjobke.de>
Diffstat (limited to 'lib/private/Repair')
-rw-r--r--lib/private/Repair/Collation.php38
1 files changed, 32 insertions, 6 deletions
diff --git a/lib/private/Repair/Collation.php b/lib/private/Repair/Collation.php
index 12e83c2b981..a01700e047e 100644
--- a/lib/private/Repair/Collation.php
+++ b/lib/private/Repair/Collation.php
@@ -88,6 +88,11 @@ class Collation implements IRepairStep {
}
$output->info("Change collation for $table ...");
+ if ($characterSet === 'utf8mb4') {
+ // need to set row compression first
+ $query = $this->connection->prepare('ALTER TABLE `' . $table . '` ROW_FORMAT=COMPRESSED;');
+ $query->execute();
+ }
$query = $this->connection->prepare('ALTER TABLE `' . $table . '` CONVERT TO CHARACTER SET ' . $characterSet . ' COLLATE ' . $characterSet . '_bin;');
try {
$query->execute();
@@ -99,16 +104,21 @@ class Collation implements IRepairStep {
}
}
}
+ if (empty($tables)) {
+ $output->info('All tables already have the correct collation -> nothing to do');
+ }
}
/**
- * @param \Doctrine\DBAL\Connection $connection
+ * @param IDBConnection $connection
* @return string[]
*/
- protected function getAllNonUTF8BinTables($connection) {
+ protected function getAllNonUTF8BinTables(IDBConnection $connection) {
$dbName = $this->config->getSystemValue("dbname");
$characterSet = $this->config->getSystemValue('mysql.utf8mb4', false) ? 'utf8mb4' : 'utf8';
- $rows = $connection->fetchAll(
+
+ // fetch tables by columns
+ $statement = $connection->executeQuery(
"SELECT DISTINCT(TABLE_NAME) AS `table`" .
" FROM INFORMATION_SCHEMA . COLUMNS" .
" WHERE TABLE_SCHEMA = ?" .
@@ -116,11 +126,27 @@ class Collation implements IRepairStep {
" AND TABLE_NAME LIKE \"*PREFIX*%\"",
array($dbName)
);
- $result = array();
+ $rows = $statement->fetchAll();
+ $result = [];
foreach ($rows as $row) {
- $result[] = $row['table'];
+ $result[$row['table']] = true;
}
- return $result;
+
+ // fetch tables by collation
+ $statement = $connection->executeQuery(
+ "SELECT DISTINCT(TABLE_NAME) AS `table`" .
+ " FROM INFORMATION_SCHEMA . TABLES" .
+ " WHERE TABLE_SCHEMA = ?" .
+ " AND TABLE_COLLATION <> '" . $characterSet . "_bin'" .
+ " AND TABLE_NAME LIKE \"*PREFIX*%\"",
+ [$dbName]
+ );
+ $rows = $statement->fetchAll();
+ foreach ($rows as $row) {
+ $result[$row['table']] = true;
+ }
+
+ return array_keys($result);
}
}