Support MySQL GIPK mode

Created on 3 November 2023, about 1 year ago
Updated 17 August 2024, 5 months ago

Problem/Motivation

MySQL 8 has a sql_generate_invisible_primary_key (GIPK) mode which, if enabled, creates an invisible primary key for tables that do not have one. If a Drupal module later calls the addField() method to add a primary key to a table that was created in GIPK mode, the MySQL driver will need to drop the invisible column in the same statement. There is already a clause that drops any already-existing primary key, but that's not quite enough in this mode.

Steps to reproduce

  1. Use a recent version of MySQL 8
  2. Set sql_generate_invisible_primary_key=ON either globally or in the session (requires permission to do so)
  3. Run:
    Drupal::database()->schema()->createTable('deleteme', ['fields' => ['foo' => ['type' => 'int']]]);
    Drupal::database()->schema()->addField('deleteme', 'id', ['type' => 'serial', 'not null' => TRUE], ['primary key' => ['id']]); 

This should throw Drupal\Core\Database\DatabaseExceptionWrapper SQLSTATE[HY000]: General error: 4111 Please drop primary key column to be able to drop generated invisible primary key.: ALTER TABLE "deleteme" ADD "id" INT NOT NULL auto_increment, DROP PRIMARY KEY, ADD PRIMARY KEY ("id");

Proposed resolution

Perhaps addField() could catch this exception and add a clause to the statement that drops the invisible column?

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

πŸ“Œ Task
Status

Fixed

Version

10.2 ✨

Component
MySQL driverΒ  β†’

Last updated 6 days ago

Created by

πŸ‡ΊπŸ‡ΈUnited States mfb San Francisco

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024