diff options
m--------- | 3rdparty | 0 | ||||
-rw-r--r-- | lib/private/db/mdb2schemamanager.php | 2 | ||||
-rw-r--r-- | tests/lib/db/migrator.php | 44 |
3 files changed, 33 insertions, 13 deletions
diff --git a/3rdparty b/3rdparty -Subproject 20066c9f65fe9237895461ff3af2ac81218382a +Subproject 6ece897f4435c246730db947576ad6f8a94dbdb diff --git a/lib/private/db/mdb2schemamanager.php b/lib/private/db/mdb2schemamanager.php index ee3d53b576a..a6d9e30cf80 100644 --- a/lib/private/db/mdb2schemamanager.php +++ b/lib/private/db/mdb2schemamanager.php @@ -58,7 +58,7 @@ class MDB2SchemaManager { /** * @return \OC\DB\Migrator */ - protected function getMigrator() { + public function getMigrator() { $platform = $this->conn->getDatabasePlatform(); if ($platform instanceof SqlitePlatform) { return new SQLiteMigrator($this->conn); diff --git a/tests/lib/db/migrator.php b/tests/lib/db/migrator.php index e94d550f836..2e49086bd63 100644 --- a/tests/lib/db/migrator.php +++ b/tests/lib/db/migrator.php @@ -19,6 +19,11 @@ class Migrator extends \PHPUnit_Framework_TestCase { */ private $connection; + /** + * @var \OC\DB\MDB2SchemaManager + */ + private $manager; + private $tableName; public function setUp() { @@ -26,6 +31,7 @@ class Migrator extends \PHPUnit_Framework_TestCase { if ($this->connection->getDriver() instanceof \Doctrine\DBAL\Driver\OCI8\Driver) { $this->markTestSkipped('DB migration tests arent supported on OCI'); } + $this->manager = new \OC\DB\MDB2SchemaManager($this->connection); $this->tableName = 'test_' . uniqid(); } @@ -62,14 +68,6 @@ class Migrator extends \PHPUnit_Framework_TestCase { return $this->connection->getDriver() instanceof \Doctrine\DBAL\Driver\PDOSqlite\Driver; } - private function getMigrator() { - if ($this->isSQLite()) { - return new \OC\DB\SQLiteMigrator($this->connection); - } else { - return new \OC\DB\Migrator($this->connection); - } - } - /** * @expectedException \OC\DB\MigrationException */ @@ -78,7 +76,7 @@ class Migrator extends \PHPUnit_Framework_TestCase { $this->markTestSkipped('sqlite doesnt throw errors when creating a new key on existing data'); } list($startSchema, $endSchema) = $this->getDuplicateKeySchemas(); - $migrator = $this->getMigrator(); + $migrator = $this->manager->getMigrator(); $migrator->migrate($startSchema); $this->connection->insert($this->tableName, array('id' => 1, 'name' => 'foo')); @@ -91,7 +89,7 @@ class Migrator extends \PHPUnit_Framework_TestCase { public function testUpgrade() { list($startSchema, $endSchema) = $this->getDuplicateKeySchemas(); - $migrator = $this->getMigrator(); + $migrator = $this->manager->getMigrator(); $migrator->migrate($startSchema); $this->connection->insert($this->tableName, array('id' => 1, 'name' => 'foo')); @@ -105,7 +103,7 @@ class Migrator extends \PHPUnit_Framework_TestCase { public function testInsertAfterUpgrade() { list($startSchema, $endSchema) = $this->getDuplicateKeySchemas(); - $migrator = $this->getMigrator(); + $migrator = $this->manager->getMigrator(); $migrator->migrate($startSchema); $migrator->migrate($endSchema); @@ -132,7 +130,29 @@ class Migrator extends \PHPUnit_Framework_TestCase { $table->addColumn('name', 'string'); $table->setPrimaryKey(array('id')); - $migrator = $this->getMigrator(); + $migrator = $this->manager->getMigrator(); + $migrator->migrate($startSchema); + + $migrator->checkMigrate($endSchema); + $migrator->migrate($endSchema); + + $this->assertTrue(true); + } + + public function testReservedKeywords() { + $startSchema = new Schema(array(), array(), $this->getSchemaConfig()); + $table = $startSchema->createTable($this->tableName); + $table->addColumn('id', 'integer', array('autoincrement' => true)); + $table->addColumn('user', 'string', array('length' => 255)); + $table->setPrimaryKey(array('id')); + + $endSchema = new Schema(array(), array(), $this->getSchemaConfig()); + $table = $endSchema->createTable($this->tableName); + $table->addColumn('id', 'integer', array('autoincrement' => true)); + $table->addColumn('user', 'string', array('length' => 64)); + $table->setPrimaryKey(array('id')); + + $migrator = $this->manager->getMigrator(); $migrator->migrate($startSchema); $migrator->checkMigrate($endSchema); |