Skip to content

Commit

Permalink
Add test for default function value in postgres
Browse files Browse the repository at this point in the history
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 ba1ddb3
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions tests/TestCase/Database/Schema/PostgresSchemaTest.php
Expand Up @@ -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
*
Expand Down

0 comments on commit ba1ddb3

Please sign in to comment.