Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Stable10] Register type mappings on createSchema invocation too #29268

Merged
merged 2 commits into from
Oct 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}

}