diff --git a/lib/Cake/Model/Datasource/Database/Postgres.php b/lib/Cake/Model/Datasource/Database/Postgres.php index aa55b7662..a9225349d 100644 --- a/lib/Cake/Model/Datasource/Database/Postgres.php +++ b/lib/Cake/Model/Datasource/Database/Postgres.php @@ -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']); } diff --git a/lib/Cake/Test/Case/Model/Datasource/Database/PostgresTest.php b/lib/Cake/Test/Case/Model/Datasource/Database/PostgresTest.php index 2cbca6eb5..0c4de769e 100644 --- a/lib/Cake/Test/Case/Model/Datasource/Database/PostgresTest.php +++ b/lib/Cake/Test/Case/Model/Datasource/Database/PostgresTest.php @@ -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); + } + }