使用 CakePHP,我有两个快照。我正在寻找两者的差异,然后使用该差异生成一个非破坏性的 MySQL 更新命令。
这是我到目前为止所拥有的,它返回一个 alter table MySQL 命令,但是,这将不起作用,因为我需要先创建所述表。
$this->Schema = new CakeSchema();
$db = ConnectionManager::getDataSource($this->Schema->connection);
$options = array();
$Old = $this->Schema->read($options);
$Schema = $this->Schema->load();
$compare = $this->Schema->compare($Old, $Schema);
$contents = array();
if (empty($table)) {
foreach ($compare as $table => $changes) {
$update = $db->alterSchema(array($table => $changes), $table);
}
}
$this->Installer->query($update);