public function addColumn($options)
{
extract($options);
if (!isset($table) || !isset($column)) {
return false;
}
if (!isset($column['name'])) {
if (isset($field)) {
$column['name'] = $field;
} else {
return false;
}
}
$old = $this->readSchema($table);
if (isset($old['tables'][$table][$field])) {
return false;
}
$new = $old;
// 配列の順番を考慮して新しいフィールドを追加しないと、$CakeSchema->compare() で、
// 間違った構成の情報を取得してしまう。(tableParametersをフィールドとして解析してしまう)
$fields = array();
foreach ($new['tables'][$table] as $key => $value) {
if ($key !== 'indexes' && $key !== 'tableParameters') {
$fields[$key] = $value;
}
}
$fields[$field] = $column;
if (!empty($new['tables'][$table]['indexes'])) {
$fields['indexes'] = $new['tables'][$table]['indexes'];
}
if (isset($new['tables'][$table]['tableParameters'])) {
$fields['tableParameters'] = $new['tables'][$table]['tableParameters'];
}
$new['tables'][$table] = $fields;
$CakeSchema = ClassRegistry::init('CakeSchema');
$CakeSchema->connection = $this->configKeyName;
$compare = $CakeSchema->compare($old, $new);
$sql = $this->alterSchema($compare);
return $this->execute($sql);
}