]> source.dussan.org Git - nextcloud-server.git/commitdiff
Fix migrator for postgres
authorRobin Appelman <icewind@owncloud.com>
Fri, 14 Mar 2014 15:28:56 +0000 (16:28 +0100)
committerRobin Appelman <icewind@owncloud.com>
Tue, 3 Jun 2014 09:17:21 +0000 (11:17 +0200)
lib/private/db/migrator.php
tests/lib/db/migrator.php

index 63fddd9c28a82e4103bc134e48825bf4f800558b..3f32e8c603edd16fa4d9a4343cbd0c6c299a3907 100644 (file)
@@ -81,6 +81,8 @@ class Migrator {
                        $this->applySchema($schema);
                        $this->dropTable($tmpName);
                } catch (DBALException $e) {
+                       // pgsql needs to commit it's failed transaction before doing anything else
+                       $this->connection->commit();
                        $this->dropTable($tmpName);
                        throw new MigrationException($table->getName(), $e->getMessage());
                }
@@ -153,7 +155,7 @@ class Migrator {
                $quotedSource = $this->connection->quoteIdentifier($sourceName);
                $quotedTarget = $this->connection->quoteIdentifier($targetName);
 
-               $this->connection->exec('CREATE TABLE ' . $quotedTarget . ' LIKE ' . $quotedSource);
+               $this->connection->exec('CREATE TABLE ' . $quotedTarget . ' (LIKE ' . $quotedSource . ')');
                $this->connection->exec('INSERT INTO ' . $quotedTarget . ' SELECT * FROM ' . $quotedSource);
        }
 
index 258d6451847cf529d31dd2f33c8b9a4a6fda6027..88f6d7dcc63451341df86cb476f4f1f95edafad2 100644 (file)
@@ -20,25 +20,21 @@ class Migrator extends \PHPUnit_Framework_TestCase {
 
        private $tableName;
 
-       private $fullTableName;
-
        public function setUp() {
                $this->tableName = 'test_' . uniqid();
                $this->connection = \OC_DB::getConnection();
                if ($this->connection->getDriver() instanceof \Doctrine\DBAL\Driver\PDOSqlite\Driver) {
                        $this->markTestSkipped('Migration tests dont function on sqlite since sqlite doesnt give an error on existing duplicate data');
-               } else {
-                       $this->fullTableName = $this->connection->getDatabase() . '.' . $this->tableName;
                }
        }
 
        public function tearDown() {
-               $this->connection->exec('DROP TABLE ' . $this->fullTableName);
+               $this->connection->exec('DROP TABLE ' . $this->tableName);
        }
 
        private function getInitialSchema() {
                $schema = new Schema(array(), array(), $this->getSchemaConfig());
-               $table = $schema->createTable($this->fullTableName);
+               $table = $schema->createTable($this->tableName);
                $table->addColumn('id', 'integer');
                $table->addColumn('name', 'string');
                $table->addIndex(array('id'), $this->tableName . '_id');
@@ -47,7 +43,7 @@ class Migrator extends \PHPUnit_Framework_TestCase {
 
        private function getNewSchema() {
                $schema = new Schema(array(), array(), $this->getSchemaConfig());
-               $table = $schema->createTable($this->fullTableName);
+               $table = $schema->createTable($this->tableName);
                $table->addColumn('id', 'integer');
                $table->addColumn('name', 'string');
                $table->addUniqueIndex(array('id'), $this->tableName . '_id');