Skip to content
Permalink
Browse files

Add test for default function value in postgres

Ensure that default values using functions don't have corrupted default
value expressions.
  • Loading branch information...
markstory committed Oct 20, 2018
1 parent 1023bfd commit ba1ddb3f360ac4470deedc5490128c9702a8fbc3
Showing with 34 additions and 0 deletions.
  1. +34 −0 tests/TestCase/Database/Schema/PostgresSchemaTest.php
@@ -637,6 +637,40 @@ public function testDescribeTableIndexesNullsFirst()
$connection->execute('DROP TABLE schema_index');
}
/**
* Test describing a table with postgres function defaults
*
* @return void
*/
public function testDescribeTableFunctionDefaultValue()
{
$this->_needsConnection();
$connection = ConnectionManager::get('test');
$sql = <<<SQL
CREATE TABLE schema_function_defaults (
"id" SERIAL,
year INT DEFAULT DATE_PART('year'::text, NOW()),
PRIMARY KEY("id")
);
SQL;
$connection->execute($sql);
$schema = new SchemaCollection($connection);
$result = $schema->describe('schema_function_defaults');
$connection->execute('DROP TABLE schema_function_defaults');
$expected = [
'type' => 'integer',
'default' => "date_part('year'::text, now())",
'null' => true,
'precision' => null,
'length' => 10,
'comment' => null,
'unsigned' => null,
'autoIncrement' => null,
];
$this->assertEquals($expected, $result->getColumn('year'));
}
/**
* Column provider for creating column sql
*

0 comments on commit ba1ddb3

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