protected function Schema::constraintExists

Helper function: check if a constraint (PK, FK, UK) exists.

Parameters

$table: The name of the table.

$name: The name of the constraint (typically 'pkey' or '[constraint]_key').

4 calls to Schema::constraintExists()
Schema::addPrimaryKey in drupal/core/lib/Drupal/Core/Database/Driver/pgsql/Schema.php
Add a primary key.
Schema::addUniqueKey in drupal/core/lib/Drupal/Core/Database/Driver/pgsql/Schema.php
Add a unique key.
Schema::dropPrimaryKey in drupal/core/lib/Drupal/Core/Database/Driver/pgsql/Schema.php
Drop the primary key.
Schema::dropUniqueKey in drupal/core/lib/Drupal/Core/Database/Driver/pgsql/Schema.php
Drop a unique key.

File

drupal/core/lib/Drupal/Core/Database/Driver/pgsql/Schema.php, line 439
Definition of Drupal\Core\Database\Driver\pgsql\Schema

Class

Schema

Namespace

Drupal\Core\Database\Driver\pgsql

Code

protected function constraintExists($table, $name) {
  $constraint_name = '{' . $table . '}_' . $name;
  return (bool) $this->connection
    ->query("SELECT 1 FROM pg_constraint WHERE conname = '{$constraint_name}'")
    ->fetchField();
}