Skip to content

Commit

Permalink
Merge pull request #29268 from owncloud/stable10-fix-29262
Browse files Browse the repository at this point in the history
[Stable10] Register type mappings on createSchema invocation too
  • Loading branch information
DeepDiver1975 authored Oct 19, 2017
2 parents b973cc7 + 956a1a7 commit ef290c2
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 62 deletions.
2 changes: 1 addition & 1 deletion lib/private/DB/MDB2SchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function getMigrator() {
} else if ($platform instanceof PostgreSqlPlatform) {
return new PostgreSqlMigrator($this->conn, $random, $config, $dispatcher);
} else {
return new NoCheckMigrator($this->conn, $random, $config, $dispatcher);
return new Migrator($this->conn, $random, $config, $dispatcher);
}
}

Expand Down
60 changes: 37 additions & 23 deletions lib/private/DB/MySQLMigrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,21 @@
use Doctrine\DBAL\Schema\Table;

class MySQLMigrator extends Migrator {
/**
* @return Schema
*/
public function createSchema() {
$this->registerAdditionalMappings($this->connection);
return parent::createSchema();
}

/**
* @param Schema $targetSchema
* @param \Doctrine\DBAL\Connection $connection
* @return \Doctrine\DBAL\Schema\SchemaDiff
*/
protected function getDiff(Schema $targetSchema, \Doctrine\DBAL\Connection $connection) {
$platform = $connection->getDatabasePlatform();
$platform->registerDoctrineTypeMapping('enum', 'string');
$platform->registerDoctrineTypeMapping('bit', 'string');
$this->registerAdditionalMappings($connection);

$schemaDiff = parent::getDiff($targetSchema, $connection);

Expand All @@ -50,26 +56,34 @@ protected function getDiff(Schema $targetSchema, \Doctrine\DBAL\Connection $conn

return $schemaDiff;
}

/**
* Speed up migration test by disabling autocommit and unique indexes check
*
* @param \Doctrine\DBAL\Schema\Table $table
* @throws \OC\DB\MigrationException
*/
protected function checkTableMigrate(Table $table) {
$this->connection->exec('SET autocommit=0');
$this->connection->exec('SET unique_checks=0');

try {
parent::checkTableMigrate($table);
} catch (\Exception $e) {
$this->connection->exec('SET unique_checks=1');
$this->connection->exec('SET autocommit=1');
throw new MigrationException($table->getName(), $e->getMessage());
}
$this->connection->exec('SET unique_checks=1');
$this->connection->exec('SET autocommit=1');
}
/**
* Speed up migration test by disabling autocommit and unique indexes check
*
* @param \Doctrine\DBAL\Schema\Table $table
* @throws \OC\DB\MigrationException
*/
protected function checkTableMigrate(Table $table) {
$this->connection->exec('SET autocommit=0');
$this->connection->exec('SET unique_checks=0');

try {
parent::checkTableMigrate($table);
} catch (\Exception $e) {
$this->connection->exec('SET unique_checks=1');
$this->connection->exec('SET autocommit=1');
throw new MigrationException($table->getName(), $e->getMessage());
}
$this->connection->exec('SET unique_checks=1');
$this->connection->exec('SET autocommit=1');
}

/**
* @param \Doctrine\DBAL\Connection $connection
*/
private function registerAdditionalMappings(\Doctrine\DBAL\Connection $connection){
$platform = $connection->getDatabasePlatform();
$platform->registerDoctrineTypeMapping('enum', 'string');
$platform->registerDoctrineTypeMapping('bit', 'string');
}
}
33 changes: 0 additions & 33 deletions lib/private/DB/NoCheckMigrator.php

This file was deleted.

2 changes: 1 addition & 1 deletion lib/private/DB/OracleMigrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Schema\Table;

class OracleMigrator extends NoCheckMigrator {
class OracleMigrator extends Migrator {

/**
* Quote a column's name but changing the name requires recreating
Expand Down
24 changes: 20 additions & 4 deletions lib/private/DB/SQLiteMigrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,22 @@
use Doctrine\DBAL\Types\Type;

class SQLiteMigrator extends Migrator {

/**
* @return Schema
*/
public function createSchema() {
$this->registerAdditionalMappings($this->connection);
return parent::createSchema();
}

/**
* @param Schema $targetSchema
* @param \Doctrine\DBAL\Connection $connection
* @return \Doctrine\DBAL\Schema\SchemaDiff
*/
protected function getDiff(Schema $targetSchema, \Doctrine\DBAL\Connection $connection) {
$platform = $connection->getDatabasePlatform();
$platform->registerDoctrineTypeMapping('tinyint unsigned', 'integer');
$platform->registerDoctrineTypeMapping('smallint unsigned', 'integer');
$platform->registerDoctrineTypeMapping('varchar ', 'string');
$this->registerAdditionalMappings($connection);

// with sqlite autoincrement columns is of type integer
foreach ($targetSchema->getTables() as $table) {
Expand All @@ -52,4 +58,14 @@ protected function getDiff(Schema $targetSchema, \Doctrine\DBAL\Connection $conn

return parent::getDiff($targetSchema, $connection);
}

/**
* @param \Doctrine\DBAL\Connection $connection
*/
private function registerAdditionalMappings(\Doctrine\DBAL\Connection $connection) {
$platform = $connection->getDatabasePlatform();
$platform->registerDoctrineTypeMapping('tinyint unsigned', 'integer');
$platform->registerDoctrineTypeMapping('smallint unsigned', 'integer');
$platform->registerDoctrineTypeMapping('varchar ', 'string');
}
}
5 changes: 5 additions & 0 deletions tests/lib/DB/MySqlMigrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,9 @@ public function testNonOCTables() {
$this->assertTrue(true);
}

public function testCreateSchemaWithNonOcTables() {
$this->connection->createSchema();
$this->assertTrue(true);
}

}
5 changes: 5 additions & 0 deletions tests/lib/DB/SqliteMigrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,9 @@ public function testNonOCTables() {
$this->assertTrue(true);
}

public function testCreateSchemaWithNonOcTables() {
$this->connection->createSchema();
$this->assertTrue(true);
}

}

0 comments on commit ef290c2

Please sign in to comment.