function Schema::addUniqueKey
Add a unique key.
Parameters
string $table: The table to be altered.
string $name: The name of the key.
array $fields: An array of field names.
Overrides Schema::addUniqueKey
1 call to Schema::addUniqueKey()
- Schema::_createKeys in core/modules/ pgsql/ src/ Driver/ Database/ pgsql/ Schema.php 
- Adds keys for an SQL table.
File
- 
              core/modules/ pgsql/ src/ Driver/ Database/ pgsql/ Schema.php, line 815 
Class
- Schema
- PostgreSQL implementation of \Drupal\Core\Database\Schema.
Namespace
Drupal\pgsql\Driver\Database\pgsqlCode
public function addUniqueKey($table, $name, $fields) {
  if (!$this->tableExists($table)) {
    throw new SchemaObjectDoesNotExistException("Cannot add unique key '{$name}' to table '{$table}': table doesn't exist.");
  }
  if ($this->constraintExists($table, $name . '__key')) {
    throw new SchemaObjectExistsException("Cannot add unique key '{$name}' to table '{$table}': unique key already exists.");
  }
  // Use the createPrimaryKeySql(), which already discards any prefix lengths
  // passed as part of the key column specifiers. (Postgres doesn't support
  // setting a prefix length for PRIMARY or UNIQUE indices.)
  $this->executeDdlStatement('ALTER TABLE {' . $table . '} ADD CONSTRAINT ' . $this->ensureIdentifiersLength($table, $name, 'key') . ' UNIQUE (' . $this->createPrimaryKeySql($fields) . ')');
  $this->resetTableInformation($table);
}Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.
