function SchemaTest::checkSequenceRenaming
Same name in other branches
- 11.x core/modules/pgsql/tests/src/Kernel/pgsql/SchemaTest.php \Drupal\Tests\pgsql\Kernel\pgsql\SchemaTest::checkSequenceRenaming()
Overrides DriverSpecificSchemaTestBase::checkSequenceRenaming
File
-
core/
modules/ pgsql/ tests/ src/ Kernel/ pgsql/ SchemaTest.php, line 29
Class
- SchemaTest
- Tests schema API for the PostgreSQL driver.
Namespace
Drupal\Tests\pgsql\Kernel\pgsqlCode
protected function checkSequenceRenaming(string $tableName) : void {
// For PostgreSQL, we also need to check that the sequence has been renamed.
// The initial name of the sequence has been generated automatically by
// PostgreSQL when the table was created, however, on subsequent table
// renames the name is generated by Drupal and can not be easily
// re-constructed. Hence we can only check that we still have a sequence on
// the new table name.
$sequenceExists = (bool) $this->connection
->query("SELECT pg_get_serial_sequence('{" . $tableName . "}', 'id')")
->fetchField();
$this->assertTrue($sequenceExists, 'Sequence was renamed.');
// Rename the table again and repeat the check.
$anotherTableName = strtolower($this->getRandomGenerator()
->name(63 - strlen($this->getDatabasePrefix())));
$this->schema
->renameTable($tableName, $anotherTableName);
$sequenceExists = (bool) $this->connection
->query("SELECT pg_get_serial_sequence('{" . $anotherTableName . "}', 'id')")
->fetchField();
$this->assertTrue($sequenceExists, 'Sequence was renamed.');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.