Skip to content
Permalink
Browse files

Unify datetime column default values between MySQL and Postgres.

Datetime columns should have 'default' => null, in both Postgres and
MySQL.

Fixes #3837
  • Loading branch information...
markstory committed Jul 12, 2014
1 parent a098d96 commit 03c2a8b72230c1cfb976cb9ef00eedd1744408f0
@@ -261,6 +261,9 @@ public function describe($model) {
$this->_sequenceMap[$table][$c->name] = $sequenceName;
}
}
if ($fields[$c->name]['type'] === 'timestamp' && $fields[$c->name]['default'] === '') {
$fields[$c->name]['default'] = null;
}
if ($fields[$c->name]['type'] === 'boolean' && !empty($fields[$c->name]['default'])) {
$fields[$c->name]['default'] = constant($fields[$c->name]['default']);
}
@@ -162,8 +162,8 @@ public function schema($field = false) {
'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8', 'key' => 'primary'),
'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
'email' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'),
'created' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => ''),
'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null)
'created' => array('type' => 'datetime', 'null' => true, 'default' => null, 'length' => ''),
'updated' => array('type' => 'datetime', 'null' => true, 'default' => null, 'length' => null)
);
}
@@ -551,6 +551,7 @@ public function testCakeSchema() {
'connection' => 'test',
'models' => array('DatatypeTest')
));
$schema->tables = array(
'datatype_tests' => $result['tables']['missing']['datatype_tests']
);
@@ -1098,4 +1099,49 @@ public function testLimit() {
$this->assertNotContains($scientificNotation, $result);
}
/**
* Test describe() behavior for timestamp columns.
*
* @return void
*/
public function testDescribeTimestamp() {
$this->loadFixtures('User');
$model = ClassRegistry::init('User');
$result = $this->Dbo->describe($model);
$expected = array(
'id' => array(
'type' => 'integer',
'null' => false,
'default' => null,
'length' => 11,
'key' => 'primary'
),
'user' => array(
'type' => 'string',
'null' => true,
'default' => null,
'length' => 255
),
'password' => array(
'type' => 'string',
'null' => true,
'default' => null,
'length' => 255
),
'created' => array(
'type' => 'datetime',
'null' => true,
'default' => null,
'length' => null
),
'updated' => array(
'type' => 'datetime',
'null' => true,
'default' => null,
'length' => null
)
);
$this->assertEquals($expected, $result);
}
}

0 comments on commit 03c2a8b

Please sign in to comment.
You can’t perform that action at this time.