Example #1
0
 /**
  * @param \OCP\IConfig $config
  * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform
  */
 public function __construct(IConfig $config, AbstractPlatform $platform)
 {
     $this->platform = $platform;
     $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);
 }
Example #2
0
 /**
  * @param \Doctrine\DBAL\Schema\Table[]      $tables
  * @param \Doctrine\DBAL\Schema\Sequence[]   $sequences
  * @param \Doctrine\DBAL\Schema\SchemaConfig $schemaConfig
  */
 public function __construct(array $tables = array(), array $sequences = array(), SchemaConfig $schemaConfig = null)
 {
     if ($schemaConfig == null) {
         $schemaConfig = new SchemaConfig();
     }
     $this->_schemaConfig = $schemaConfig;
     $this->_setName($schemaConfig->getName() ?: 'public');
     foreach ($tables as $table) {
         $this->_addTable($table);
     }
     foreach ($sequences as $sequence) {
         $this->_addSequence($sequence);
     }
 }
 /**
  * @group DBAL-204
  */
 public function testCleanupForeignKeysDifferentOrder()
 {
     $config = new SchemaConfig();
     $config->setName("test");
     $schema = new Schema(array(), array(), $config);
     $testTable = $schema->createTable("test.test");
     $testTable->addColumn('id', 'integer');
     $fooTable = $schema->createTable("foo.bar");
     $fooTable->addColumn('id', 'integer');
     $testTable->addForeignKeyConstraint("foo.bar", array("id"), array("id"));
     $schema->visit(new RemoveNamespacedAssets());
     $sql = $schema->toSql(new MySqlPlatform());
     $this->assertEquals(1, count($sql), "Just one CREATE TABLE statement, no foreign key and table to foo.bar");
 }
Example #4
0
 /**
  * @return int
  */
 protected function _getMaxIdentifierLength()
 {
     if ($this->_schemaConfig instanceof SchemaConfig) {
         return $this->_schemaConfig->getMaxIdentifierLength();
     } else {
         return 63;
     }
 }
Example #5
0
 /**
  * Creates a new table.
  *
  * @param string $tableName
  *
  * @return \Doctrine\DBAL\Schema\Table
  */
 public function createTable($tableName)
 {
     $table = new Table($tableName);
     $this->_addTable($table);
     foreach ($this->_schemaConfig->getDefaultTableOptions() as $name => $value) {
         $table->addOption($name, $value);
     }
     return $table;
 }
 /**
  * Create the configuration for this schema.
  *
  * @return SchemaConfig
  */
 public function createSchemaConfig()
 {
     $schemaConfig = new SchemaConfig();
     $schemaConfig->setMaxIdentifierLength($this->_platform->getMaxIdentifierLength());
     return $schemaConfig;
 }
 /**
  * @group DBAL-204
  */
 public function testFqnSchemaComparisionNoSchemaSame()
 {
     $config = new SchemaConfig();
     $config->setName("foo");
     $oldSchema = new Schema(array(), array(), $config);
     $oldSchema->createTable('bar');
     $newSchema = new Schema();
     $newSchema->createTable('bar');
     $c = new Comparator();
     $diff = $c->compare($oldSchema, $newSchema);
     $this->assertEquals(new SchemaDiff(), $c->compare($oldSchema, $newSchema));
 }
 /**
  * Creates the configuration for this schema.
  *
  * @return \Doctrine\DBAL\Schema\SchemaConfig
  */
 public function createSchemaConfig()
 {
     $schemaConfig = new SchemaConfig();
     $schemaConfig->setMaxIdentifierLength($this->_platform->getMaxIdentifierLength());
     $searchPaths = $this->getSchemaSearchPaths();
     if (isset($searchPaths[0])) {
         $schemaConfig->setName($searchPaths[0]);
     }
     $params = $this->_conn->getParams();
     if (isset($params['defaultTableOptions'])) {
         $schemaConfig->setDefaultTableOptions($params['defaultTableOptions']);
     }
     return $schemaConfig;
 }
Example #9
0
 /**
  * Check the migration of a table on a copy so we can detect errors before messing with the real table
  *
  * @param \Doctrine\DBAL\Schema\Table $table
  * @throws \OC\DB\MigrationException
  */
 protected function checkTableMigrate(Table $table)
 {
     $name = $table->getName();
     $tmpName = $this->generateTemporaryTableName($name);
     $this->copyTable($name, $tmpName);
     //create the migration schema for the temporary table
     $tmpTable = $this->renameTableSchema($table, $tmpName);
     $schemaConfig = new SchemaConfig();
     $schemaConfig->setName($this->connection->getDatabase());
     $schema = new Schema(array($tmpTable), array(), $schemaConfig);
     try {
         $this->applySchema($schema);
         $this->dropTable($tmpName);
     } catch (DBALException $e) {
         // pgsql needs to commit it's failed transaction before doing anything else
         if ($this->connection->isTransactionActive()) {
             $this->connection->commit();
         }
         $this->dropTable($tmpName);
         throw new MigrationException($table->getName(), $e->getMessage());
     }
 }
Example #10
0
	private function getSchemaConfig() {
		$config = new SchemaConfig();
		$config->setName($this->connection->getDatabase());
		return $config;
	}
 /**
  * Create the configuration for this schema.
  *
  * @return SchemaConfig
  */
 public function createSchemaConfig()
 {
     $schemaConfig = new SchemaConfig();
     $schemaConfig->setExplicitForeignKeyIndexes($this->_platform->createsExplicitIndexForForeignKeys());
     $schemaConfig->setMaxIdentifierLength($this->_platform->getMaxIdentifierLength());
     return $schemaConfig;
 }
 /**
  * Create the configuration for this schema.
  *
  * @return SchemaConfig
  */
 public function createSchemaConfig()
 {
     $schemaConfig = new SchemaConfig();
     $schemaConfig->setMaxIdentifierLength($this->_platform->getMaxIdentifierLength());
     $searchPaths = $this->getSchemaSearchPaths();
     if (isset($searchPaths[0])) {
         $schemaConfig->setName($searchPaths[0]);
     }
     return $schemaConfig;
 }
Example #13
0
 /**
  * @group DBAL-204
  */
 public function testFqnSchemaComparisionNoSchemaSame()
 {
     $config = new SchemaConfig();
     $config->setName("foo");
     $oldSchema = new Schema(array(), array(), $config);
     $oldSchema->createTable('bar');
     $newSchema = new Schema();
     $newSchema->createTable('bar');
     $expected = new SchemaDiff();
     $expected->fromSchema = $oldSchema;
     $this->assertEquals($expected, Comparator::compareSchemas($oldSchema, $newSchema));
 }
Example #14
0
 /**
  * @return bool
  */
 public function hasExplicitForeignKeyIndexes()
 {
     return $this->_schemaConfig->hasExplicitForeignKeyIndexes();
 }