src/Charcoal/Admin/Script/Object/Table/AlterPrimaryKeyScript.php
private function insertNewField(PropertyField $field, IdProperty $prop)
    {
        unset($prop);

        $model  = $this->targetModel();
        $source = $model->source();

        $extra = $field->extra();
        $field->setExtra('');

        // Don't alter table if column name already exists.
        $sql = strtr(
            'SHOW COLUMNS FROM `%table` LIKE "%key"',
            [
                '%table' => $source->table(),
                '%key'   => $field->ident(),
            ]
        );

        $res = $source->db()->query($sql);

        if ($res->fetch(1)) {
            // Column name already exists.
            return $this;
        }

        $sql = strtr(
            'ALTER TABLE `%table` ADD COLUMN %field FIRST',
            [
                '%table' => $source->table(),
                '%field' => $field->sql(),
            ]
        );
        $field->setExtra($extra);

        $source->db()->query($sql);

        return $this;
    }
private function insertNewField(PropertyField $field, IdProperty $prop)
    {
        unset($prop);

        $model  = $this->targetModel();
        $source = $model->source();

        $extra = $field->extra();
        $field->setExtra('');

        // Don't alter table if column name already exists.
        $sql = strtr(
            'SHOW COLUMNS FROM `%table` LIKE "%key"',
            [
                '%table' => $source->table(),
                '%key'   => $field->ident(),
            ]
        );

        $res = $source->db()->query($sql);

        if ($res->fetch(1)) {
            // Column name already exists.
            return $this;
        }

        $sql = strtr(
            'ALTER TABLE `%table` ADD COLUMN %field FIRST',
            [
                '%table' => $source->table(),
                '%field' => $field->sql(),
            ]
        );
        $field->setExtra($extra);

        $source->db()->query($sql);

        return $this;
    }
private function insertNewField ( PropertyField $ field , IdProperty $ prop ) { unset ( $ prop ) ; $ model = $ this -> targetModel ( ) ; $ source = $ model -> source ( ) ; $ extra = $ field -> extra ( ) ; $ field -> setExtra ( '' ) ; // Don't alter table if column name already exists. $ sql = strtr ( 'SHOW COLUMNS FROM `%table` LIKE "%key"' , [ '%table' => $ source -> table ( ) , '%key' => $ field -> ident ( ) , ] ) ; $ res = $ source -> db ( ) -> query ( $ sql ) ; if ( $ res -> fetch ( 1 ) ) { // Column name already exists. return $ this ; } $ sql = strtr ( 'ALTER TABLE `%table` ADD COLUMN %field FIRST' , [ '%table' => $ source -> table ( ) , '%field' => $ field -> sql ( ) , ] ) ; $ field -> setExtra ( $ extra ) ; $ source -> db ( ) -> query ( $ sql ) ; return $ this ; }
Insert the given field.

@param  PropertyField $field The new ID field.
@param  IdProperty    $prop  The new ID property.
@return self
Insert the given field .