summaryrefslogtreecommitdiffstats
path: root/lib/private/DB
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/DB
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/DB')
-rw-r--r--lib/private/DB/Connection.php8
-rw-r--r--lib/private/DB/ConnectionFactory.php15
-rw-r--r--lib/private/DB/MDB2SchemaManager.php10
-rw-r--r--lib/private/DB/MDB2SchemaReader.php10
4 files changed, 31 insertions, 12 deletions
diff --git a/lib/private/DB/Connection.php b/lib/private/DB/Connection.php
index 4b1c560c5ca..0ee58a54ece 100644
--- a/lib/private/DB/Connection.php
+++ b/lib/private/DB/Connection.php
@@ -416,6 +416,12 @@ class Connection extends \Doctrine\DBAL\Connection implements IDBConnection {
* @since 11.0.0
*/
public function supports4ByteText() {
- return ! ($this->getDatabasePlatform() instanceof MySqlPlatform && $this->getParams()['charset'] !== 'utf8mb4');
+ if (!$this->getDatabasePlatform() instanceof MySqlPlatform) {
+ return true;
+ }
+ if ($this->getParams()['charset'] === 'utf8mb4') {
+ return true;
+ }
+ return false;
}
}
diff --git a/lib/private/DB/ConnectionFactory.php b/lib/private/DB/ConnectionFactory.php
index d8f1fb2480d..39f15ff4a63 100644
--- a/lib/private/DB/ConnectionFactory.php
+++ b/lib/private/DB/ConnectionFactory.php
@@ -201,6 +201,21 @@ class ConnectionFactory {
$connectionParams['driverOptions'] = $driverOptions;
}
+ // set default table creation options
+ $connectionParams['defaultTableOptions'] = [
+ 'collate' => 'utf8_bin',
+ 'tablePrefix' => $connectionParams['tablePrefix']
+ ];
+
+ if($this->config->getValue('mysql.utf8mb4', false)) {
+ $connectionParams['defaultTableOptions'] = [
+ 'collate' => 'utf8mb4_bin',
+ 'charset' => 'utf8mb4',
+ 'row_format' => 'compressed',
+ 'tablePrefix' => $connectionParams['tablePrefix']
+ ];
+ }
+
return $connectionParams;
}
}
diff --git a/lib/private/DB/MDB2SchemaManager.php b/lib/private/DB/MDB2SchemaManager.php
index f209991eb84..89b0d153212 100644
--- a/lib/private/DB/MDB2SchemaManager.php
+++ b/lib/private/DB/MDB2SchemaManager.php
@@ -33,6 +33,7 @@ use Doctrine\DBAL\Platforms\MySqlPlatform;
use Doctrine\DBAL\Platforms\OraclePlatform;
use Doctrine\DBAL\Platforms\PostgreSqlPlatform;
use Doctrine\DBAL\Platforms\SqlitePlatform;
+use Doctrine\DBAL\Schema\Schema;
use OCP\IDBConnection;
class MDB2SchemaManager {
@@ -66,7 +67,8 @@ class MDB2SchemaManager {
*/
public function createDbFromStructure($file) {
$schemaReader = new MDB2SchemaReader(\OC::$server->getConfig(), $this->conn->getDatabasePlatform());
- $toSchema = $schemaReader->loadSchemaFromFile($file);
+ $toSchema = new Schema([], [], $this->conn->getSchemaManager()->createSchemaConfig());
+ $toSchema = $schemaReader->loadSchemaFromFile($file, $toSchema);
return $this->executeSchemaChange($toSchema);
}
@@ -100,7 +102,8 @@ class MDB2SchemaManager {
private function readSchemaFromFile($file) {
$platform = $this->conn->getDatabasePlatform();
$schemaReader = new MDB2SchemaReader(\OC::$server->getConfig(), $platform);
- return $schemaReader->loadSchemaFromFile($file);
+ $toSchema = new Schema([], [], $this->conn->getSchemaManager()->createSchemaConfig());
+ return $schemaReader->loadSchemaFromFile($file, $toSchema);
}
/**
@@ -137,7 +140,8 @@ class MDB2SchemaManager {
*/
public function removeDBStructure($file) {
$schemaReader = new MDB2SchemaReader(\OC::$server->getConfig(), $this->conn->getDatabasePlatform());
- $fromSchema = $schemaReader->loadSchemaFromFile($file);
+ $toSchema = new Schema([], [], $this->conn->getSchemaManager()->createSchemaConfig());
+ $fromSchema = $schemaReader->loadSchemaFromFile($file, $toSchema);
$toSchema = clone $fromSchema;
/** @var $table \Doctrine\DBAL\Schema\Table */
foreach ($toSchema->getTables() as $table) {
diff --git a/lib/private/DB/MDB2SchemaReader.php b/lib/private/DB/MDB2SchemaReader.php
index 0a51f1b48f2..dc067b43c4a 100644
--- a/lib/private/DB/MDB2SchemaReader.php
+++ b/lib/private/DB/MDB2SchemaReader.php
@@ -68,21 +68,15 @@ class MDB2SchemaReader {
$this->config = $config;
$this->DBNAME = $config->getSystemValue('dbname', 'owncloud');
$this->DBTABLEPREFIX = $config->getSystemValue('dbtableprefix', 'oc_');
-
- // Oracle does not support longer index names then 30 characters.
- // We use this limit for all DBs to make sure it does not cause a
- // problem.
- $this->schemaConfig = new SchemaConfig();
- $this->schemaConfig->setMaxIdentifierLength(30);
}
/**
* @param string $file
+ * @param Schema $schema
* @return Schema
* @throws \DomainException
*/
- public function loadSchemaFromFile($file) {
- $schema = new \Doctrine\DBAL\Schema\Schema();
+ public function loadSchemaFromFile($file, Schema $schema) {
$loadEntities = libxml_disable_entity_loader(false);
$xml = simplexml_load_file($file);
libxml_disable_entity_loader($loadEntities);