function SchemaTest::testGeneratedInvisiblePrimaryKey
Same name in other branches
- 11.x core/modules/mysql/tests/src/Kernel/mysql/SchemaTest.php \Drupal\Tests\mysql\Kernel\mysql\SchemaTest::testGeneratedInvisiblePrimaryKey()
Tests adding a primary key when sql_generate_invisible_primary_key is on.
File
-
core/
modules/ mysql/ tests/ src/ Kernel/ mysql/ SchemaTest.php, line 320
Class
- SchemaTest
- Tests schema API for the MySQL driver.
Namespace
Drupal\Tests\mysql\Kernel\mysqlCode
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',
],
]);
$this->assertTrue($this->schema
->fieldExists('test_primary_key', 'id'));
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.