addColumn() public method

Builds and executes a SQL statement for adding a new DB column.
public addColumn ( string $table, string $column, string $type )
$table string the table that the new column will be added to. The table name will be properly quoted by the method.
$column string the name of the new column. The name will be properly quoted by the method.
$type string the 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'.
コード例 #1
-1
ファイル: Migration.php プロジェクト: flexibuild/migrate
 /**
  * @inheritdoc
  * Note: table will be auto pefixied if [[$autoWrapTableNames]] is true.
  */
 public function addColumn($table, $column, $type)
 {
     $table = $this->autoWrappedTableName($table);
     return parent::addColumn($table, $column, $type);
 }
コード例 #2
-1
ファイル: Migration.php プロジェクト: ivan-chkv/yii2-boost
 /**
  * @inheritdoc
  */
 public function addColumn($table, $column, $type)
 {
     parent::addColumn($table, $column, $this->fixColumnType($type));
 }
コード例 #3
-1
ファイル: CmField.php プロジェクト: jackieit/aimocms
 /**
  * @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;
 }
コード例 #4
-1
 public function addColumn($tableName, $column, $type)
 {
     $table = Yii::$app->db->schema->getTableSchema($tableName);
     if (!isset($table->columns[$column])) {
         parent::addColumn($tableName, $column, $type);
     }
 }
コード例 #5
-1
ファイル: Migration.php プロジェクト: carono/yii2-installer
 public function addColumn($table, $column, $type)
 {
     if ($type instanceof ForeignKeyColumn) {
         parent::addColumn($table, $column, $this->integer());
         $type->migrate = $this;
         $type->sourceTable($table);
         $type->sourceColumn($column);
         $type->apply();
     } else {
         return parent::addColumn($table, $column, $type);
     }
 }
コード例 #6
-2
 /**
  * Add multiple columns to a table
  * @param string $table
  * @param array $columns ["column_name"=>type]
  */
 public function addColumns($table, $columns)
 {
     foreach ($columns as $column => $type) {
         parent::addColumn($table, $column, $type);
     }
 }