You are here

public function Schema::compressPrimaryKeyIndex in Drupal driver for SQL Server and SQL Azure 8.2

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

Sometimes the size of a table's primary key index needs to be reduced to allow for Primary XML Indexes.

Parameters

string $table:

int $limit:

2 calls to Schema::compressPrimaryKeyIndex()
Schema::addIndex in drivers/lib/Drupal/Driver/Database/sqlsrv/Schema.php
Override DatabaseSchema::addIndex().
Schema::dropIndex in drivers/lib/Drupal/Driver/Database/sqlsrv/Schema.php
Override DatabaseSchema::dropIndex().

File

drivers/lib/Drupal/Driver/Database/sqlsrv/Schema.php, line 755
Definition of Drupal\Driver\Database\sqlsrv\Schema

Class

Schema

Namespace

Drupal\Driver\Database\sqlsrv

Code

public function compressPrimaryKeyIndex($table, $limit = 900) {

  // Introspect the schema and save the current primary key if the column
  // we are modifying is part of it.
  $primary_key_fields = $this
    ->introspectPrimaryKeyFields($table);

  // SQL Server supports transactional DDL, so we can just start a transaction
  // here and pray for the best.

  /** @var Transaction $transaction */
  $transaction = $this->connection
    ->startTransaction(null, DatabaseTransactionSettings::GetDDLCompatibleDefaults());

  // Clear current Primary Key.
  $this
    ->cleanUpPrimaryKey($table);

  // Recreate the Primary Key with the given limit size.
  $this
    ->createPrimaryKey($table, $primary_key_fields, $limit);
  $transaction
    ->commit();

  // Refresh introspection for this table.
  $this
    ->getTableIntrospectionInvalidate($table);
}