public function testDropAndCreateIndex()
 {
     $table = $this->getTestTable('test_create_index');
     $table->addUniqueIndex(array('test'), 'test');
     $this->_sm->dropAndCreateTable($table);
     $this->_sm->dropAndCreateIndex($table->getIndex('test'), $table);
     $tableIndexes = $this->_sm->listTableIndexes('test_create_index');
     $this->assertType('array', $tableIndexes);
     $this->assertEquals('test', strtolower($tableIndexes['test']->getName()));
     $this->assertEquals(array('test'), array_map('strtolower', $tableIndexes['test']->getColumns()));
     $this->assertTrue($tableIndexes['test']->isUnique());
     $this->assertFalse($tableIndexes['test']->isPrimary());
 }
 /**
  * Get table indexes.
  *
  * Get table indexes
  * @param string $table
  * @return array
  */
 public function getIndexes($table)
 {
     $indexes = ['unique' => [], 'index' => []];
     foreach ($this->schema->listTableIndexes($table) as $indexName => $index) {
         if ('primary' != $indexName) {
             $columns = $index->getColumns();
             $unique = $index->isUnique();
             $addKey = $unique ? 'unique' : 'index';
             $isForeign = $this->isIndexForeign($columns, $table);
             $generatedIndexName = $this->generateIndexName($table, $columns, $unique, $isForeign);
             $columns = count($columns) == 1 ? reset($columns) : $columns;
             if ($indexName == $generatedIndexName) {
                 $indexes[$addKey][] = $columns;
             } else {
                 $indexes[$addKey][$indexName] = $columns;
             }
         }
     }
     return $indexes;
 }
 public function testListTableIndexes()
 {
     $indexes = $this->sm->listTableIndexes('points');
     $spatialIndexes = array('idx_27ba8e293be136c3', 'idx_27ba8e295f51a43c', 'idx_27ba8e295afbb72d', 'idx_27ba8e29b7a5f324', 'idx_27ba8e293c257075', 'idx_27ba8e2999674a3d', 'idx_27ba8e29cf3dedbb', 'idx_27ba8e29cf3dedbb', 'idx_27ba8e293d5fe69e', 'idx_27ba8e29b832b304');
     $nonSpatialIndexes = array('idx_text', 'idx_text_gist');
     foreach ($spatialIndexes as $spatialIndex) {
         $this->assertArrayHasKey($spatialIndex, $indexes);
         $this->assertTrue($indexes[$spatialIndex]->hasFlag('SPATIAL'));
     }
     foreach ($nonSpatialIndexes as $nonSpatialIndex) {
         $this->assertArrayHasKey($nonSpatialIndex, $indexes);
         $this->assertFalse($indexes[$nonSpatialIndex]->hasFlag('SPATIAL'));
     }
 }
 /**
  * @param string                                      $table Table Name
  * @param \Doctrine\DBAL\Schema\AbstractSchemaManager $schema
  * @param bool                                        $ignoreIndexNames
  */
 public function __construct($table, $schema)
 {
     $this->indexes = array();
     $this->multiFieldIndexes = array();
     $indexes = $schema->listTableIndexes($table);
     foreach ($indexes as $index) {
         $indexArray = $this->indexToArray($table, $index);
         if (count($indexArray['columns']) == 1) {
             $columnName = $indexArray['columns'][0];
             $this->indexes[$columnName] = (object) $indexArray;
         } else {
             $this->multiFieldIndexes[] = (object) $indexArray;
         }
     }
 }
Esempio n. 5
0
 /**
  * return the the interesect on primary index and foreign key.
  * if we have 2 primary key that are also foreign key without a type field it should be a pivot table !
  *
  * @param $table
  * @return array
  */
 public function checkPivots($table)
 {
     $foreignKeys = $this->schema->listTableForeignKeys($table);
     $indexes = $this->schema->listTableIndexes($table);
     $toto = [];
     foreach ($foreignKeys as $key) {
         $toto[] = $key->getLocalColumns();
     }
     $tata = [];
     foreach ($indexes as $key) {
         if ($key->isPrimary()) {
             $tata[] = $key->getColumns();
         }
     }
     return array_intersect(array_flatten($toto), array_flatten($tata));
 }
 /**
  * @group DBAL-1095
  */
 public function testDoesNotListIndexesImplicitlyCreatedByForeignKeys()
 {
     if (!$this->_sm->getDatabasePlatform()->supportsForeignKeyConstraints()) {
         $this->markTestSkipped('This test is only supported on platforms that have foreign keys.');
     }
     $primaryTable = new Table('test_list_index_implicit_primary');
     $primaryTable->addColumn('id', 'integer');
     $primaryTable->setPrimaryKey(array('id'));
     $foreignTable = new Table('test_list_index_implicit_foreign');
     $foreignTable->addColumn('fk1', 'integer');
     $foreignTable->addColumn('fk2', 'integer');
     $foreignTable->addIndex(array('fk1'), 'explicit_fk1_idx');
     $foreignTable->addForeignKeyConstraint('test_list_index_implicit_primary', array('fk1'), array('id'));
     $foreignTable->addForeignKeyConstraint('test_list_index_implicit_primary', array('fk2'), array('id'));
     $this->_sm->dropAndCreateTable($primaryTable);
     $this->_sm->dropAndCreateTable($foreignTable);
     $indexes = $this->_sm->listTableIndexes('test_list_index_implicit_foreign');
     $this->assertCount(2, $indexes);
     $this->assertArrayHasKey('explicit_fk1_idx', $indexes);
     $this->assertArrayHasKey('idx_6d88c7b4fdc58d6c', $indexes);
 }
Esempio n. 7
0
 /**
  * {@see AbstractSchemaManager::listTableIndexes}
  */
 public function listTableIndexes($table)
 {
     return $this->manager->listTableIndexes($this->replacePrefix($table));
 }
Esempio n. 8
0
 /**
  * @return  array
  */
 private function listIndexes()
 {
     return $this->schema->listTableIndexes($this->table);
 }