src/Charcoal/Admin/Script/Object/Table/AlterPrimaryKeyScript.php
private function dropPrimaryKey(PropertyField $field, IdProperty $prop)
    {
        $keepId = $this->climate()->arguments->defined('keep_id');
        $model  = $this->targetModel();
        $source = $model->source();
        $dbh    = $source->db();
        $key    = $prop->ident();

        if ($keepId) {
            $field->setIdent(sprintf('%1$s_%2$s', $key, date('YmdHis')));
            $sql = strtr(
                'ALTER TABLE `%table` CHANGE COLUMN `%key` %field, DROP PRIMARY KEY',
                [
                    '%table' => $source->table(),
                    '%field' => $field->sql(),
                    '%key'   => $key,
                ]
            );
        } else {
            $sql = strtr(
                'ALTER TABLE `%table` MODIFY COLUMN %field, DROP PRIMARY KEY',
                [
                    '%table' => $source->table(),
                    '%field' => $field->sql(),
                ]
            );
        }

        $dbh->query($sql);

        return $this;
    }
private function dropPrimaryKey(PropertyField $field, IdProperty $prop)
    {
        $keepId = $this->climate()->arguments->defined('keep_id');
        $model  = $this->targetModel();
        $source = $model->source();
        $dbh    = $source->db();
        $key    = $prop->ident();

        if ($keepId) {
            $field->setIdent(sprintf('%1$s_%2$s', $key, date('YmdHis')));
            $sql = strtr(
                'ALTER TABLE `%table` CHANGE COLUMN `%key` %field, DROP PRIMARY KEY',
                [
                    '%table' => $source->table(),
                    '%field' => $field->sql(),
                    '%key'   => $key,
                ]
            );
        } else {
            $sql = strtr(
                'ALTER TABLE `%table` MODIFY COLUMN %field, DROP PRIMARY KEY',
                [
                    '%table' => $source->table(),
                    '%field' => $field->sql(),
                ]
            );
        }

        $dbh->query($sql);

        return $this;
    }
private function dropPrimaryKey ( PropertyField $ field , IdProperty $ prop ) { $ keepId = $ this -> climate ( ) -> arguments -> defined ( 'keep_id' ) ; $ model = $ this -> targetModel ( ) ; $ source = $ model -> source ( ) ; $ dbh = $ source -> db ( ) ; $ key = $ prop -> ident ( ) ; if ( $ keepId ) { $ field -> setIdent ( sprintf ( '%1$s_%2$s' , $ key , date ( 'YmdHis' ) ) ) ; $ sql = strtr ( 'ALTER TABLE `%table` CHANGE COLUMN `%key` %field, DROP PRIMARY KEY' , [ '%table' => $ source -> table ( ) , '%field' => $ field -> sql ( ) , '%key' => $ key , ] ) ; } else { $ sql = strtr ( 'ALTER TABLE `%table` MODIFY COLUMN %field, DROP PRIMARY KEY' , [ '%table' => $ source -> table ( ) , '%field' => $ field -> sql ( ) , ] ) ; } $ dbh -> query ( $ sql ) ; return $ this ; }
Drop the primary key from the given field.

@param  PropertyField $field The previous ID field.
@param  IdProperty    $prop  The previous ID property.
@return self
Drop the primary key from the given field .