Unverified Commit c4923ea2 authored by alexpott's avatar alexpott

Issue #2976493 by tstoeckler, daffie: Creating a table with an explicitly...

Issue #2976493 by tstoeckler, daffie: Creating a table with an explicitly empty primary key is broken on PostgreSQL
parent 0cc5879a
......@@ -249,7 +249,7 @@ protected function createTableSql($name, $table) {
}
$sql_keys = [];
if (isset($table['primary key']) && is_array($table['primary key'])) {
if (!empty($table['primary key']) && is_array($table['primary key'])) {
$sql_keys[] = 'CONSTRAINT ' . $this->ensureIdentifiersLength($name, '', 'pkey') . ' PRIMARY KEY (' . $this->createPrimaryKeySql($table['primary key']) . ')';
}
if (isset($table['unique keys']) && is_array($table['unique keys'])) {
......
......@@ -1009,7 +1009,7 @@ public function testFindPrimaryKeyColumns() {
$this->assertSame(['id3', 'test_field_2', 'id4'], $method->invoke($schema, 'table_with_pk_3'));
// Test with table without a primary key.
$schema->createTable('table_without_pk', [
$schema->createTable('table_without_pk_1', [
'description' => 'Table without primary key.',
'fields' => [
'id' => [
......@@ -1022,7 +1022,24 @@ public function testFindPrimaryKeyColumns() {
],
],
]);
$this->assertSame([], $method->invoke($schema, 'table_without_pk'));
$this->assertSame([], $method->invoke($schema, 'table_without_pk_1'));
// Test with table with an empty primary key.
$schema->createTable('table_without_pk_2', [
'description' => 'Table without primary key.',
'fields' => [
'id' => [
'type' => 'int',
'not null' => TRUE,
],
'test_field' => [
'type' => 'int',
'not null' => TRUE,
],
],
'primary key' => [],
]);
$this->assertSame([], $method->invoke($schema, 'table_without_pk_2'));
// Test with non existing table.
$this->assertFalse($method->invoke($schema, 'non_existing_table'));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment