Unify datetime column default values between MySQL and Postgres.

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

Fixes #3837
This commit is contained in:
mark_story 2014-07-11 23:10:16 -04:00
parent a098d96c94
commit 03c2a8b722
2 changed files with 51 additions and 2 deletions

View file

@ -261,6 +261,9 @@ class Postgres extends DboSource {
$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']);
}

View file

@ -162,8 +162,8 @@ class PostgresClientTestModel extends Model {
'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 @@ class PostgresTest extends CakeTestCase {
'connection' => 'test',
'models' => array('DatatypeTest')
));
$schema->tables = array(
'datatype_tests' => $result['tables']['missing']['datatype_tests']
);
@ -1098,4 +1099,49 @@ class PostgresTest extends CakeTestCase {
$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);
}
}