Drop support for unique keys specified as an array of column name and length (breaks PG installation)

Created on 2 June 2014, about 10 years ago
Updated 18 July 2023, 12 months ago

Problem/Motivation

Per our Schema API documentation, each column of a unique key of a table schema can be specified either as a column name or as an array of column name and length:

* - 'unique keys': An associative array of unique keys ('keyname' =>
* specification). Each specification is an array of one or more
* key column specifiers (see below) that form a unique key on the table.

* A key column specifier is either a string naming a column or an
* array of two elements, column name and length, specifying a prefix
* of the named column.

The PostreSQL database backend does not support the latter case. The relevant code is in lines 135 to 139 of \Drupal\Core\Database\Driver\pqsql\Schema::createTableSql():

    if (isset($table['unique keys']) && is_array($table['unique keys'])) {
      foreach ($table['unique keys'] as $key_name => $key) {
        $sql_keys[] = 'CONSTRAINT ' . $this->prefixNonTable($name, $key_name, 'key') . ' UNIQUE (' . implode(', ', $key) . ')';
      }
    }

The $key variable in the foreach can be (per the API documentation) for example array(array('foo', 123)) in which case the implode() fails. The resulting string will then be Array and the resulting SQL will fail hard.

Proposed resolution

Remaining tasks

User interface changes

API changes

📌 Task
Status

Active

Version

11.0 🔥

Component
PostgreSQL driver  →

Last updated 6 days ago

No maintainer
Created by

🇩🇪Germany tstoeckler Essen, Germany

Live updates comments and jobs are added and updated live.
  • PostgreSQL

    Particularly affects sites running on the PostgreSQL database.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024