for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace carono\yii2migrate;
class IndexColumn
{
/**
* @var Migration
*/
public $migrate;
protected $_unique;
protected $_name;
protected $_columns;
protected $_table;
protected $_length;
public function length($value)
$this->_length = $value;
return $this;
}
* @param $migrate
* @return $this
public function setMigrate($migrate)
$this->migrate = $migrate;
* @param bool $value
public function unique($value = true)
$this->_unique = $value;
* @param $name
public function name($name)
$this->_name = $name;
* @param array $columns
* @return IndexColumn
public function columns($columns)
$this->_columns = $columns;
* @param $table
public function table($table)
$this->_table = $table;
* @return mixed
public function getTable()
return $this->_table;
public function getColumns()
return $this->_columns;
public function getUnique()
return $this->_unique;
public function formIndexName()
$unique = $this->_unique;
$columns = $this->_columns;
if (!$this->_name) {
$indexName = Migration::formIndexName($this->_table, $columns, $unique ? '_unq' : '_idx', $this->migrate->db->tablePrefix);
$name = $this->migrate->expandTablePrefix($indexName);
} else {
$name = $this->_name;
return $name;
public function apply()
if ($this->_length) {
foreach ($columns as $idx => $column) {
$columns[$idx] = "{$column}({$this->_length})";
$this->migrate->createIndex($this->formIndexName(), $this->_table, $columns, $this->_unique);
public function remove()
$this->migrate->dropIndex($this->formIndexName(), $this->_table);
public function getName()
return $this->_name;