Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Adding missing & operators.

Adding tests for run update.
Adding -f param to schema run update to allow for testing and forcing of table comparison.  Skips model checks and uses tables only instead.
  • Loading branch information...
commit a7499be154143271b3fcb91ef276fcdd6f889832 1 parent dc4cfc5
@markstory markstory authored
View
12 cake/console/libs/schema.php
@@ -287,7 +287,7 @@ function run() {
*
* @access private
*/
- function __create($Schema, $table = null) {
+ function __create(&$Schema, $table = null) {
$db =& ConnectionManager::getDataSource($this->Schema->connection);
$drop = $create = array();
@@ -331,11 +331,15 @@ function __create($Schema, $table = null) {
*
* @access private
*/
- function __update($Schema, $table = null) {
+ function __update(&$Schema, $table = null) {
$db =& ConnectionManager::getDataSource($this->Schema->connection);
$this->out(__('Comparing Database to Schema...', true));
- $Old = $this->Schema->read();
+ $options = array();
+ if (isset($this->params['f'])) {
+ $options['models'] = false;
+ }
+ $Old = $this->Schema->read($options);
$compare = $this->Schema->compare($Old, $Schema);
$contents = array();
@@ -369,7 +373,7 @@ function __update($Schema, $table = null) {
*
* @access private
*/
- function __run($contents, $event, $Schema) {
+ function __run($contents, $event, &$Schema) {
if (empty($contents)) {
$this->err(__('Sql could not be run', true));
return;
View
1  cake/libs/model/cake_schema.php
@@ -186,6 +186,7 @@ function load($options = array()) {
* - 'connection' - the db connection to use
* - 'name' - name of the schema
* - 'models' - a list of models to use, or false to ignore models
+ *
* @param array $options schema object properties
* @return array Array indexed by name and tables
* @access public
View
85 cake/tests/cases/console/libs/schema.test.php
@@ -48,6 +48,67 @@
Mock::generate('CakeSchema', 'MockSchemaCakeSchema');
/**
+ * Test for Schema database management
+ *
+ * @package cake
+ * @subpackage cake.tests.cases.libs
+ */
+class SchemaShellTestSchema extends CakeSchema {
+
+/**
+ * name property
+ *
+ * @var string 'MyApp'
+ * @access public
+ */
+ var $name = 'SchemaShellTest';
+
+/**
+ * connection property
+ *
+ * @var string 'test_suite'
+ * @access public
+ */
+ var $connection = 'test_suite';
+
+/**
+ * comments property
+ *
+ * @var array
+ * @access public
+ */
+ var $comments = array(
+ 'id' => array('type' => 'integer', 'null' => false, 'default' => 0, 'key' => 'primary'),
+ 'post_id' => array('type' => 'integer', 'null' => false, 'default' => 0),
+ 'user_id' => array('type' => 'integer', 'null' => false),
+ 'title' => array('type' => 'string', 'null' => false, 'length' => 100),
+ 'comment' => array('type' => 'text', 'null' => false, 'default' => null),
+ 'published' => array('type' => 'string', 'null' => true, 'default' => 'N', 'length' => 1),
+ 'created' => array('type' => 'datetime', 'null' => true, 'default' => null),
+ 'updated' => array('type' => 'datetime', 'null' => true, 'default' => null),
+ 'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => true)),
+ );
+
+/**
+ * posts property
+ *
+ * @var array
+ * @access public
+ */
+ var $articles = array(
+ 'id' => array('type' => 'integer', 'null' => false, 'default' => 0, 'key' => 'primary'),
+ 'user_id' => array('type' => 'integer', 'null' => true, 'default' => ''),
+ 'title' => array('type' => 'string', 'null' => false, 'default' => 'Title'),
+ 'body' => array('type' => 'text', 'null' => true, 'default' => null),
+ 'summary' => array('type' => 'text', 'null' => true),
+ 'published' => array('type' => 'string', 'null' => true, 'default' => 'Y', 'length' => 1),
+ 'created' => array('type' => 'datetime', 'null' => true, 'default' => null),
+ 'updated' => array('type' => 'datetime', 'null' => true, 'default' => null),
+ 'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => true)),
+ );
+}
+
+/**
* SchemaShellTest class
*
* @package cake
@@ -279,5 +340,29 @@ function testRunCreateWithTableArgs() {
$this->assertFalse(in_array('aros_acos', $sources));
}
+/**
+ * test run update with a table arg.
+ *
+ * @return void
+ **/
+ function testRunUpdateWithTable() {
+ $this->Shell->params = array(
+ 'name' => 'SchemaShellTest',
+ 'connection' => 'test_suite',
+ 'f' => true
+ );
+ $this->Shell->args = array('update', 'articles');
+ $this->Shell->startup();
+ $this->Shell->setReturnValue('in', 'y');
+ $this->Shell->run();
+
+ $article =& new Model(array('name' => 'Article', 'ds' => 'test_suite'));
+ $fields = $article->schema();
+ $this->assertTrue(isset($fields['summary']));
+
+ $this->_fixtures['core.article']->drop($this->db);
+ $this->_fixtures['core.article']->create($this->db);
+ }
+
}
?>
Please sign in to comment.
Something went wrong with that request. Please try again.