You are here

protected function Schema::cleanUpTechnicalPrimaryColumn in Drupal driver for SQL Server and SQL Azure 3.0.x

Same name and namespace in other branches
  1. 8.2 drivers/lib/Drupal/Driver/Database/sqlsrv/Schema.php \Drupal\Driver\Database\sqlsrv\Schema::cleanUpTechnicalPrimaryColumn()
  2. 8 drivers/lib/Drupal/Driver/Database/sqlsrv/Schema.php \Drupal\Driver\Database\sqlsrv\Schema::cleanUpTechnicalPrimaryColumn()

Tries to clean up the technical primary column.

It will be deleted if: (a) It is not being used as the current primary key and... (b) There is no unique constraint because they depend on this column (see addUniqueKey())

Parameters

string $table: Table name.

3 calls to Schema::cleanUpTechnicalPrimaryColumn()
Schema::addPrimaryKey in drivers/lib/Drupal/Driver/Database/sqlsrv/Schema.php
Add a primary key.
Schema::cleanUpPrimaryKey in drivers/lib/Drupal/Driver/Database/sqlsrv/Schema.php
Drop the primary key constraint.
Schema::dropUniqueKey in drivers/lib/Drupal/Driver/Database/sqlsrv/Schema.php
Drop a unique key.

File

drivers/lib/Drupal/Driver/Database/sqlsrv/Schema.php, line 1949

Class

Schema

Namespace

Drupal\Driver\Database\sqlsrv

Code

protected function cleanUpTechnicalPrimaryColumn($table) {

  // Get the number of remaining unique indexes on the table, that
  // are not primary keys and prune the technical primary column if possible.
  $prefixInfo = $this
    ->getPrefixInfo($table, TRUE);
  $sql = 'SELECT COUNT(*) FROM sys.indexes WHERE object_id = OBJECT_ID(:table) AND is_unique = 1 AND is_primary_key = 0';
  $args = [
    ':table' => $prefixInfo['table'],
  ];
  $unique_indexes = $this->connection
    ->query($sql, $args)
    ->fetchField();
  $primary_key_is_technical = $this
    ->isTechnicalPrimaryKey($this
    ->primaryKeyName($table));
  if (!$unique_indexes && !$primary_key_is_technical) {
    $this
      ->dropField($table, self::TECHNICAL_PK_COLUMN_NAME);
  }
}