Exemple #1
0
 public function testProxyAdapterCanInvertAddIndex()
 {
     $table = new \Phinx\Db\Table('atable');
     $index = new \Phinx\Db\Table\Index();
     $index->setType(\Phinx\Db\Table\Index::INDEX)->setColumns(array('email'));
     $this->adapter->addIndex($table, $index);
     $commands = $this->adapter->getInvertedCommands();
     $this->assertEquals('dropIndex', $commands[0]['name']);
     $this->assertEquals('atable', $commands[0]['arguments'][0]);
     $this->assertContains('email', $commands[0]['arguments'][1]);
 }
Exemple #2
0
 /**
  * Gets the SqlServer Index Definition for an Index object.
  *
  * @param Index $index Index
  * @return string
  */
 protected function getIndexSqlDefinition(Index $index, $tableName)
 {
     if (is_string($index->getName())) {
         $indexName = $index->getName();
     } else {
         $columnNames = $index->getColumns();
         if (is_string($columnNames)) {
             $columnNames = array($columnNames);
         }
         $indexName = sprintf('%s_%s', $tableName, implode('_', $columnNames));
     }
     $def = sprintf("CREATE %s INDEX %s ON %s (%s);", $index->getType() === Index::UNIQUE ? 'UNIQUE' : '', $indexName, $this->quoteTableName($tableName), '[' . implode('],[', $index->getColumns()) . ']');
     return $def;
 }
Exemple #3
0
 /**
  * Gets the MySQL Index Definition for an Index object.
  *
  * @param Index $index Index
  * @return string
  */
 protected function getIndexSqlDefinition(Index $index)
 {
     $def = '';
     $limit = '';
     if ($index->getLimit()) {
         $limit = '(' . $index->getLimit() . ')';
     }
     if ($index->getType() == Index::UNIQUE) {
         $def .= ' UNIQUE';
     }
     if ($index->getType() == Index::FULLTEXT) {
         $def .= ' FULLTEXT';
     }
     $def .= ' KEY';
     if (is_string($index->getName())) {
         $def .= ' `' . $index->getName() . '`';
     }
     $def .= ' (`' . implode('`,`', $index->getColumns()) . '`' . $limit . ')';
     return $def;
 }
 /**
  * Gets the PostgreSQL Index Definition for an Index object.
  *
  * @param Index  $index Index
  * @param string $tableName Table name
  * @return string
  */
 protected function getIndexSqlDefinition(Index $index, $tableName)
 {
     $def = sprintf("CREATE %s INDEX %s ON %s (%s);", $index->getType() == Index::UNIQUE ? 'UNIQUE' : '', $this->getIndexName($tableName, $index->getColumns()), $this->quoteTableName($tableName), implode(',', $index->getColumns()));
     return $def;
 }
Exemple #5
0
 /**
  * Add an index to a database table.
  *
  * In $options you can specific unique = true/false or name (index name).
  *
  * @param string|array|Index $columns Table Column(s)
  * @param array $options Index Options
  * @return Table
  */
 public function addIndex($columns, $options = array())
 {
     // create a new index object if strings or an array of strings were supplied
     if (!$columns instanceof Index) {
         $index = new Index();
         if (is_string($columns)) {
             $columns = array($columns);
             // str to array
         }
         $index->setColumns($columns);
         $index->setOptions($options);
     } else {
         $index = $columns;
     }
     $this->indexes[] = $index;
     return $this;
 }
 /**
  * Gets the MySQL Index Definition for an Index object.
  *
  * @param Index $index Index
  * @return string
  */
 protected function getIndexSqlDefinition(Index $index)
 {
     $def = '';
     if ($index->getType() == Index::UNIQUE) {
         $def .= ' UNIQUE KEY (`' . implode('`,`', $index->getColumns()) . '`)';
     } else {
         $def .= ' KEY (`' . implode('`,`', $index->getColumns()) . '`)';
     }
     return $def;
 }
Exemple #7
0
 /**
  * Gets the SQLite Index Definition for an Index object.
  *
  * @param Index $index Index
  * @return string
  */
 protected function getIndexSqlDefinition(Table $table, Index $index)
 {
     if ($index->getType() == Index::UNIQUE) {
         $def = 'UNIQUE INDEX';
     } else {
         $def = 'INDEX';
     }
     if (is_string($index->getName())) {
         $indexName = $index->getName();
     } else {
         $indexName = $table->getName() . '_';
         foreach ($index->getColumns() as $column) {
             $indexName .= $column . '_';
         }
         $indexName .= 'index';
     }
     $def .= ' `' . $indexName . '`';
     return $def;
 }
 /**
  * Utility method that maps an array of index options to this objects methods.
  *
  * @param array $options Options
  *
  * @throws \RuntimeException
  * @return $this
  */
 public function setOptions(array $options)
 {
     $this->index->setOptions($options);
     return $this;
 }
Exemple #9
0
 /**
  * @expectedException \RuntimeException
  * @expectedExceptionMessage "0" is not a valid index option.
  */
 public function testSetOptionThrowsExceptionIfOptionIsNotString()
 {
     $column = new Index();
     $column->setOptions(['type']);
 }