interdiff impossible; taking evasive action reverted: --- b/core/lib/Drupal/Core/Database/Driver/pgsql/Connection.php +++ a/core/lib/Drupal/Core/Database/Driver/pgsql/Connection.php @@ -351,45 +351,6 @@ } } - /** - * Retrieves a sequence name that is owned by the table and column.. - * - * @param string $table - * A table name that is not prefixed or quoted. - * @param string $column - * The column name. - * - * @return string|null - * The name of the sequence or NULL if it does not exist. - */ - public function getSequence($table, $column) { - $args = [ - ':table' => $this->prefixTables('{' . $table . '}'), - ':column' => $column, - ]; - return $this - ->query("SELECT pg_get_serial_sequence(:table, :column)", $args) - ->fetchField(); - } - - /** - * Checks if a sequence exists. - * - * @param string $name - * The fully-qualified sequence name. - * - * @return bool - * TRUE if the sequence exists by the name. - * - * @see \Drupal\Core\Database\Connection::makeSequenceName() - */ - public function sequenceExists($name) { - $args = [':name' => $name]; - return (bool) $this - ->query("SELECT c.relname FROM pg_class as c WHERE c.relkind = 'S' AND c.relname = :name", $args) - ->fetchField(); - } - } /** unchanged: --- a/core/lib/Drupal/Core/Database/Driver/pgsql/Connection.php +++ b/core/lib/Drupal/Core/Database/Driver/pgsql/Connection.php @@ -9,7 +9,7 @@ use Drupal\Core\Database\StatementInterface; use Drupal\Core\Database\StatementWrapper; -// cSpell:ignore ilike nextval +// cSpell:ignore ilike nextval relname relkind relname /** * @addtogroup database @@ -368,6 +368,45 @@ public function rollbackSavepoint($savepoint_name = 'mimic_implicit_commit') { } } + /** + * Retrieves a sequence name that is owned by the table and column.. + * + * @param string $table + * A table name that is not prefixed or quoted. + * @param string $column + * The column name. + * + * @return string|null + * The name of the sequence or NULL if it does not exist. + */ + public function getSequence($table, $column) { + $args = [ + ':table' => $this->prefixTables('{' . $table . '}'), + ':column' => $column, + ]; + return $this + ->query("SELECT pg_get_serial_sequence(:table, :column)", $args) + ->fetchField(); + } + + /** + * Checks if a sequence exists. + * + * @param string $name + * The fully-qualified sequence name. + * + * @return bool + * TRUE if the sequence exists by the name. + * + * @see \Drupal\Core\Database\Connection::makeSequenceName() + */ + public function sequenceExists($name) { + $args = [':name' => $name]; + return (bool) $this + ->query("SELECT c.relname FROM pg_class as c WHERE c.relkind = 'S' AND c.relname = :name", $args) + ->fetchField(); + } + } /** interdiff impossible; taking evasive action reverted: --- b/core/lib/Drupal/Core/Database/Driver/pgsql/Schema.php +++ a/core/lib/Drupal/Core/Database/Driver/pgsql/Schema.php @@ -958,7 +958,7 @@ // not when altering. Because of that, the sequence needs to be created // and initialized by hand. $seq = $this->connection->makeSequenceName($table, $field_new); + $this->connection->query("CREATE SEQUENCE " . $seq); - $this->connection->query("CREATE SEQUENCE " . $seq . " OWNED BY {" . $table . "}." . $field_new); // Set sequence to maximal field value to not conflict with existing // entries. $this->connection->query("SELECT setval('" . $seq . "', MAX(\"" . $field . '")) FROM {' . $table . "}"); @@ -1016,25 +1016,6 @@ } } - /** - * Alters the ownership of a sequence. - * - * This is used for updating orphaned sequences. - * See issue https://www.drupal.org/project/drupal/issues/3028706 - * - * @param string $table - * The unquoted or prefixed table name. - * @param string $column - * The column name for the sequence. - * - * @internal - */ - public function updateSequenceOwnership($table, $column) { - $seq = $this->connection->makeSequenceName($table, $column); - $table_name = $this->connection->prefixTables('{' . $table . '}'); - $this->connection->query('ALTER SEQUENCE IF EXISTS ' . $seq . ' OWNED BY ' . $table_name . '.' . $column); - } - /** * Retrieve a table or column comment. */ unchanged: --- a/core/lib/Drupal/Core/Database/Driver/pgsql/Schema.php +++ b/core/lib/Drupal/Core/Database/Driver/pgsql/Schema.php @@ -971,7 +971,7 @@ public function changeField($table, $field, $field_new, $spec, $new_keys = []) { // not when altering. Because of that, the sequence needs to be created // and initialized by hand. $seq = $this->connection->makeSequenceName($table, $field_new); - $this->connection->query("CREATE SEQUENCE " . $seq); + $this->connection->query("CREATE SEQUENCE " . $seq . " OWNED BY {" . $table . "}." . $field_new); // Set sequence to maximal field value to not conflict with existing // entries. $this->connection->query("SELECT setval('" . $seq . "', MAX(\"" . $field . '")) FROM {' . $table . "}"); @@ -1029,6 +1029,25 @@ protected function _createKeys($table, $new_keys) { } } + /** + * Alters the ownership of a sequence. + * + * This is used for updating orphaned sequences. + * See issue https://www.drupal.org/project/drupal/issues/3028706 + * + * @param string $table + * The unquoted or prefixed table name. + * @param string $column + * The column name for the sequence. + * + * @internal + */ + public function updateSequenceOwnership($table, $column) { + $seq = $this->connection->makeSequenceName($table, $column); + $table_name = $this->connection->prefixTables('{' . $table . '}'); + $this->connection->query('ALTER SEQUENCE IF EXISTS ' . $seq . ' OWNED BY ' . $table_name . '.' . $column); + } + /** * Retrieve a table or column comment. */ diff -u b/core/modules/system/system.install b/core/modules/system/system.install --- b/core/modules/system/system.install +++ b/core/modules/system/system.install @@ -1552,7 +1552,7 @@ // Discovers all content entity types with integer entity keys that are most // likely serial columns. $entity_types = \Drupal::entityTypeManager()->getDefinitions(); - // @var \Drupal\Core\Entity\EntityTypeInterface $entity_type + /** @var \Drupal\Core\Entity\EntityTypeInterface $entity_type */ foreach ($entity_types as $entity_type) { $storage_class = $entity_type->getStorageClass(); if (is_subclass_of($storage_class, SqlContentEntityStorage::class)) { @@ -1560,7 +1560,7 @@ $id_key = $entity_type->getKey('id'); $revision_key = $entity_type->getKey('revision'); - // @var \Drupal\Core\Field\BaseFieldDefinition[] $base_field_definitions + /** @var \Drupal\Core\Field\BaseFieldDefinition[] $base_field_definitions */ $base_field_definitions = $entity_class::baseFieldDefinitions($entity_type); if ($base_field_definitions[$id_key]->getType() === 'integer') { $sandbox['tables'][] = [