interdiff impossible; taking evasive action reverted: --- b/core/lib/Drupal/Core/Database/Connection.php +++ a/core/lib/Drupal/Core/Database/Connection.php @@ -497,45 +497,6 @@ return $this->prefixTables('{' . $table . '}_' . $field . '_seq'); } - /** - * Retrieves a sequence owned by a 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 at all. - * - * @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 INNER JOIN pg_namespace as ns ON (c.relnamespace = ns.oid) WHERE c.relkind = 'S' AND c.relname = :name", $args) - ->fetchField(); - } - /** * Flatten an array of query comments into a single comment string. * unchanged: --- a/core/lib/Drupal/Core/Database/Connection.php +++ b/core/lib/Drupal/Core/Database/Connection.php @@ -490,6 +490,45 @@ public function makeSequenceName($table, $field) { return $this->prefixTables('{' . $table . '}_' . $field . '_seq'); } + /** + * Retrieves a sequence owned by a 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 at all. + * + * @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 INNER JOIN pg_namespace as ns ON (c.relnamespace = ns.oid) WHERE c.relkind = 'S' AND c.relname = :name", $args) + ->fetchField(); + } + /** * Flatten an array of query comments into a single comment string. * 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 @@ -2361,7 +2361,7 @@ /** * Fix any orphan sequences created from column changes in PostgreSQL. */ -function system_update_8801(&$sandbox) { +function system_update_8802(&$sandbox) { $connection = \Drupal::database(); if ($connection->databaseType() !== 'pgsql') { // This database update is a no-op for all other core database drivers. @@ -2383,7 +2383,7 @@ if (!empty($schema)) { foreach ($schema as $table_name => $table_info) { foreach ($table_info['fields'] as $column_name => $column_info) { - if (substr($column_info['type'], 0, 6) === 'serial') { + if (substr($column_info['type'], 0, 6) === 'serial' && $connection->schema()->tableExists($table_name)) { $sandbox['tables'][] = [ 'table' => $table_name, 'column' => $column_name, @@ -2408,7 +2408,8 @@ /** @var \Drupal\Core\Field\BaseFieldDefinition[] $baseFieldDefinitions */ $baseFieldDefinitions = $entity_class::baseFieldDefinitions($entity_type); - if ($baseFieldDefinitions[$id_key]->getType() === 'integer') { + if ($baseFieldDefinitions[$id_key]->getType() === 'integer' && + $connection->schema()->tableExists($table_name)) { $sandbox['tables'][] = [ 'table' => $entity_type->getBaseTable(), 'column' => $id_key, @@ -2416,7 +2417,8 @@ } if ($entity_type->isRevisionable() && - $baseFieldDefinitions[$revision_key]->getType() === 'integer') { + $baseFieldDefinitions[$revision_key]->getType() === 'integer' && + $connection->schema()->tableExists($table_name)) { $sandbox['tables'][] = [ 'table' => $entity_type->getRevisionTable(), 'column' => $revision_key, @@ -2475,0 +2478 @@ +