Skip to content
Snippets Groups Projects
Verified Commit 7eb3267b authored by Dave Long's avatar Dave Long
Browse files

Issue #3399160 by mfb, smustgrave, bradjones1, Ghost of Drupal Past: Support MySQL GIPK mode

(cherry picked from commit 6a0d80e4)
parent cb6d0184
No related branches found
No related tags found
15 merge requests!8376Drupal views: adding more granularity to the ‘use ajax’ functionality,!8300Issue #3443586 View area displays even when parent view has no results.,!7567Issue #3153723 by quietone, Hardik_Patel_12: Change the scaffolding...,!7565Issue #3153723 by quietone, Hardik_Patel_12: Change the scaffolding...,!7509Change label "Block description" to "Block type",!7344Issue #3292350 by O'Briat, KlemenDEV, hswong3i, smustgrave, quietone: Update...,!6922Issue #3412959 by quietone, smustgrave, longwave: Fix 12 'un' words,!6848Issue #3417553 by longwave: Remove withConsecutive() in CacheCollectorTest,!6720Revert "Issue #3358581 by pfrenssen, _tarik_, a.dmitriiev, smustgrave:...,!6560Update ClaroPreRender.php, confirming classes provided are in array format,!6528Issue #3414261 by catch: Add authenticated user umami performance tests,!6501Issue #3263668 by omkar-pd, Wim Leers, hooroomoo: Re-enable inline form errors...,!6354Draft: Issue #3380392 by phma: Updating language weight from the overview reverts label if translated,!6324Issue #3416723 by Ludo.R: Provide a "node type" views default argument,!6119Issue #3405704 by Spokje, longwave: symfony/psr-http-message-bridge major version bump
Pipeline #70606 passed
Pipeline: drupal

#70620

    Pipeline: drupal

    #70617

      Pipeline: drupal

      #70614

        +1
        ...@@ -2,12 +2,15 @@ ...@@ -2,12 +2,15 @@
        namespace Drupal\mysql\Driver\Database\mysql; namespace Drupal\mysql\Driver\Database\mysql;
        use Drupal\Core\Database\DatabaseExceptionWrapper;
        use Drupal\Core\Database\SchemaException; use Drupal\Core\Database\SchemaException;
        use Drupal\Core\Database\SchemaObjectExistsException; use Drupal\Core\Database\SchemaObjectExistsException;
        use Drupal\Core\Database\SchemaObjectDoesNotExistException; use Drupal\Core\Database\SchemaObjectDoesNotExistException;
        use Drupal\Core\Database\Schema as DatabaseSchema; use Drupal\Core\Database\Schema as DatabaseSchema;
        use Drupal\Component\Utility\Unicode; use Drupal\Component\Utility\Unicode;
        // cspell:ignore gipk
        /** /**
        * @addtogroup schemaapi * @addtogroup schemaapi
        * @{ * @{
        ...@@ -426,7 +429,21 @@ public function addField($table, $field, $spec, $keys_new = []) { ...@@ -426,7 +429,21 @@ public function addField($table, $field, $spec, $keys_new = []) {
        $query .= ', ADD ' . implode(', ADD ', $keys_sql); $query .= ', ADD ' . implode(', ADD ', $keys_sql);
        } }
        $this->connection->query($query); try {
        $this->connection->query($query);
        }
        catch (DatabaseExceptionWrapper $e) {
        // MySQL error number 4111 (ER_DROP_PK_COLUMN_TO_DROP_GIPK) indicates that
        // when dropping and adding a primary key, the generated invisible primary
        // key (GIPK) column must also be dropped.
        if (isset($e->getPrevious()->errorInfo[1]) && $e->getPrevious()->errorInfo[1] === 4111 && isset($keys_new['primary key']) && $this->indexExists($table, 'PRIMARY') && $this->findPrimaryKeyColumns($table) === ['my_row_id']) {
        $this->connection->query($query . ', DROP COLUMN [my_row_id]');
        }
        else {
        throw $e;
        }
        }
        if (isset($spec['initial_from_field'])) { if (isset($spec['initial_from_field'])) {
        if (isset($spec['initial'])) { if (isset($spec['initial'])) {
        $expression = 'COALESCE(' . $spec['initial_from_field'] . ', :default_initial_value)'; $expression = 'COALESCE(' . $spec['initial_from_field'] . ', :default_initial_value)';
        ......
        ...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
        namespace Drupal\Tests\mysql\Kernel\mysql; namespace Drupal\Tests\mysql\Kernel\mysql;
        use Drupal\Component\Utility\Unicode; use Drupal\Component\Utility\Unicode;
        use Drupal\Core\Database\DatabaseExceptionWrapper;
        use Drupal\Core\Database\Exception\SchemaTableColumnSizeTooLargeException; use Drupal\Core\Database\Exception\SchemaTableColumnSizeTooLargeException;
        use Drupal\Core\Database\Exception\SchemaTableKeyTooLargeException; use Drupal\Core\Database\Exception\SchemaTableKeyTooLargeException;
        use Drupal\Core\Database\SchemaException; use Drupal\Core\Database\SchemaException;
        ...@@ -311,4 +312,32 @@ public function testSchemaTableColumnSizeTooLargeException(): void { ...@@ -311,4 +312,32 @@ public function testSchemaTableColumnSizeTooLargeException(): void {
        ]); ]);
        } }
        /**
        * Tests adding a primary key when sql_generate_invisible_primary_key is on.
        */
        public function testGeneratedInvisiblePrimaryKey(): void {
        $is_maria = method_exists($this->connection, 'isMariaDb') && $this->connection->isMariaDb();
        if ($this->connection->databaseType() !== 'mysql' || $is_maria || version_compare($this->connection->version(), '8.0.30', '<')) {
        $this->markTestSkipped('This test only runs on MySQL 8.0.30 and above');
        }
        try {
        $this->connection->query("SET sql_generate_invisible_primary_key = 1;")->execute();
        }
        catch (DatabaseExceptionWrapper $e) {
        $this->markTestSkipped('This test requires the SESSION_VARIABLES_ADMIN privilege.');
        }
        $this->schema->createTable('test_primary_key', [
        'fields' => [
        'foo' => [
        'type' => 'varchar',
        'length' => 1,
        ],
        ],
        ]);
        $this->schema->addField('test_primary_key', 'id', [
        'type' => 'serial',
        'not null' => TRUE,
        ], ['primary key' => ['id']]);
        }
        } }
        0% Loading or .
        You are about to add 0 people to the discussion. Proceed with caution.
        Finish editing this message first!
        Please register or to comment