/** * Check if table of migrations is ready * * @return void * @access private */ function __checkTable() { $describe = $this->db->describe($this->_schemaTable); if (array_keys($describe) == array_keys($this->_schemaStructure)) { // Chaves iguais $ok = true; foreach ($this->_schemaStructure as $key => $structure) { if ($structure['type'] != $describe[$key]['type']) { $ok = false; break; } } if ($ok) { return; } } $fakeSchema = new CakeSchema(); $fakeSchema->tables = array($this->_schemaTable => ''); $this->db->execute($this->db->dropSchema($fakeSchema, $this->_schemaTable)); $this->__createTable(); }
/** * Change column * * @param string $tableName * @param string $columnName * @param array $newColumnConfig * @param boolean $verbose * @return boolean * @access public */ function changeColumn($tableName, $columnName, $newColumnConfig = array(), $verbose = true) { if ($this->stopOnError && $this->__error) { return false; } $verbose && $this->out('> ' . String::insert(__d('migrations', 'Changing column ":column"... ', true), array('column' => $columnName)), false); if ($this->_db->isInterfaceSupported('describe')) { $describe = $this->_db->describe($tableName, true); if (!isset($describe[$columnName])) { $verbose && $this->out(__d('migrations', 'column not found.', true)); $this->__error = true; return false; } $newColumnConfig = array_merge($describe[$columnName], $newColumnConfig); } if ($this->_db->execute($this->_db->alterSchema(array($tableName => array('change' => array($columnName => $newColumnConfig))), $tableName))) { $verbose && $this->out('ok'); return true; } $verbose && $this->out('nok'); $this->__error = true; return false; }
/** * testDescribe method * * @access public * @return void */ function testDescribe() { $MssqlTableDescription = array(0 => array(0 => array('Default' => '((0))', 'Field' => 'count', 'Key' => 0, 'Length' => '4', 'Null' => 'NO', 'Type' => 'integer'))); $this->db->fetchAllResultsStack = array($MssqlTableDescription); $dummyModel = $this->model; $result = $this->db->describe($dummyModel); $expected = array('count' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => 4)); $this->assertEqual($result, $expected); }