Browse Source

Fix UUID primary key columns not being reflected properly.

When UUID columns are converted into varchar(36) they should also be
default = null, null = false.

Fixes #4695
mark_story 11 years ago
parent
commit
1877cab341

+ 1 - 0
lib/Cake/Model/Datasource/Database/Postgres.php

@@ -249,6 +249,7 @@ class Postgres extends DboSource {
 				}
 				if (
 					$fields[$c->name]['default'] === 'NULL' ||
+					$c->default === null ||
 					preg_match('/nextval\([\'"]?([\w.]+)/', $c->default, $seq)
 				) {
 					$fields[$c->name]['default'] = null;

+ 20 - 0
lib/Cake/Test/Case/Model/Datasource/Database/PostgresTest.php

@@ -1100,6 +1100,26 @@ class PostgresTest extends CakeTestCase {
 	}
 
 /**
+ * Test that postgres describes UUID columns correctly.
+ *
+ * @return void
+ */
+	public function testDescribeUuid() {
+		$db = $this->Dbo;
+		$db->execute('CREATE TABLE test_uuid_describe (id UUID PRIMARY KEY, name VARCHAR(255))');
+		$data = $db->describe('test_uuid_describe');
+
+		$expected = array(
+			'type' => 'string',
+			'null' => false,
+			'default' => null,
+			'length' => 36,
+		);
+		$this->assertSame($expected, $data['id']);
+		$db->execute('DROP TABLE test_uuid_describe');
+	}
+
+/**
  * Test describe() behavior for timestamp columns.
  *
  * @return void