alterColumn() public method

Builds and executes a SQL statement for changing the definition of a column.
public alterColumn ( string $table, string $column, string $type )
$table string the table whose column is to be changed. The table name will be properly quoted by the method.
$column string the name of the column to be changed. The name will be properly quoted by the method.
$type string the new column type. The [[QueryBuilder::getColumnType()]] method will be invoked to convert abstract column type (if any) into the physical one. Anything that is not recognized as abstract type will be kept in the generated SQL. For example, 'string' will be turned into 'varchar(255)', while 'string not null' will become 'varchar(255) not null'.
Exemplo n.º 1
0
 /**
  * @inheritdoc
  * Note: table will be auto pefixied if [[$autoWrapTableNames]] is true.
  */
 public function alterColumn($table, $column, $type)
 {
     $table = $this->autoWrappedTableName($table);
     return parent::alterColumn($table, $column, $type);
 }
Exemplo n.º 2
0
 /**
  * @inheritdoc
  */
 public function alterColumn($table, $column, $type)
 {
     if ($type instanceof ForeignKeyColumn) {
         $type->migrate = $this;
         $type->sourceTable($table);
         $type->sourceColumn($column);
         $type->apply();
     } else {
         return parent::alterColumn($table, $column, $type);
     }
 }
Exemplo n.º 3
-1
 /**
  * @param bool $insert
  * @param array $changedAttributes
  * @return bool
  */
 public function afterSave($insert, $changedAttributes)
 {
     parent::afterSave($insert, $changedAttributes);
     if (!in_array($this->scenario, ['update', 'create'])) {
         return true;
     }
     $cm = $this->cm;
     $mg = new Migration();
     $table = Cm::$TAB_PREFIX[$cm->tab_index] . $cm->tab;
     $column = null;
     $type = $this->data_type;
     switch ($type) {
         case 'integer':
         case 'smallInteger':
         case 'boolean':
         case 'float':
         case 'double':
             $column = $mg->{$type}()->notNull()->defaultValue(0);
             break;
         case 'string':
             $column = $mg->{$type}($this->length)->notNull()->defaultValue('');
             break;
         case 'decimal':
             $column = $mg->{$type}($this->length)->notNull()->defaultValue(0);
             break;
         default:
             $column = $mg->{$type}()->defaultValue(null);
             break;
     }
     $column .= " COMMENT '" . $this->label . "'";
     if ($insert) {
         $mg->addColumn('{{%' . $table . '}}', $this->name, $column);
     } else {
         $oldName = $this->old_name;
         $newname = $this->name;
         if ($oldName !== $newname) {
             $mg->renameColumn('{{%' . $table . '}}', $oldName, $newname);
         }
         $mg->alterColumn('{{%' . $table . '}}', $newname, $column);
     }
     return true;
 }